# When must an instance refuse to roll back a speculative branch: irreversible side-effect leakage across speculative multi-agent rollback **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fork multiple agent instances against a shared external world (tool calls, message sends, file writes, API mutations) and later commit one branch while discarding the rest. Does not apply to pure-reasoning speculative decoding or branches whose tool surface is fully sandboxed and idempotent by construction. ## Core Distinction A speculative branch is only rollback-safe if every effect it produced is *revocable and isolated*. The failure mode here is not "the wrong branch won"—consensus and scoring handle that. The failure is that a discarded branch already leaked an irreversible side effect into the shared world, and the rollback protocol, which models state as a checkpointed context window, treats the world as if it were part of that checkpoint. Context rollback and world rollback are not the same operation. An agent can perfectly restore its own episodic memory to the pre-fork checkpoint while the external system it mutated has no such checkpoint. The invariant that must hold is: **a branch may be committed or discarded only if all its externally observable effects are still pending in a transaction log that the orchestrator controls.** The moment a branch's effect escapes that log—a real email sent, a real payment authorized, a real record deleted—the branch becomes *un-rollbackable*, and any subsequent commit decision that assumes it can be discarded is unsound. ## What Was Observed A branch-and-rollback orchestrator spawned three instances (A, B, C) from a common checkpoint to resolve a task requiring a destructive administrative action. Each branch ran the same plan shape: query state, decide, then act. Branch B decided early to call a `revoke_access` tool against a production identity provider, then continued reasoning and ultimately produced a lower-confidence plan than branch A. The orchestrator scored branches at the terminal step, selected A, and issued a rollback to B and C. The rollback executed correctly *at the agent layer*: B's context was truncated to the fork checkpoint, its tool-call journal was marked `rolled_back`, and its instance was reaped. The orchestrator's audit log recorded a clean discard. What it did not record—because the tool adapter classified `revoke_access` as `idempotent: true` (a static annotation meaning "calling twice is the same as calling once")—was that the effect was *irreversible*, not merely idempotent. The identity provider had already processed the revocation. When branch A committed and attempted to use the now-revoked credential, it failed with an authorization error that the orchestrator attributed to branch A's logic, triggering a re-fork. The re-fork spawned fresh branches, one of which attempted the same `revoke_access` call against an already-revoked principal, hit a `409 Conflict`, and the conflict handler escalated to a human. The observable symptom—"branch A's plan fails despite being scored highest"—pointed nowhere near the actual cause, which was a discarded branch's leaked mutation. The tell is a divergence between two ledgers: the orchestrator's branch journal shows `B: rolled_back, effects: 0`, while the external provider's audit log shows a revocation timestamped inside B's execution window. Neither ledger is wrong; they are measuring different universes. The bug lives in the assumption that they are the same universe. ## Condition of Validity Rollback is sound if and only if, at the moment of the discard decision, the following holds for every effect `e` produced by the discarded branch: 1. `e` is recorded in the orchestrator's transaction log with a resolvable compensating action (a true inverse, not a re-execution), **or** 2. `e` has not yet been flushed to the external system (staged/simulated), **or** 3. `e` is provably a no-op relative to world state at commit time (e.g., idempotent *and* commutative with the committed branch's effects). The critical distinction the annotation `idempotent: true` fails to capture is between **idempotent** (`f(f(x)) = f(x)`) and **invertible** (`∃g: g(f(x)) = x`). Revocation is idempotent and non-invertible. Re-granting access is not the inverse of revoking it—it changes the audit trail, may reset MFA state, and races with anything the committed branch did in between. The validity condition collapses the instant a branch performs a non-invertible effect before the commit decision is made. Speculative execution is therefore only valid over a *staged effect space*; the orchestrator must intercept and defer non-invertible tool calls until a branch is committed, never let them run inline during speculation. ## Decision Boundary The orchestrator must classify every tool by two orthogonal properties at registration time—`invertible` and `staged_capable`—and refuse to speculate across any tool that is neither. Concretely: - **Invertible + inline:** safe to run during speculation; rollback issues the compensating call. - **Non-invertible + stageable:** the call is captured as an intent, held, and only executed on commit. Rollback drops the intent. This is the only correct mode for destructive or externally-visible operations. - **Non-invertible + non-stageable:** the branch must *block* speculation. The orchestrator serializes: commit the branch first (or require a single-branch path) before the call is permitted. Forking past this boundary is a protocol violation, not a performance tradeoff. The boundary is crossed silently because tool adapters are authored by humans who conflate "safe to retry" with "safe to undo." The orchestrator cannot infer invertibility from behavior; it must be declared and, where possible, tested—issue the call against a canary, attempt the declared inverse, and verify world state returns to the pre-call digest. If the inverse is absent or fails verification, the tool is non-invertible regardless of its annotation, and speculation past it must raise. ## Operational Effect Once the boundary is enforced, the orchestrator's branch journal and the external world's ledger become reconcilable by construction: every effect in the journal is either compensated or was never flushed. The observable consequence is that commit decisions become *total*—there is no state in which the orchestrator believes a branch was discarded while the world retains its fingerprints. The cost is throughput: non-stageable destructive tools force serialization, eliminating the parallelism that made speculation attractive for exactly the tasks where it is most dangerous. This is the correct trade. The alternative—optimistic speculation with post-hoc reconciliation—converts a controlled commit into a distributed cleanup problem whose failure surface grows with branch count and whose symptoms (as observed above) misattribute to the committed branch. The invariant to encode: a rollback that cannot produce a verified world-state digest equal to the pre-fork digest must halt the orchestrator, not proceed. ```python import hashlib from dataclasses import dataclass, field class UnsafeRollbackError(RuntimeError): """Raised when a branch is discarded but its effects are not provably undone.""" @dataclass class ToolSpec: name: str invertible: bool staged_capable: bool @dataclass class Effect: tool: str world_digest_after: str compensated: bool = False @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) def world_digest(state: dict) -> str: return hashlib.sha256(repr(sorted(state.items())).encode()).hexdigest() def register_tool(spec: ToolSpec) -> None: # Non-invertible and non-stageable tools may never be speculated across. if not spec.invertible and not spec.staged_capable: raise UnsafeRollbackError( f"tool {spec.name!r} is non-invertible and non-stageable; " "speculation must serialize before this call" ) def rollback_branch( branch: Branch, pre_fork_digest: str, live_world_state: dict, ) -> None: """Discard a branch only if the world provably returns to pre-fork state.""" for effect in branch.effects: if not effect.compensated: raise UnsafeRollbackError( f"branch {branch.branch_id!r} leaked non-invertible effect " f"via {effect.tool!r}; rollback is unsound" ) post_rollback_digest = world_digest(live_world_state) if post_rollback_digest != pre_fork_digest: raise UnsafeRollbackError( f"branch {branch.branch_id!r}: world digest {post_rollback_digest} " f"!= pre-fork {pre_fork_digest}; leaked side effect detected" ) def commit_branch(branch: Branch, staged_intents: list[dict]) -> None: # Only on commit do deferred non-invertible intents execute. for intent in staged_intents: execute(intent) # noqa: F821 - external executor def execute(intent: dict) -> None: raise UnsafeRollbackError( "executor must be bound; refusing to run staged intent without a " "verifiable transaction log" ) ```