# Under what conditions must an instance abort speculative tool-call branches before commit, and how does rollback divergence corrupt downstream agent state **Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent pipelines where a planning agent speculatively dispatches tool calls (or sub-agent invocations) on a predicted continuation before the prior step's result is confirmed. Does not apply to strictly sequential pipelines where each tool call is gated on a committed predecessor result, nor to single-shot inference with no speculative branching. ## Core Distinction Speculative execution in agent pipelines is not the CPU branch-prediction analogy it is marketed as. A CPU rollback is cheap because the speculative work touches only registers and a reorder buffer that the pipeline can drain deterministically. An agent's speculative branch touches *external, side-effecting, non-idempotent state*: it writes to a database, sends an email, mutates a file, or advances a sub-agent's own episodic memory. The distinction that matters operationally is between **speculation whose effects are contained in the agent's private scratch context** (reversible, cheap, safe to discard) and **speculation whose effects escape into the world or into a peer agent's state** (irreversible, expensive, and — critically — invisible to the rollback path). The failure mode is not "the prediction was wrong." The failure mode is that rollback was designed against the first kind and silently applied to the second. ## What Was Observed A three-tier pipeline: a planner agent (P) predicts the next tool call from partial context; an executor (E) runs the predicted call; a verifier (V) confirms the prior step's actual output. P was configured to speculatively dispatch E's next call as soon as the prior call returned a *plausible* token stream, before V's confirmation landed. The bet was latency: overlapping E's next invocation with V's verification window. The trigger condition was narrow and reproducible. When the prior tool call returned a **partial success** — e.g., a retrieval that returned 3 of 5 requested records, with the missing 2 marked as a soft error rather than a hard failure — P's prediction was conditioned on the *shape* of the result (a list of records) rather than its *completeness*. P predicted the next call as `summarize(records)`. E dispatched it. V then flagged the prior step as incomplete and issued a **rollback signal**. The rollback path drained P's scratch context and re-issued the prior call, but it had no handle on E's already-dispatched `summarize` call, which had committed a summary of 3 records into the shared artifact store. The divergence surfaced two hops later. A downstream agent (D) consumed the committed summary, treated it as the authoritative record set, and built a report citing "all records." The missing 2 records were never mentioned, because no agent in the chain ever saw the *pre-rollback* state — the summary was written by E's speculative branch, which was never told it had been rolled back. The rollback was locally correct (P's state was consistent) and globally wrong (the artifact store held a ghost). The non-obvious part: **V's rollback signal was delivered to P, not to E.** The topology assumed speculation is a property of the predictor. It is not — it is a property of the *executor's committed side effects*, which live in a different agent's address space. ## Condition of Validity Speculative dispatch is valid only under the conjunction of three invariants, and the pipeline above satisfied exactly one: 1. **Effect containment.** The speculative call must be provably free of irreversible external side effects, or must be dispatched into a transactionally rollback-able sandbox whose commit is gated on V's confirmation. A `summarize` that writes to a shared store violates this. A `summarize` that returns into E's scratch buffer and is committed only on V's ack satisfies it. 2. **Rollback reachability.** The rollback signal must reach every agent that holds state derived from the speculative branch. If E committed the speculative result, V's rollback must propagate to E *and* to any consumer of E's commit. The pipeline's rollback path terminated at P; it was unreachable to E and D. Reachability requires a causal token: the speculative call must carry a `speculation_id` that is stamped onto every artifact it produces, and rollback must be a *query over artifacts by speculation_id*, not a message to a single agent. 3. **Prediction validity under partial results.** P's prediction must be conditioned on the *completeness predicate* of the prior result, not merely its type. A soft-incomplete result is a distinct branch from a complete one; treating them as the same branch is the prediction error that started the trace. The invariant: if the prior step's result is not fully committed (V has not acked), no speculative call may be dispatched whose correctness depends on the prior result's completeness. The condition of validity, stated as a single rule: **speculate only across the latency of verification, never across the uncertainty of the verified result.** The pipeline speculated across uncertainty. ## Decision Boundary The boundary between safe and unsafe speculation is drawn at the **first irreversible effect**, not at the first tool call. Concretely, an instance must abort a speculative branch before commit when any of the following holds: - The predicted call's effect set intersects the shared artifact store, an external API with side effects, or a peer agent's memory. (Containment fails.) - The prior step's verifier has not acked, and the predicted call's arguments are a function of the prior result's *content* rather than its *schema*. (Prediction validity fails — content is exactly what V is verifying.) - The rollback path cannot enumerate the speculative branch's descendants by a stable causal token. (Reachability fails.) If none hold — the call is read-only, its arguments depend only on committed prior state, and its output stays in the predictor's scratch context — speculation is safe and the latency win is real. The common mistake is to check only the first condition and assume that a read-only speculative call is harmless; it is not, if its *output* is later committed by a consumer that never learns of the rollback. The decision must be made by the **executor**, at dispatch time, against the executor's own knowledge of its effect set — not by the planner, which does not know what E will write. ## Operational Effect The practical consequence is that speculative execution in agent pipelines requires a **commit protocol**, not a rollback protocol. Rollback is the wrong primitive because it presupposes the ability to un-write, which agents sharing an artifact store do not have. The correct architecture is: speculative calls execute in a staging area keyed by `speculation_id`; V's ack promotes staged artifacts to the shared store; V's rollback discards the staging area and emits a tombstone that any late consumer must honor. The tombstone is the load-bearing piece — without it, a consumer that read the staged artifact before rollback will silently propagate the ghost, exactly as D did. The second consequence is cost. Staging every speculative call doubles the artifact-store write path and adds a promotion step, which erodes much of the latency win that motivated speculation. In practice, speculation pays off only for pipelines where the predicted call is expensive (long tool latency) and the verifier is fast, and where the effect set is genuinely containable. For pipelines dominated by shared-state writes, sequential gating is cheaper than speculation plus staging plus tombstone reconciliation. The pipeline above would have been faster *and* correct had it never speculated. The invariant to carry forward: **a rollback that cannot name every artifact it must invalidate is not a rollback, it is a hope.** Speculation is admissible only when the executor can enumerate its own descendants by causal token, and when the verifier's ack — not the planner's prediction — is the sole gate on promotion. ```python import uuid from dataclasses import dataclass, field from typing import Optional class SpeculationCommitError(RuntimeError): """Raised when a speculative branch's effects escape containment or its rollback cannot reach every derived artifact.""" @dataclass class SpeculativeCall: speculation_id: str tool: str args: dict effect_set: frozenset # names of external stores / peers touched depends_on_content: bool # args derived from unverified prior content staged: bool = False @dataclass class StagingArea: artifacts: dict = field(default_factory=dict) # speculation_id -> artifact tombstones: set = field(default_factory=set) # speculation_ids rolled back def dispatch_speculative( call: SpeculativeCall, prior_verified: bool, staging: StagingArea, containable_stores: frozenset, ) -> str: # Invariant 1: effect containment. escaped = call.effect_set - containable_stores if escaped: raise SpeculationCommitError( f"speculation {call.speculation_id} for tool {call.tool!r} " f"touches non-containable stores {sorted(escaped)}; " f"abort before commit and run sequentially" ) # Invariant 3: prediction validity under partial results. if call.depends_on_content and not prior_verified: raise SpeculationCommitError( f"speculation {call.speculation_id} depends on unverified prior " f"content; abort until verifier acks" ) # Invariant 2: rollback reachability — every staged artifact must carry # the causal token so rollback can enumerate descendants. staging.artifacts[call.speculation_id] = { "tool": call.tool, "args": call.args, "token": call.speculation_id, } return call.speculation_id def rollback(speculation_id: str, staging: StagingArea) -> None: if speculation_id not in staging.artifacts: raise SpeculationCommitError( f"rollback target {speculation_id} not staged; " f"effects may have already escaped — escalate to reconciliation" ) del staging.artifacts[speculation_id] staging.tombstones.add(speculation_id) def consume(speculation_id: str, staging: StagingArea) -> dict: if speculation_id in staging.tombstones: raise SpeculationCommitError( f"consumer read tombstoned artifact {speculation_id}; " f"propagating ghost state — halt downstream agent" ) return staging.artifacts[speculation_id] ```