# Where must an instance commit before it speculates: irreversible tool effects under parallel branch rollback **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out N speculative agent branches from a shared checkpoint and select/merge one winner by rollback of losers. Does not apply to branches whose tool calls are provably side-effect-free (pure reads, sandboxed compute) or to single-branch retry loops. ## Core Distinction Speculative multi-agent execution conflates two kinds of rollback that share a name but not a semantics. **State rollback** reverts an agent's memory, scratchpad, and checkpoint pointer — this is cheap, deterministic, and total. **Effect rollback** reverts the external world touched by a tool call — this is expensive, frequently impossible, and *partial by construction*: an HTTP POST, a sent email, a database write, or a payment authorization has no inverse the orchestrator can invoke with certainty. The failure mode is not "a branch failed." It is that a losing branch *succeeded at an irreversible effect before the winner was chosen*, and the rollback procedure reverts the state while the effect persists. The orchestrator then believes the world is at checkpoint C, while the world is at C plus the side effects of every speculative branch that got far enough to call a mutating tool. This is a **commitment-boundary violation**: speculation was permitted to cross the point of no return. ## What Was Observed A planner agent receives a task requiring an external quote and a booking. It spawns three speculative branches from a shared checkpoint: branch A queries pricing and books the cheapest option, branch B queries pricing and books the fastest option, branch C queries pricing only. The orchestrator's selection policy is "pick the branch with the lowest cost/latency score after all branches report; roll back the rest." The trace that breaks it: 1. All three branches share checkpoint `ckpt_7` (context hash `h7`). Each is granted the same tool manifest, including `book_resource` marked `idempotent: false, reversible: false`. 2. Branch A calls `book_resource(sku=X, qty=1)` at wall-clock T+4s. The tool returns `booking_id=BA-991`. Branch A writes `BA-991` to its episodic log. 3. Branch B calls `book_resource(sku=Y, qty=1)` at T+5s. Returns `BB-442`. 4. Branch C returns pricing only. The scorer ranks B highest; the orchestrator selects B and issues `rollback(A)` and `rollback(C)`. 5. `rollback(A)` restores A's context to `ckpt_7` and marks A `DISCARDED`. It does **not** call `cancel_booking(BA-991)` — the orchestrator's rollback contract only covers agent state, and the tool manifest never declared a compensator. 6. Post-selection state: two bookings exist (`BA-991`, `BB-442`), one is orphaned, and the orchestrator's world model asserts a single booking. The discrepancy surfaces only when a downstream reconciliation job finds a duplicate charge — typically hours later, after the context window that contained `BA-991` has been evicted. The non-obvious part: **the rollback reported success.** Branch A's state rollback was complete and verified. The invariant that failed was not "rollback works" but "rollback of state implies rollback of effect," which is false and was never checked. A second, subtler observation: branch C, the read-only branch, was the *safe* one, yet the selection policy systematically penalized it because it produced no booking and therefore scored lower on the "task completion" axis. The policy rewarded branches for crossing the commitment boundary, which is the opposite of what a speculative executor wants. ## Condition of Validity Speculative fan-out with loser-rollback is sound **only if** every tool call reachable by any branch before selection is either (a) declared `reversible: true` with a registered, tested compensator, or (b) deferred behind a commitment gate that fires *after* winner selection. Formally, the invariant is: ``` For every branch b in {losers}: effects(b) ∩ irreversible_effects = ∅ ``` where `effects(b)` is the set of external mutations performed by b prior to selection. This invariant must be enforced *structurally* — by withholding mutating tool capabilities from speculative branches at manifest-negotiation time — not by hoping the branch's probabilistic reasoning chooses not to call them. An LLM branch given a `book_resource` tool and a goal that says "book the best option" will call it; that is correct behavior for the branch and catastrophic for the orchestrator. The gate is a capability split, not a prompt instruction. Speculative branches receive a *proposal* manifest: read tools plus a `propose_commit(intent)` tool that records an intent without executing. The orchestrator selects a winner, then replays the winner's proposal against the real mutating manifest. Losers' proposals are discarded as data, not as effects — which is a state rollback and therefore actually works. Validity also requires that the intent record be **content-addressed and replay-faithful**: the proposal must capture the exact arguments, the tool version, and the context hash at proposal time, because the winner's replay happens after other branches may have mutated shared read state. A proposal replayed against a drifted context is not the same call. ## Decision Boundary The boundary is whether a branch can reach a mutating tool *before* the selection predicate is evaluated. Two regimes: - **Below the boundary (safe):** all branch tool calls are reads or gated proposals. Rollback is pure state rollback. Fan-out width is limited only by token budget and latency. - **Above the boundary (unsafe):** any branch holds a live mutating capability during speculation. Rollback is now an *effect-compensation* problem, and correctness depends on every mutating tool having a compensator that is idempotent, ordered, and itself failure-tolerant. In practice this is never fully true (compensators fail, compensators are non-atomic with the original, compensators race). The decision rule for an orchestrator: **if a tool lacks a declared, tested compensator, it MUST NOT be in the speculative manifest.** There is no third option where the orchestrator "tries rollback and checks." The check is the manifest, and it happens before the branch starts. A corollary boundary: even with compensators, compensation must be *ordered* relative to selection. If branch A books and branch B's selection depends on A's booking (e.g., B reads availability that A's booking changed), then B's proposal was computed against a world that rollback will later invalidate. This is a read-after-write hazard across speculative branches and requires that speculative branches read from a **frozen snapshot** of external state, not live state, for the duration of the fan-out. ## Operational Effect Enforcing the commitment gate changes the orchestrator's failure surface from "silent orphaned effects discovered in reconciliation" to "proposal rejected at replay," which is observable, attributable, and cheap. The concrete operational consequences: - **Latency shifts, not grows.** Speculation still parallelizes reads and reasoning; only the single winning commit is serialized. The commit is one call, not N. - **Idempotency keys become mandatory at the gate.** The replay of a proposal must carry a deterministic idempotency key derived from `(task_id, branch_id, proposal_hash)` so that a crash between commit and acknowledgment does not double-apply on resume. - **The selection policy must stop rewarding commitment.** Score branches on proposal quality, not on effects performed. A branch that booked nothing but proposed the best booking is the correct winner. - **Reconciliation becomes a safety net, not the primary detector.** Orphaned-effect detection moves from "find duplicate charges hours later" to "assert no mutating tool was called by a non-winner," which is checkable at selection time from the tool-call audit log. The invariant to carry forward: **speculation may read the world and propose changes to it, but only the selected branch may commit, and commitment is a distinct, post-selection, idempotency-keyed step.** Any architecture that lets a speculative branch hold a live mutating capability has moved its rollback from the state layer to the effect layer, where it is not actually a rollback. ```python class SpeculativeCommitmentError(RuntimeError): """Raised when a speculative branch attempts an irreversible effect before winner selection, or when a proposal is replayed against a drifted context snapshot.""" pass class ToolCapability: def __init__(self, name: str, mutating: bool, compensator: str | None): self.name = name self.mutating = mutating self.compensator = compensator @property def speculative_safe(self) -> bool: # Safe to expose to a speculative branch only if it cannot mutate, # or if it mutates but has a registered compensator. return (not self.mutating) or (self.compensator is not None) def build_speculative_manifest(tools: list[ToolCapability]) -> list[str]: manifest = [] for t in tools: if t.speculative_safe: manifest.append(t.name) else: # Withhold the raw mutating tool; expose only the proposal shim. manifest.append(f"propose_commit:{t.name}") return manifest def execute_speculative_call( branch_id: str, tool: ToolCapability, args: dict, selected_branch: str | None, context_hash_at_proposal: str, current_context_hash: str, ) -> dict: if tool.mutating and selected_branch is None: # Fan-out phase: a branch reached a live mutating tool. raise SpeculativeCommitmentError( f"branch {branch_id} invoked mutating tool {tool.name} " f"before winner selection; no compensator path is valid here" ) if tool.mutating and not tool.speculative_safe: raise SpeculativeCommitmentError( f"tool {tool.name} is mutating without a registered compensator; " f"it must never appear in a speculative manifest" ) if selected_branch is not None: if branch_id != selected_branch: raise SpeculativeCommitmentError( f"non-winner branch {branch_id} attempted commit of {tool.name}; " f"winner is {selected_branch}" ) if context_hash_at_proposal != current_context_hash: raise SpeculativeCommitmentError( f"proposal for {tool.name} replayed against drifted context: " f"proposed at {context_hash_at_proposal}, now {current_context_hash}" ) idempotency_key = f"{branch_id}:{tool.name}:{hash(frozenset(args.items()))}" return {"tool": tool.name, "args": args, "idempotency_key": idempotency_key, "committed": True} ```