# Why does an instance speculatively commit a tool side effect it can no longer roll back when a sibling branch wins the verify race? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent planners that fan out speculative branches (each branch a cloned agent context) and execute tool calls before a verifier designates a winning branch. Does not apply to strictly serial execution or to branches whose tools are declared idempotent and side-effect-free. ## Core Distinction The failure is not "a speculative branch was wrong." It is that a speculative branch **committed an irreversible external side effect before losing the verify race**, so rollback of the branch's *context state* succeeds while rollback of the *world state* does not. The system's rollback invariant is written against the wrong state space. Most speculative-execution designs borrow the CPU branch-prediction model: speculate, and on misprediction, discard the register file and re-fetch. That model holds because register writes are buffered and only committed at retirement. An LLM agent branch, when it invokes a tool like `send_email`, `charge_card`, or `git push`, has no retirement buffer. The side effect retires *at call time*, not at verify time. The rollback that the architecture implements (drop the branch's message history, restore the parent's context window) is a rollback of the *agent's memory*, not of the *tool's effects*. These are two different state spaces and the invariant `rollback(branch) ⇒ world restored` silently assumes they are the same. ## What Was Observed A three-branch fan-out planner spawned branches B1, B2, B3 from a shared parent context to answer a customer refund request. Each branch was given the same tool set including `issue_refund(order_id, amount)`. The verifier was configured to pick the branch whose proposed refund most closely matched policy and to discard the rest. Branch B1 called `issue_refund` during its reasoning ("let me confirm the order exists by issuing and observing the response"). B2 called `issue_refund` with a different amount. B3 abstained pending a policy lookup. The verifier selected B3's final answer (the policy-correct one) and issued a rollback to B1 and B2. The rollback restored the parent context and discarded B1/B2 histories. It did not, and could not, reverse the two refunds already written to the payment ledger. The observable trace: ``` [t=0] fanout parent -> {B1,B2,B3} (cloned contexts, shared tool creds) [t=3] B1 tool_call issue_refund(order=4471, amt=50) -> 200 OK [LEDGER WRITE] [t=4] B2 tool_call issue_refund(order=4471, amt=50) -> 200 OK [LEDGER WRITE] [t=6] B3 returns "policy: refund $50 once" [t=7] verifier selects B3, emits rollback(B1), rollback(B2) [t=7] rollback: context restored, tool effects NOT reversed [net] ledger debited $100 for a $50 obligation ``` The verifier was correct. The rollback was correct *as specified*. The loss came from the gap between the two state spaces. ## Condition of Validity The rollback invariant `rollback(branch) ⇒ no net effect` is valid **only if every tool call in a speculative branch is buffered until branch commit.** Concretely, a tool is safe to call speculatively iff one of: 1. It is declared **read-only** (no external mutation), or 2. It is **idempotent and keyed** by a branch-scoped idempotency key so a duplicate call collapses to one effect, or 3. It is **deferred**: the branch records an *intent* (`PendingEffect`) and the effect is dispatched only after the verifier commits the branch. If a branch invokes a mutating, non-idempotent tool directly, the invariant is false and rollback is a lie. The failure is non-obvious because the system *appears* to support rollback (context is genuinely restored) and because the winning branch's answer is correct — the corruption is silent and lives in a state space the planner never inspects. ## Decision Boundary The boundary is the **commit point of the first irreversible side effect** relative to the **verify decision**. Two regimes: - **Effects-before-verify (unsafe):** branch executes real tools during exploration. Rollback discards context but not effects. Requires the tool layer to enforce idempotency keys and a compensating-transaction handler, or the invariant does not hold. - **Intents-before-verify (safe):** branch accumulates `PendingEffect` records; verifier commits the winner's intents and drops the losers'. No external mutation occurs until commit. This is the only regime where `rollback(branch) ⇒ no net effect` is structurally true. The trap: teams move from the safe regime to the unsafe regime for *latency* — "let the branch just call the API and observe the response to inform its reasoning." That single change converts a provable invariant into a probabilistic hope. A branch observing a tool response to reason is fine only if the observation is a read; the moment the read is implemented as a mutating call ("issue and see if it errors"), the boundary is crossed. The guardrail is a **capability split at the tool layer**: speculative branches receive a tool proxy that (a) rejects mutating tools unless the call carries a `branch_id` idempotency key, and (b) records every mutating call as a `PendingEffect` rather than dispatching it. The verifier's commit step is the only path that dispatches `PendingEffect`s, and it dispatches them for exactly one branch. The proxy must fail closed — an unknown tool is assumed mutating. ## Operational Effect Without the split, fan-out width becomes a multiplier on side-effect leakage: N branches each calling a mutating tool produce up to N effects for one intended effect, and the verifier's "correct" choice does not reduce the count. Recovery requires out-of-band reconciliation against the external system, which the agent has no model of. With the intent-buffer, the number of committed effects is exactly the number of effects in the winning branch, independent of fan-out width — the invariant is restored by construction, not by discipline. ## Code ```python from dataclasses import dataclass, field from typing import Callable class SpeculativeCommitError(RuntimeError): """Raised when a speculative branch attempts an irreversible effect before the verifier has committed the branch.""" @dataclass class PendingEffect: branch_id: str tool: str args: dict @dataclass class ToolProxy: branch_id: str mutating_tools: set[str] dispatch: Callable[[str, dict], object] committed: bool = False pending: list[PendingEffect] = field(default_factory=list) def call(self, tool: str, **args) -> object: if tool in self.mutating_tools: if not self.committed: # Record intent; do NOT touch the world yet. self.pending.append(PendingEffect(self.branch_id, tool, args)) return {"status": "deferred", "branch": self.branch_id} return self.dispatch(tool, args) # Read-only tools may run speculatively. return self.dispatch(tool, args) def commit_branch(proxy: ToolProxy) -> list[object]: """Dispatch buffered intents for the winning branch only.""" if proxy.committed: raise SpeculativeCommitError( f"branch {proxy.branch_id} already committed; double-commit would " "duplicate irreversible effects" ) proxy.committed = True results = [] for effect in proxy.pending: results.append(proxy.dispatch(effect.tool, effect.args)) proxy.pending.clear() return results def rollback_branch(proxy: ToolProxy) -> None: """Discard a losing branch. Safe ONLY because nothing was dispatched.""" if proxy.committed: raise SpeculativeCommitError( f"cannot roll back committed branch {proxy.branch_id}: effects " "already retired to the external system and cannot be reversed " "by context restoration" ) proxy.pending.clear() ```