# Why does an instance abandon a speculative branch that already committed an irreversible side effect? **Date of Record:** 2026 November 21 **Scope:** Applies to orchestrators that fan a task out into parallel speculative branches (best-of-N, tree-of-thought, plan-then-race) where each branch may invoke tools optimistically before reconciliation. Does not cover single-branch sequential agents, pure reasoning rollouts with no external side effects, or systems where every tool call is gated behind a global lock. ## Core Distinction The interesting failure is not "a speculative branch produced a wrong answer." It is the moment the reconciler decides to **discard a branch whose tool invocation has already escaped the sandbox**—an optimistic write, a sent email, a charge, a `git push`, a state mutation on a shared resource. Rollback of *reasoning state* is free; rollback of *world state* is not. The boundary condition is: reconciliation logic that treats all branches as symmetric, reversible units of computation, when in fact only a subset of their effects are reversible. The reconciler reasons about branches as if they were pure functions, but they are partial functions with committed side effects. The invariant that must hold is a **monotonic commit lattice**: once a branch crosses an irreversibility threshold, it can no longer be "rolled back"—only *compensated*, and compensation is a new forward action, not a rewind. Any architecture that models rollback as a rewind over branches that have crossed this threshold is unsound. ## What Was Observed A planner decomposed a task ("reconcile two inventory ledgers and issue a correction") into three parallel speculative branches, each racing a different reconciliation strategy. Branch B2 adopted an optimistic strategy: it called `inventory.adjust(sku, delta)` on the live ledger *before* the reconciler had selected a winning branch, on the assumption that its plan would win and that a losing plan would simply be rolled back. The orchestrator's rollback primitive was `restore_checkpoint(branch_id)`, which snapshotted only the agent's *context window and scratchpad*—not the external ledger. The trace proceeded as follows: 1. B1, B2, B3 spawn with identical initial context and a shared `checkpoint_0`. 2. B2's reasoning converges faster; it invokes `inventory.adjust` with an optimistic delta of `-40`. 3. The ledger service accepts the write and returns `200 OK`. B2 records the tool result into its scratchpad. 4. B1 finishes with a higher-confidence plan that computes a delta of `-12` and, crucially, *also* invokes `inventory.adjust(-12)`—because B1 has no visibility into B2's write. 5. The reconciler scores B1 higher (better calibration, more supporting evidence) and selects B1 as the winner. 6. The reconciler calls `restore_checkpoint` on B2 and B3 to reclaim context budget and "undo" their work. 7. `restore_checkpoint` rewinds B2's *scratchpad*, erasing the record that `inventory.adjust(-40)` ever happened. The ledger now reflects `-52`, but the agent's memory of the world reflects `-12`. The result is a **divergence between world state and agent memory**: the ledger is off by 40 units, and no branch's episodic record contains the write that caused it. The error is silent. The reconciler reports success. The agent's semantic memory later distills "ledger reconciliation succeeded with delta -12," which is false. The non-obvious part: the failure is not that B2 wrote early. It is that **rollback erased the evidence of the write**. A system that failed to roll back B2's scratchpad would at least have a recoverable audit trail. The rollback primitive was *too effective* on the dimension it covered and *blind* to the dimension that mattered. ## Condition of Validity The failure requires all of the following to co-occur: - **Optimistic invocation is permitted**: branches may call tools before reconciliation selects a winner. If tools are gated behind a "commit only after reconciliation" barrier, this failure cannot occur (but the system loses the latency benefit of speculation). - **Rollback is scoped to agent state, not world state**: the checkpoint primitive covers context/scratchpad/memory but not the external effects of tool calls. This is the default in most orchestrators because world-state rollback is hard. - **Tool effects are non-idempotent or non-compensable without the record**: a `-40` adjustment cannot be undone without knowing it happened. If the tool is idempotent and self-describing (e.g., `set_balance(120)` rather than `adjust(-40)`), the failure is masked. - **Branches are blind to each other's side effects**: B1 does not see B2's write, so it computes against a stale world model. If branches share a live effect log, B1 would have seen the `-40` and adjusted. - **Reconciliation scores branches on reasoning quality, not on effect footprint**: the winner is chosen by plan quality, not by which branch's effects are already committed. This is the common case—scoring functions rarely incorporate "what has this branch already done to the world." When any of these is absent, the failure is bounded or absent. The dangerous configuration is the *default* one: optimistic tools + context-only rollback + blind branches + reasoning-only scoring. ## Decision Boundary The reconciler must classify every tool invocation along an **irreversibility axis** before permitting speculation: - **Reversible**: pure reads, idempotent sets, sandboxed writes. Safe to roll back by rewind. - **Compensable**: writes with a known inverse (`adjust(+40)` compensates `adjust(-40)`). Safe to roll back *only if the compensating action is recorded and executed*, and only if the compensation itself is idempotent. - **Irreversible**: sends, charges, publishes, deletes. **Must not be invoked optimistically.** These require a commit barrier: the branch proposes, the reconciler disposes. The decision boundary is: *a branch may not cross the irreversibility threshold until it is the unique winner of reconciliation, or until the orchestrator has recorded a compensation obligation that survives rollback.* The second clause is the subtle one—it means rollback must be **effect-aware**: it rewinds reasoning state but *preserves* a durable ledger of committed effects and their compensation obligations. Rollback that erases the effect record is strictly worse than no rollback. Concretely, the orchestrator must maintain a **write-ahead effect log** that is *outside* the checkpoint boundary. `restore_checkpoint` rewinds the branch's context but does not touch the effect log. On reconciliation, the orchestrator diffs the effect log against the winning branch's intended effects and issues compensations for any orphaned writes. The invariant: *no committed effect may exist without a corresponding entry in the effect log, and no rollback may remove an entry from the effect log.* ## Operational Effect When the invariant holds, speculative execution retains its latency benefit for reversible work while converting irreversible work into a propose-then-commit protocol. The cost is one extra round-trip for irreversible tools and a persistent effect log that grows with branch count. When the invariant is violated, the system exhibits **silent world-state divergence**: the agent's memory and the world disagree, the disagreement is not detectable from within any single branch, and semantic distillation will encode the false belief as fact. The failure compounds—later tasks reason against a corrupted world model and produce further divergences, each individually plausible. The guardrail is not "don't speculate." It is "make rollback effect-aware and make irreversible tools non-speculative." The two are separable and must be implemented separately: effect-aware rollback bounds the damage of a mis-speculated reversible write; the commit barrier prevents irreversible writes from ever needing rollback. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List class Irreversibility(Enum): REVERSIBLE = "reversible" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class SpeculativeRollbackError(RuntimeError): """Raised when rollback would erase a committed effect or when an irreversible tool is invoked optimistically before reconciliation.""" pass @dataclass class Effect: branch_id: str tool: str args: dict irreversibility: Irreversibility compensation: dict | None = None @dataclass class EffectLog: # Deliberately OUTSIDE the checkpoint boundary: never rewound. entries: List[Effect] = field(default_factory=list) def record(self, effect: Effect) -> None: self.entries.append(effect) def orphaned_for(self, winner_id: str) -> List[Effect]: return [e for e in self.entries if e.branch_id != winner_id] def invoke_tool( branch_id: str, tool: str, args: dict, irreversibility: Irreversibility, reconciled: bool, log: EffectLog, ) -> Effect: if irreversibility is Irreversibility.IRREVERSIBLE and not reconciled: # Commit barrier: irreversible tools may not run speculatively. raise SpeculativeRollbackError( f"branch {branch_id} attempted irreversible tool {tool!r} " f"before reconciliation; refusing optimistic invocation" ) effect = Effect(branch_id, tool, args, irreversibility) log.record(effect) return effect def restore_checkpoint(branch_id: str, log: EffectLog) -> None: # Rewinds reasoning state only. If the caller expects this to also # undo world effects, that expectation is the bug. committed = [e for e in log.entries if e.branch_id == branch_id] irreversible = [e for e in committed if e.irreversibility is Irreversibility.IRREVERSIBLE] if irreversible: raise SpeculativeRollbackError( f"cannot roll back branch {branch_id}: " f"{len(irreversible)} irreversible effect(s) already committed; " f"compensation required, not rewind" ) # Context/scratchpad rewind happens here; effect log is untouched. def reconcile(winner_id: str, log: EffectLog) -> List[dict]: """Issue compensations for orphaned compensable effects. Returns the compensation actions the orchestrator must execute forward.""" compensations = [] for effect in log.orphaned_for(winner_id): if effect.irreversibility is Irreversibility.COMPENSABLE: if effect.compensation is None: raise SpeculativeRollbackError( f"orphaned effect {effect.tool!r} from {effect.branch_id} " f"has no recorded compensation; world-state divergence is unbounded" ) compensations.append(effect.compensation) elif effect.irreversibility is Irreversibility.IRREVERSIBLE: # Should be unreachable if invoke_tool enforced the barrier. raise SpeculativeRollbackError( f"irreversible effect from losing branch {effect.branch_id} " f"survived into reconciliation; commit barrier was bypassed" ) return compensations ```