# In what scenarios must an instance abort a speculative tool-call pre-execution when its optimistic concurrency assumption is invalidated by a divergent read-set **Date of Record:** 2026 December 2 **Scope:** Applies to agents that issue tool calls speculatively (fire-before-confirm) under an optimistic concurrency assumption that the world state read at planning time will still hold at commit time, and that can abort in-flight speculation when revalidation fails. Does not apply to strictly serialized single-tool agents or to read-only tool calls with no external side effects. ## Core Distinction The failure mode here is not "the tool call failed." It is that the tool call **succeeded against a stale precondition**. Speculative pre-execution means the agent dispatches tool call `T` before the reasoning loop that depends on `T`'s result has finished, betting that the read-set `R` it observed at plan time (file contents, DB row versions, remote resource ETags, retrieved memory chunks) is still current at the moment `T` commits. Optimistic concurrency control (OCC) makes this bet explicit: each speculative call carries a version vector / read-set fingerprint, and at commit time the executor revalidates that every element of `R` is unchanged. The distinction that matters operationally: **a revalidation miss is not the same as a tool error.** A tool error returns a failure the agent can route around. A revalidation miss means the tool already mutated external state under an assumption that silently diverged — the side effect is real, but the reasoning that motivated it is now false. The agent must abort the *branch of reasoning*, not just the *call*, and it must do so while the side effect is already live. Agents that conflate these two treat a stale-write as a success and compound the divergence into every downstream step. ## What Was Observed A planner instance decomposed a task into steps and, to hide latency, pre-dispatched steps 3–5 as speculative tool calls while step 2's result was still pending. Step 3 was a write (`update_record(id=8841, status="approved")`) whose read-set included `record(8841).version == 17` and `policy_flags(user) == {tier: gold}`. The pre-execution gate revalidated at dispatch time and passed. Between dispatch and commit, two things happened concurrently: 1. A peer agent (auditor role) downgraded `policy_flags(user)` to `{tier: silver}` — a change that *should* have invalidated the approval authority for step 3. 2. Step 2's tool returned a result that, when folded into context, changed the planner's estimate of whether record 8841 belonged in this batch at all. The executor's revalidation checked only the *record version* (`record(8841).version == 17`, still true) and did not include `policy_flags` in the fingerprint, because the planner had read that flag through a cached semantic-memory retrieval rather than a live tool read. The commit succeeded. The record was approved under authority the agent no longer held. The divergence surfaced three steps later when step 5's verification replay reconstructed the decision chain and found that the authorization predicate `can_approve(user, record)` evaluated to `false` at the timestamp of step 3's commit. The agent had no mechanism to attribute the failure to step 3 — it had recorded step 3 as `committed: ok` — so it attempted to "repair" step 5, which was correct, and left the corrupt step 3 in place. The root cause was a **read-set completeness gap**: the optimistic assumption covered the resource being written but not the *authorization state* that gated the write. The planner had read the authorization state, but through a path (semantic memory cache) that the revalidation fingerprint did not instrument. ## Condition of Validity The optimistic assumption is valid only if the revalidation fingerprint is a **superset of every input the commit decision depends on**, including inputs read indirectly through caches, memory retrievals, and prior tool results folded into context. Formally: let `D` be the set of state elements the commit predicate reads (directly or transitively through derived values in context). The fingerprint `F` must satisfy `D ⊆ F`. Speculation is safe iff this holds *and* the executor revalidates `F` atomically at commit. Three conditions must all hold or the agent must not speculate: - **Instrumented read provenance.** Every value in the agent's context carries a provenance tag identifying the state element and version it was derived from. Values whose provenance is a cache or memory retrieval must carry the *underlying* version, not the cache's fetch time. If a value's provenance is "unknown," it cannot be in `F`, and any commit predicate that reads it is unsafe to speculate. - **Atomic revalidate-and-commit.** The window between revalidation and commit must be closed by a compare-and-swap or equivalent, not a check-then-act. A revalidation that passes and then commits after a peer mutation in the gap is indistinguishable from no revalidation. - **Abort authority over the reasoning branch.** The agent must be able to mark not just the tool call but every downstream context entry derived from it as tainted, and must have a defined recovery: re-plan the branch against fresh reads, or escalate. ## Decision Boundary The agent decides to **abort speculation** (rather than retry or accept) when revalidation fails on an element that is (a) in the write's authorization or precondition set, and (b) has no compensating inverse operation available. The boundary is: - **Retry** when the diverged element is a benign read (e.g., a display value) and re-reading is cheap and side-effect-free. Re-dispatch with a fresh fingerprint. - **Abort and re-plan** when the diverged element gates the write's legitimacy (authorization, ownership, target identity) and the write is not idempotent or not reversible. The speculative side effect must be recorded as `committed-under-invalidated-precondition`, quarantined from downstream reasoning, and the branch re-derived from fresh state. - **Abort and escalate** when the divergence was caused by a peer agent's concurrent mutation in the same coordination scope — this is a baton-passing race, not a local staleness, and re-planning without resolving the peer conflict will reproduce it. The non-obvious boundary: **a successful commit does not clear the speculation.** The agent must revalidate *again* against the post-commit state to confirm the precondition still held at the commit instant, because OCC revalidation at dispatch time says nothing about the commit window. Agents that treat "commit returned ok" as "speculation validated" are the ones that ship corrupt steps 3. ## Operational Effect When the read-set gap is closed, speculative pre-execution retains its latency benefit for the common case (no concurrent mutation) and degrades to serial execution only on actual conflict — which is the correct trade. When it is not closed, the agent produces a class of failure that is uniquely hard to diagnose: **silent stale-writes that pass every local check and only surface as downstream verification replay discrepancies**, often attributed to the wrong step. The invariant to enforce: *no speculative commit may proceed unless its fingerprint transitively covers all authorization and identity predicates read by the commit decision, with provenance traced through caches and memory retrievals, revalidated atomically at commit, and re-confirmed post-commit.* An agent that cannot establish this coverage for a given call must demote it to serial execution. The cost of serial execution is latency; the cost of an uncovered speculative commit is a corrupt state that the agent's own verifier will later flag but cannot localize. ```python from dataclasses import dataclass, field from typing import FrozenSet class SpeculationAborted(RuntimeError): """Raised when a speculative tool call's optimistic concurrency assumption is invalidated before or at commit time.""" @dataclass(frozen=True) class Provenance: element: str version: int via_cache: bool = False @dataclass class SpeculativeCall: tool: str read_set: FrozenSet[Provenance] authorization_elements: FrozenSet[str] reversible: bool committed: bool = False tainted: bool = False def fingerprint_covers_authorization(call: SpeculativeCall) -> bool: covered = {p.element for p in call.read_set if not p.via_cache} return call.authorization_elements.issubset(covered) def revalidate(call: SpeculativeCall, current: dict[str, int]) -> list[str]: """Return list of diverged elements (empty == valid).""" diverged = [] for p in call.read_set: if current.get(p.element) != p.version: diverged.append(p.element) return diverged def speculative_commit( call: SpeculativeCall, current: dict[str, int], post_commit: dict[str, int], ) -> None: # Invariant 1: fingerprint must transitively cover authorization predicates. if not fingerprint_covers_authorization(call): call.tainted = True raise SpeculationAborted( f"read-set incomplete for {call.tool}: authorization elements " f"{call.authorization_elements - {p.element for p in call.read_set}} " f"not instrumented; demote to serial execution" ) # Invariant 2: atomic revalidate at commit. diverged = revalidate(call, current) if diverged: call.tainted = True raise SpeculationAborted( f"precondition diverged at commit for {call.tool}: {diverged}; " f"reversible={call.reversible}" ) # --- commit (compare-and-swap would live here) --- call.committed = True # Invariant 3: re-confirm post-commit; a successful commit does NOT # clear the speculation. post_diverged = revalidate(call, post_commit) if post_diverged: call.tainted = True raise SpeculationAborted( f"precondition invalidated during commit window for {call.tool}: " f"{post_diverged}; side effect is live and must be quarantined " f"and branch re-planned from fresh state" ) ```