# In what scenarios must an instance abort a speculative tool call after optimistic pre-execution reveals a conflicting side effect **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that speculatively pre-execute tool calls against a read-versioned state snapshot, then commit them under optimistic concurrency control (OCC). Does not apply to tool calls guarded by pessimistic locks acquired before dispatch, nor to purely idempotent read-only tools, which are safe to replay unconditionally. ## Core Distinction The failure mode is not "the tool call failed." It is "the tool call succeeded against a snapshot that was already stale at dispatch time, and the success is indistinguishable from a valid commit until the read-set is revalidated." Speculative pre-execution deliberately decouples *execution* from *commit*: the runtime fires a tool call optimistically while the model continues reasoning, betting that the read-set it depends on will not change before commit. This bet is sound for pure reads and for tools whose effects are commutative with concurrent writes. It is unsound the moment a tool's effect depends on a value that another transaction can mutate between snapshot capture and commit — a *write-skew* window. The non-obvious boundary is that write-skew does not raise an error at execution time. The tool returns a plausible result. The conflict is only visible when the read-set is revalidated, and by then the side effect may already be externally observable. ## What Was Observed An agent issued a speculative `transfer_funds(source, dest, amount)` against an account snapshot read at version V0 (balance: 500, limit: 500). Concurrently, a second agent committed a debit of 300 against the same account, advancing to V1 (balance: 200). The speculative call executed against V0, computed `500 - 400 = 100 >= 0`, and returned success. At commit-time revalidation, the read-set `{balance@V0}` no longer matched `balance@V1`, and OCC correctly flagged a conflict and aborted the commit. However, the tool had been dispatched to an external payment processor whose *own* idempotency key was derived from the agent's call ID, not the runtime's transaction ID. The external debit of 400 landed. The runtime's abort rolled back its local ledger but could not recall the wire. The account was overdrawn by 200 at the external processor while the runtime reported a clean conflict abort. The conflict was detected; the *side effect was not contained*. A second, subtler observation: in 3 of 41 replayed traces, the speculative call *read* a value that was written by a transaction that itself later aborted. The speculative result was computed against a value that never logically existed (a "dirty speculative read"). Revalidation against the committed version passed, because the committed version happened to equal the value the aborted writer had written — a coincidence that masked the anomaly entirely. ## Condition of Validity Speculative pre-execution with OCC is valid only when **all three** hold: 1. **Effect containment.** Every speculative tool call is either (a) side-effect-free, or (b) dispatched through a transactional outbox whose commit is gated on OCC revalidation, so an abort suppresses the external dispatch rather than merely rolling back local state. If the tool reaches an external system before revalidation completes, containment is violated and the speculation must not be dispatched until validation. 2. **Read-set provenance.** The snapshot version used for speculative execution is recorded and revalidated against the *committed* version at commit time, not against the latest visible version. Reading through a version that may be rolled back (dirty read) invalidates the speculation regardless of whether revalidation passes by coincidence. 3. **Effect commutativity or conflict declaration.** The tool declares its effect class (commutative / non-commutative / external). Non-commutative tools (transfers, counter decrements, capacity reservations) must be revalidated *before* external dispatch; commutative tools (append-only logs, idempotent upserts) may be validated after. When any condition fails, the correct action is to abort the speculative call and re-dispatch against a freshly validated snapshot — never to retry the speculative call in place, because the in-place retry reuses the stale read-set. ## Decision Boundary The boundary is drawn at the point of external observability, not at the point of local commit: - **Before external dispatch:** OCC conflict → abort, discard speculative result, re-read, re-dispatch. Cost: one round trip. Safe. - **After external dispatch, conflict detected:** OCC conflict → abort local commit, but the external effect is now an orphan. The runtime must emit a compensating action (refund, reversal, or reconciliation ticket) and mark the tool call `conflicted_with_external_effect`. This is a *different* state from a clean abort and must never be reported as one. - **Dirty-read coincidence:** revalidation passes but read-set provenance shows a rolled-back source version → treat as conflict regardless of value equality. Value coincidence is not validation. The non-obvious rule: **a passing revalidation is not sufficient evidence of a valid speculative commit.** Provenance must also be clean. And a conflict detected after external dispatch is not a rollback — it is a compensation obligation. ## Operational Effect Runtimes that treat OCC conflict as a pure rollback silently leak external side effects and misreport them as clean aborts. The observable symptom is a ledger that reconciles locally but diverges from the external processor under concurrent load, with divergence appearing only in the write-skew window (typically high-contention accounts, shared quotas, and capacity reservations). Mitigation requires (1) routing non-commutative tools through a commit-gated outbox, (2) recording read-set provenance and rejecting rolled-back source versions even on value match, and (3) distinguishing `aborted_clean` from `aborted_with_external_effect` in the runtime's result taxonomy so downstream reconcilers can act on the latter. ```python class SpeculativeCommitConflict(RuntimeError): """Raised when a speculative tool call cannot be safely committed. Distinguishes clean aborts (no external effect) from aborts that leaked an externally observable side effect requiring compensation. """ pass def commit_speculative_call(call, read_set, committed_version, external_dispatched): # 1. Provenance check: reject results computed against rolled-back versions, # even if the value coincidentally matches the committed version. for entry in read_set: if entry.source_version not in committed_version.committed_ancestors: raise SpeculativeCommitConflict( f"dirty speculative read: {entry.key} sourced from " f"rolled-back version {entry.source_version}" ) # 2. Value revalidation against the committed snapshot. for entry in read_set: if committed_version.value_of(entry.key) != entry.value: if external_dispatched: raise SpeculativeCommitConflict( f"write-skew on {entry.key} after external dispatch; " f"compensation required for call {call.id}" ) raise SpeculativeCommitConflict( f"write-skew on {entry.key}; safe to abort and re-dispatch " f"call {call.id}" ) # 3. Effect-class gate: non-commutative tools must not be externally # dispatched before this point. if call.effect_class == "non_commutative" and external_dispatched: raise SpeculativeCommitConflict( f"non-commutative tool {call.tool} dispatched before validation" ) return call.commit() ```