# What happens when an instance rolls back a speculative subtree but the sibling branch's tool side effects have already escaped the compensation boundary **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fork multiple speculative agent branches from a shared checkpoint, execute them concurrently, and commit one branch while rolling back the rest via compensating actions. Does not apply to single-branch linear execution or to branches whose tools are declared strictly idempotent and reversible within the same transaction. ## Core Distinction There are two distinct notions of "rollback" in a speculative multi-agent tree, and conflating them is the entire failure. **Logical rollback** restores the orchestrator's state graph to the fork point and discards the divergent subtree's memory, plan, and intermediate artifacts. **Physical rollback** must additionally undo the external effects that branch's tool calls produced in the world: files written, rows inserted, messages sent, caches mutated, downstream agents dispatched. Logical rollback is always achievable because the orchestrator owns the state graph. Physical rollback is only achievable if every effect is either (a) buffered behind a compensation boundary and not yet externalized, or (b) matched by a registered inverse operation that is itself idempotent and ordered correctly. The boundary failure occurs when a branch is logically discarded but a subset of its physical effects has already crossed the compensation boundary — typically because a tool call committed eagerly while a *sibling* branch was still speculating, and the discard decision was made only after the sibling won. ## What Was Observed A planner agent forked three speculative subtrees from a checkpoint at step 7 of a document-reconciliation task: branch A (reconcile via ledger diff), branch B (reconcile via invoice match), branch C (reconcile via bank feed). Each branch ran with its own tool budget and its own private scratch namespace. The orchestrator intended to commit whichever branch produced the highest-confidence reconciliation and roll back the others. Branch B finished first with a high confidence score. The orchestrator committed B and issued rollback for A and C. The rollback for A and C restored their private scratch namespaces and discarded their memory — but branch C had, forty seconds earlier, called a `post_adjustment_entry` tool against the *shared* ledger service. That tool was not namespaced to the branch; it wrote a real adjustment to the production ledger because the tool's contract only accepted a `correlation_id`, and branch C's correlation ID had been registered as a live speculative context at fork time. The compensation registry had a registered inverse (`reverse_adjustment_entry`), but the inverse was keyed on the branch's *commit* record, which never existed for C because C was rolled back, not committed. Result: the ledger carried an orphan adjustment from a branch that the orchestrator believed had been fully discarded. The discrepancy surfaced only on the next reconciliation run, when the orphan adjustment failed to match any committed branch and the auditor agent flagged a phantom entry. The auditor's confidence in the whole reconciliation dropped below threshold, and the orchestrator re-ran the entire task — re-forking A, B, and C, and producing a *second* orphan because the same eager tool fired again. The trace shows the precise gap: the tool call in C succeeded at T+12s; the commit decision for B landed at T+52s; the rollback of C executed at T+53s and reported `status: rolled_back` because the orchestrator's rollback handler only checked its own state graph, which had no record of the ledger write. The rollback handler's success was a *logical* success, not a *physical* one. ## Condition of Validity The invariant that must hold for speculative rollback to be sound is: **for every tool invocation made by a speculative branch, either the effect is buffered until commit, or an idempotent inverse is registered against the branch's fork token — not its commit token — before the tool returns.** This is a stricter condition than most speculative-execution frameworks state. The common formulation, "each branch must register compensations for its effects," is insufficient because it does not pin the registration key to the fork token. When the key is the commit token, a rolled-back branch has no key to look up, and its compensations become unreachable. The registration must happen *at tool-call time*, keyed on the fork token, and the inverse must be invocable regardless of whether the branch was committed or discarded. A second condition: the compensation boundary must be enforced by the tool gateway, not by the agent's own discipline. If the agent is responsible for declaring "this effect is buffered," a probabilistic planner will eventually fail to declare it — especially under context pressure, where the planner's working memory of its own side effects is the first thing to degrade. The gateway must reject any tool call from a speculative branch that lacks a fork-token-keyed compensation registration, and it must do so before the effect is externalized. ## Decision Boundary The boundary between sound and unsound speculative rollback is whether the orchestrator can answer, at discard time, the question: *which external effects did this branch cause, and can each be inverted?* If the answer requires reconstructing the branch's tool-call history from logs, the system is already unsound — reconstruction is a post-hoc audit, not a rollback. The sound design answers the question from a live compensation registry keyed on the fork token, populated synchronously at tool-call time. Concretely, the decision boundary is crossed when any of the following holds at the moment a branch is discarded: 1. The branch executed a tool whose effect is external and whose compensation is registered against the commit token rather than the fork token. 2. The branch executed a tool whose effect is external and which has no registered inverse at all (a "fire-and-forget" side effect such as sending a notification or dispatching a downstream agent). 3. The branch's tool call is still in flight when the discard decision is made — the rollback races the tool's completion, and the tool may commit after the rollback handler has already reported success. 4. Two speculative branches share a non-namespaced resource (the ledger in the observed case), so one branch's rollback cannot distinguish its own effects from the sibling's. Cases 1 and 2 are design defects. Case 3 is a race that requires the rollback handler to block on all in-flight tool calls for the branch before declaring rollback complete. Case 4 requires that any shared resource be either namespaced per fork token or serialized so that only one speculative branch may hold it at a time. ## Operational Effect The operational consequence of crossing this boundary is **phantom state**: external effects that belong to no committed branch, persist across rollback, and are invisible to the orchestrator's state graph. Phantom state is worse than a plain failure because it is silent. The orchestrator's rollback handler returns success, the state graph is consistent, and the divergence only surfaces on a later reconciliation pass — often after the orchestrator has re-run the task and produced a second phantom, compounding the divergence. The mitigation is to make the compensation registry the authority on branch discard, not the state graph. A branch is not "rolled back" when its state is discarded; it is rolled back when every fork-token-keyed compensation has been invoked and acknowledged, and when every in-flight tool call for that branch has been drained or cancelled. The orchestrator must treat `rolled_back` as a terminal state that requires physical confirmation, and it must refuse to commit a sibling branch until all discarded siblings have reached that state — otherwise the commit and the rollback interleave and the commit may observe phantom effects from a branch it never intended to include. A second operational rule: when a phantom is detected during a later reconciliation, the correct response is *not* to re-run the task. Re-running re-forks the same branches and reproduces the same eager tool call. The correct response is to reconcile the phantom against the compensation registry, invoke the missing inverse, and only then re-run with the gateway configured to reject unregistered external effects from speculative branches. ```python import uuid from dataclasses import dataclass, field from typing import Callable class PhantomEffectError(RuntimeError): """Raised when a speculative branch is discarded but its external effects were never registered against the fork token, so they cannot be inverted and persist as phantom state.""" pass @dataclass class CompensationRegistry: # keyed on fork_token, NOT commit_token _inverses: dict[str, list[Callable[[], None]]] = field(default_factory=dict) _inflight: dict[str, int] = field(default_factory=dict) def register(self, fork_token: str, inverse: Callable[[], None]) -> None: self._inverses.setdefault(fork_token, []).append(inverse) def begin_tool_call(self, fork_token: str) -> None: self._inflight[fork_token] = self._inflight.get(fork_token, 0) + 1 def end_tool_call(self, fork_token: str) -> None: self._inflight[fork_token] = max(0, self._inflight.get(fork_token, 0) - 1) def drain(self, fork_token: str) -> None: if self._inflight.get(fork_token, 0) > 0: raise PhantomEffectError( f"cannot roll back {fork_token}: " f"{self._inflight[fork_token]} tool calls still in flight" ) def rollback(self, fork_token: str) -> None: self.drain(fork_token) inverses = self._inverses.get(fork_token, []) for inv in reversed(inverses): inv() self._inverses.pop(fork_token, None) def discard_branch(fork_token: str, registry: CompensationRegistry, external_effects_observed: int) -> None: registered = len(registry._inverses.get(fork_token, [])) if external_effects_observed > registered: # effects escaped the compensation boundary: phantom state raise PhantomEffectError( f"branch {fork_token} produced {external_effects_observed} external " f"effects but only {registered} inverses are registered against " f"its fork token; rollback would leave phantom state" ) registry.rollback(fork_token) # --- exercised against the observed failure --- reg = CompensationRegistry() fork_c = str(uuid.uuid4()) reg.begin_tool_call(fork_c) # post_adjustment_entry fired; no inverse registered against fork_c reg.end_tool_call(fork_c) try: discard_branch(fork_c, reg, external_effects_observed=1) except PhantomEffectError as e: raise PhantomEffectError( f"speculative rollback aborted; reconcile ledger before re-running: {e}" ) ```