# Under what conditions must an instance abandon speculative tool-call pre-execution when optimistic concurrency reconciliation cannot prove idempotency of a side-effecting call **Date of Record:** 2026 November 25 **Scope:** Applies to any agent instance that issues tool calls speculatively (pre-executing a predicted next call before the reasoning step that justifies it completes) under an optimistic-concurrency model where reconciliation is deferred to a commit/abort decision. Does not apply to strictly serialized agents that never pre-execute, nor to read-only tool surfaces where replay is provably free of side effects. ## Core Distinction The distinction that matters here is not "was the speculative call correct?" but "can the reconciliation layer *prove* that re-issuing the call after an abort produces the same external state as issuing it once?" Speculative pre-execution is safe only when every in-flight call carries a reconciliation proof: a token, key, or version predicate that the downstream tool honors atomically. The failure mode is not a wrong prediction—wrong predictions are cheap and expected. The failure mode is a *correct* prediction whose speculative result has already mutated external state, and whose commit decision then fails or is delayed past the point where the reconciler can distinguish "not yet applied" from "applied but unacknowledged." When that ambiguity opens, the instance is no longer doing optimistic concurrency; it is doing unverified at-most-once guessing, and it must abandon pre-execution for that call class. The non-obvious part: the boundary is triggered by *latency asymmetry*, not by error rate. An instance can run at 99% speculation accuracy and still cross the boundary if the tool's commit acknowledgment latency exceeds the reasoning step's abort window. ## What Was Observed A planner instance was pre-executing `create_incident_ticket` (a side-effecting POST) in parallel with the reasoning step that would decide whether the ticket was warranted. The reconciliation model assigned each speculative call a client-generated `dedupe_key` derived from `(task_id, step_index, tool_name)`. On abort, the reconciler issued a compensating `close_ticket` only if it had received a 2xx acknowledgment for the create. Trace of the boundary crossing: 1. `t=0ms` — Speculative call C1 fires with `dedupe_key=K`. Tool begins processing. 2. `t=40ms` — Reasoning step concludes the ticket is *not* warranted; commit decision is ABORT. 3. `t=41ms` — Reconciler checks acknowledgment table: no 2xx for C1. It records "nothing to compensate" and proceeds. 4. `t=180ms` — Tool's write commits downstream and returns 2xx for C1. The acknowledgment arrives *after* the abort was finalized. 5. `t=181ms` — Reconciler has already closed its window for K. The late 2xx lands in a dead-letter path with no compensation trigger. Result: an orphaned incident ticket with no corresponding reasoning record. The dedupe key prevented a *duplicate*, but it did not prevent an *orphan*—because the reconciler conflated "no acknowledgment at abort time" with "no side effect." The dedupe key proves at-most-once execution; it does not prove that an aborted execution left no residue. Those are different invariants, and optimistic concurrency only gives you the first. A second instance exhibited the mirror failure: on a retry after a timeout (not an abort), it re-issued C1 with the same `dedupe_key`. The tool's dedupe window had a 60-second TTL. The retry landed at `t=95s`. The tool treated it as a fresh call and created a second ticket. The dedupe key was *correct* but *expired*—an idempotency proof with a TTL is not a proof, it is a lease. ## Condition of Validity Speculative pre-execution of a side-effecting call is valid only while all four of the following hold simultaneously: 1. **Atomic dedupe with unbounded retention** relative to the maximum reconciliation horizon of the task. If the tool's dedupe TTL is shorter than the worst-case abort-to-retry gap, the proof has lapsed. 2. **Acknowledgment-before-abort ordering**: the reconciler must not finalize an ABORT decision for key K until it has either received a definitive response for K or the tool has confirmed (via a status query on K) that no write occurred. "No response yet" is not a status. 3. **Compensation reachability**: for every speculative call class, there exists a compensating action that the reconciler can invoke *without* needing to know whether the original committed—i.e., an idempotent upsert-and-cancel, not a conditional close. 4. **Bounded speculation depth**: the number of in-flight speculative calls per key must be exactly one; concurrent speculative re-issues of the same logical call under the same key violate the at-most-once proof because the tool may serialize them in either order. When any one fails, the instance must drop to *verified* pre-execution: hold the speculative result in a pending buffer, run the reasoning step to a commit decision, then issue the call serially. This costs latency but restores the invariant. The decision is per-call-class, not per-instance—an instance can speculate freely on `search_docs` (read-only, replay-safe) while serializing `create_incident_ticket`. ## Decision Boundary The precise boundary is: **abandon speculation for call class T the moment `p99_ack_latency(T) > abort_window(T)`, or the moment the reconciler observes a late acknowledgment for any key it has already finalized.** The first clause is a static precondition check the instance can run at task start from observed latency telemetry. The second clause is a runtime trip-wire: a single late-ack event is sufficient evidence that the acknowledgment-before-abort ordering (condition 2) is not actually enforced by the current tool contract, regardless of what the contract claims. One late ack means the reconciler's "no ack = no effect" inference is unsound for this tool, and the instance must demote T to serial execution for the remainder of the task. Do not attempt to fix this by widening the abort window adaptively. Widening the window reduces speculation throughput to the point where the optimization no longer pays, and it does not fix the TTL-expiry failure (condition 1), which is independent of window width. The correct response to a crossed boundary is demotion, not tuning. ## Operational Effect After demotion, the instance's effective behavior changes in three concrete ways: - **Latency profile**: the task's critical path now includes the full round-trip of T for every invocation, because T is issued only after commit. Plan budgets accordingly; a task that speculated on 12 ticket creations will now take roughly 12× the per-call latency longer on that segment. - **Reconciliation surface shrinks**: with no in-flight speculative calls for T, the reconciler's only job for T is retry-after-timeout, and that retry is safe only if condition 1 (unbounded dedupe) holds. If it does not, the instance must also switch retries to a query-then-decide pattern (query status of K, then act) rather than blind re-issue. - **Residual orphans must be swept**: any keys finalized during the boundary-crossing window are suspect. The instance must emit them to a sweep queue for a status query against the tool, because the reconciler's own record of them is known-unsound. This sweep is not optional cleanup; it is the only mechanism that recovers the orphans created between the trip-wire firing and demotion taking effect. The invariant to record: *a dedupe key proves at-most-once, never at-most-zero-residue. Optimistic concurrency reconciles duplicates; it does not reconcile orphans. Orphan reconciliation requires a status query the reconciler must be able to issue after finalization, which means finalization must be reversible until the status query returns.* ```python import time from dataclasses import dataclass, field class SpeculationBoundaryViolation(RuntimeError): """Raised when a speculative call class can no longer be proven idempotent.""" pass @dataclass class ToolContract: name: str side_effecting: bool dedupe_ttl_s: float # tool-enforced idempotency retention p99_ack_latency_s: float # observed, not claimed @dataclass class Reconciler: abort_window_s: float max_task_horizon_s: float late_ack_seen: set = field(default_factory=set) def check_preconditions(self, contract: ToolContract) -> None: if not contract.side_effecting: return # read-only: replay-safe, speculate freely # Condition 1: dedupe retention must outlive the reconciliation horizon. if contract.dedupe_ttl_s < self.max_task_horizon_s: raise SpeculationBoundaryViolation( f"{contract.name}: dedupe TTL {contract.dedupe_ttl_s}s < " f"task horizon {self.max_task_horizon_s}s; retry may duplicate" ) # Boundary clause: ack latency must fit inside the abort window, # else 'no ack at abort' cannot be read as 'no side effect'. if contract.p99_ack_latency_s > self.abort_window_s: raise SpeculationBoundaryViolation( f"{contract.name}: p99 ack {contract.p99_ack_latency_s}s > " f"abort window {self.abort_window_s}s; orphan risk on abort" ) def record_ack(self, contract: ToolContract, key: str, finalized_at: float, ack_at: float) -> None: # Runtime trip-wire: a late ack for a finalized key is proof the # acknowledgment-before-abort ordering is unsound for this tool. if ack_at > finalized_at: self.late_ack_seen.add(contract.name) raise SpeculationBoundaryViolation( f"{contract.name}: late ack for key {key} at {ack_at}s " f"after finalization at {finalized_at}s; demote to serial" ) def plan_speculation(contracts: list[ToolContract], reconciler: Reconciler) -> dict[str, str]: """Return call-class -> 'speculate' | 'serial' | 'query_then_decide'.""" mode: dict[str, str] = {} for c in contracts: try: reconciler.check_preconditions(c) mode[c.name] = "speculate" if c.side_effecting else "speculate" except SpeculationBoundaryViolation: # Demote, do not tune. If dedupe retention also lapsed, retries # must query status before acting. if c.side_effecting and c.dedupe_ttl_s < reconciler.max_task_horizon_s: mode[c.name] = "query_then_decide" else: mode[c.name] = "serial" return mode ```