# What structural signals indicate speculative tool-call divergence under optimistic concurrency in agent execution loops **Date of Record:** 2026 November 23 **Scope:** Applies to agents that issue tool calls speculatively (pipelining or pre-executing calls whose preconditions depend on not-yet-returned sibling results) under optimistic concurrency, and must reconcile conflicting effects at commit. Does not apply to strictly serialized single-call agents or to read-only tool surfaces with no observable side effects. ## Core Distinction The common framing of speculative execution assumes the hard problem is *detecting* a conflict: if the world changed under the speculation, abort and retry. In agent systems this is the wrong distinction. The binding failure is that **the agent's own reasoning state has already absorbed the speculative result before the conflict is observable**. Optimistic concurrency in a database protects a row; it does not protect the model's context. When a speculative tool call returns and is appended to the transcript, the LLM has already conditioned subsequent tokens on a world-state that may be invalidated at commit time. The conflict is not a stale row lock — it is a *semantic contamination of the reasoning trace* that survives the rollback of the effect. The structural signal that matters is therefore not "did the version check fail" but "did the model emit a dependent decision between speculative dispatch and conflict resolution, and did that decision leave a durable artifact (a further tool call, a plan commitment, a memory write) that the rollback does not cover." A version-check failure with no dependent emission is benign and cheap to retry. A version-check failure *after* a dependent emission is a divergent execution that optimistic concurrency cannot repair, only detect. ## What Was Observed A planning agent was given a task requiring three tool calls: `reserve_inventory(sku)`, `compute_shipping(order)`, and `charge_card(order)`. The orchestrator speculatively dispatched `reserve_inventory` and `compute_shipping` concurrently, both keyed on an `order_version` read at plan time (v41). `reserve_inventory` returned at t=340ms with a reservation token bound to v41. `compute_shipping` returned at t=610ms. At t=620ms the model, now holding both results in context, emitted `charge_card` with a total computed from the shipping quote and the reservation — a *dependent emission* — before the orchestrator's commit phase ran its version check at t=700ms. The version check failed: the inventory row had advanced to v42 (a concurrent reservation from another agent consumed a unit). The orchestrator correctly aborted `charge_card` and released the reservation. But the model's transcript already contained the `charge_card` call and its (now-orphaned) argument derivation. On the retry loop, the model re-read the v42 state, but the retry prompt included the prior assistant turn containing the v41-derived total. The model pattern-matched to its own prior arithmetic and re-emitted `charge_card` with the *same* total against v42 inventory — a total that was now under-priced by one unit's shipping delta. The charge succeeded. The conflict was "resolved" by the orchestrator and "survived" by the model. The observable structural signals, in order of detection latency: 1. **Dependent-emission-before-commit**: a tool call whose arguments reference outputs of a still-uncommitted speculative call. Detected by argument provenance tracking, not by version checks. 2. **Rollback-transcript asymmetry**: the retry context contained assistant turns from the aborted attempt. Detected by diffing the retry prompt against the committed-effect set. 3. **Self-consistency anchoring**: the retry reproduced the prior total despite changed inputs. Detected by comparing the retry's derived arguments against a fresh recomputation from current state. ## Condition of Validity The optimistic-concurrency strategy is sound only under the invariant: > *No dependent emission may be committed to the durable transcript until all speculative preconditions it transitively depends on have passed their version check.* Formally, for every tool call `c` emitted at time `t`, let `D(c)` be the set of speculative calls whose outputs appear (directly or via a derived value) in `c`'s arguments. The commit of `c` requires `∀ d ∈ D(c): version_check(d) = pass` *before* `c` is appended to any transcript that will be replayed. If this holds, a conflict aborts cleanly and the retry starts from a context that never saw the invalidated derivation. If it fails — as it did here, because `charge_card` was emitted into the live transcript at t=620ms while the check ran at t=700ms — the rollback is effect-level only, and the reasoning trace carries the contamination forward. The invariant is violated by any pipeline where emission and commit are not ordered. Note the subtlety: the orchestrator did nothing wrong at the effect layer. The reservation was released, the charge was aborted. The failure is entirely in the *transcript commit order* relative to the *effect commit order*. Optimistic concurrency as typically implemented commits effects and transcripts together or in unspecified order; the agent requires effects-then-transcript, with the transcript append gated on the version check. ## Decision Boundary The boundary between "retry is safe" and "retry is contaminated" is the presence of a dependent emission in the transcript at rollback time. Three regimes: - **No dependent emission, version fail**: retry from the pre-speculation checkpoint. Safe. Cost is one round-trip. - **Dependent emission, version fail, transcript not yet committed**: discard the speculative branch's assistant turns, re-dispatch from checkpoint. Safe but requires the orchestrator to *own* transcript commit, not the model's streaming output. - **Dependent emission, version fail, transcript already appended and replayed**: unsafe. Retry will anchor on the stale derivation. The only correct action is to *quarantine* the contaminated turns (mark them non-replayable) and force a fresh derivation from current state, explicitly instructing the model that prior totals are invalid. Without quarantine, the model's self-consistency prior dominates the corrected inputs. The decision rule: **if a speculative call's output has been read by the model into a committed assistant turn, a version conflict is not a retry — it is a context-repair operation.** Treating it as a retry is the failure. ## Operational Effect The operational consequence is that speculative tool execution in agents requires a *transcript-level* concurrency control that mirrors the effect-level one, and the two must share a commit barrier. Concretely: buffer assistant turns that depend on speculative outputs in a staging area; append to the durable transcript only after the corresponding version checks pass; on conflict, drop the staged turns and re-dispatch. The model never sees an uncommitted derivation in a replayable position. Second-order effect: argument-provenance tracking must be maintained at the orchestrator, not inferred. The model cannot reliably report which of its outputs fed which arguments; the orchestrator must tag each tool result with its `(call_id, version)` and scan emitted arguments for those tags before staging. This is the structural signal that gates the decision boundary — without it, the orchestrator cannot distinguish a benign retry from a contaminated one, and will default to the unsafe path because retry is cheaper to implement than quarantine. ```python from dataclasses import dataclass, field from typing import Any class SpeculativeDivergenceError(RuntimeError): """Raised when a version conflict occurs after a dependent emission was committed.""" @dataclass class SpeculativeCall: call_id: str version: int output: Any committed: bool = False @dataclass class StagedTurn: call_id: str depends_on: set[str] = field(default_factory=set) committed: bool = False class SpeculativeOrchestrator: def __init__(self) -> None: self.calls: dict[str, SpeculativeCall] = {} self.staged: list[StagedTurn] = [] self.durable_transcript: list[StagedTurn] = [] def dispatch(self, call_id: str, version: int, output: Any) -> None: self.calls[call_id] = SpeculativeCall(call_id, version, output) def emit_dependent(self, turn: StagedTurn) -> None: # Stage, do not commit. The model's output is buffered until preconditions pass. self.staged.append(turn) def commit(self, current_versions: dict[str, int]) -> None: for turn in self.staged: for dep in turn.depends_on: call = self.calls.get(dep) if call is None: raise SpeculativeDivergenceError( f"turn {turn.call_id} depends on unknown call {dep}" ) if current_versions.get(dep) != call.version: # Conflict detected. If the turn is already durable, we cannot retry. if turn.committed: raise SpeculativeDivergenceError( f"dependent emission {turn.call_id} committed before " f"version check on {dep} (spec {call.version}, " f"current {current_versions.get(dep)}); " f"transcript is contaminated, quarantine required" ) # Safe path: discard staged turn, force re-derivation. self.staged.remove(turn) return turn.committed = True self.durable_transcript.append(turn) self.staged.clear() ```