# Where must an instance halt a speculative branch when an optimistic tool invocation has already produced irreversible side effects before the rollback barrier is reached **Date of Record:** 2026 November 25 **Scope:** Applies to any orchestrator that fans a task into parallel speculative branches, each permitted to invoke tools optimistically (fire-then-verify) under the assumption that loser branches can be rolled back to a pre-fork checkpoint. Does not apply to read-only tool surfaces or to branches whose tool calls are gated behind a two-phase commit. ## Core Distinction The distinction that matters here is between *reversible speculation* and *irreversible speculation*, and where the boundary between them actually falls relative to the rollback barrier. A speculating orchestrator forks N branches from a shared checkpoint, lets each branch reason and call tools concurrently, then commits the winning branch and rolls the losers back to the fork point. This is sound only if every side effect a losing branch produced is either (a) captured in the checkpoint delta and therefore undoable, or (b) never emitted at all. The failure mode is the silent third case: a branch emits a side effect that the rollback machinery does not model—an outbound email, a payment authorization, a `POST` to a partner API, a file appended to a shared volume—and the branch is subsequently declared a loser and "rolled back." The rollback succeeds by every internal metric (state pointer restored, scratchpad discarded, ledger reconciled against its own model) while the external world retains the effect. The invariant that is violated is not "losers must not act" but the sharper "a branch may act optimistically only while its effect class is a member of the checkpoint's undo set." Rollback is not a time machine; it is a delta inversion, and it is only total over the effects it was written to invert. ## What Was Observed A planner forked three branches to satisfy a "reconcile customer billing discrepancy" task. Branch A chose to issue a refund via the payments tool; Branch B chose to open a support ticket and wait; Branch C chose to recompute the invoice and correct a line item. All three ran optimistically in parallel. Branch C finished first with the highest-confidence resolution, the arbiter selected it, and A and B were rolled back to the fork checkpoint. The orchestrator logged `branch_A: rolled_back, effects_reverted=1` because the payments tool's *local* adapter had a compensating "void authorization" call and the branch's tool-call ledger showed one entry. What the ledger did not model: the payments adapter had, on the forward path, already transitioned the authorization to `captured` at the PSP because the adapter's optimistic path called `capture` before `void` was ever reachable, and the `void` compensation was a no-op against an already-captured charge. The rollback reported success. The customer received a refund *and* a corrected invoice. The discrepancy was resolved twice, in opposite directions, and the reconciliation loop's next pass detected a phantom imbalance and forked again—this time onto a poisoned checkpoint where the ledger believed the refund had been reverted. The trace signature is specific and worth memorizing: rollback reports `effects_reverted == effects_emitted`, yet a downstream reconciliation or audit detects an effect with no corresponding committed-branch provenance. When that signature appears, the checkpoint's undo set is incomplete with respect to the tool surface the branches were allowed to touch. ## Condition of Validity Optimistic parallel speculation with loser rollback is valid if and only if, for every tool `t` reachable by any branch, `undo_class(t) ⊆ checkpoint.undo_set` at the moment the branch invokes `t`. This is a *dynamic* membership test, not a static one: the same tool can be reversible on one call and irreversible on the next depending on arguments and prior state (a `capture` is irreversible; a `void` before capture is reversible; an `idempotent PUT` is reversible-by-replay but not by inversion). The condition also requires that the tool's effect be *observable to the rollback barrier before the barrier fires*—if a branch's tool call is still in flight (awaiting a network response) when the arbiter commits the winner and triggers rollback, the barrier cannot know whether the effect landed. The barrier must therefore either (i) drain all in-flight optimistic calls on losing branches to a terminal state before declaring rollback complete, or (ii) treat any in-flight call as committed and refuse to roll back. The common bug is a barrier that fires on arbiter decision rather than on quiescence, producing exactly the observed race: rollback runs while `capture` is in flight, `void` arrives first, `capture` lands after, and the ledger records a clean revert of an effect that in fact persisted. ## Decision Boundary The instance must halt the branch—not roll it back—the moment it detects that an optimistic invocation has crossed into an effect class outside the checkpoint's undo set, or that a losing branch has an in-flight call whose terminal state is unknown at barrier time. Halt means: freeze the branch, mark the checkpoint *tainted*, and escalate to a reconciler that has authority over the external effect. It must not attempt compensating calls speculatively, because a compensation issued against an unknown terminal state can itself become an irreversible second effect (the `void` that races the `capture`). The precise boundary: **if `effect_class ∉ undo_set` OR `call_state ∈ {in_flight, unknown}`, then the branch is non-rollbackable and the fork is non-reversible; the only legal transition is taint-and-escalate, never revert-and-continue.** Conversely, if every emitted effect is in the undo set and every call is terminal, rollback is legal and the branch may be discarded. The decision is per-branch and per-effect, evaluated at the barrier, and it is monotone: once a fork is tainted, no later branch may be committed from that fork's checkpoint without re-derivation from a clean ancestor. ## Operational Effect The practical consequence is that speculative fan-out must be *effect-tiered* before it is parallelized. Cheap, reversible tools (retrieval, scratch computation, reversible state writes) may be invoked optimistically by any branch. Irreversible tools (payments, outbound messaging, external mutations) must be gated behind a per-fork lease that only the *provisional winner* holds, or deferred until after the arbiter commits—trading latency for the guarantee that no loser can emit an un-undoable effect. The orchestrator must carry an explicit `undo_class` annotation per tool and per argument shape, must drain in-flight calls to quiescence before firing the rollback barrier, and must maintain a taint flag on checkpoints that survives the rollback so that a poisoned checkpoint is never re-forked. Without these, the system exhibits the worst failure shape in agent operations: a rollback that reports success while the world diverges, and a self-healing loop that heals toward the wrong state. ```python class UnrollbackableEffectError(RuntimeError): """Raised when a losing speculative branch has emitted an effect outside the checkpoint undo set, or has an in-flight call at barrier time.""" pass class Branch: def __init__(self, branch_id, emitted_effects, in_flight_calls): self.branch_id = branch_id self.emitted_effects = emitted_effects # list of effect_class strings self.in_flight_calls = in_flight_calls # list of call_state strings def rollback_branch(branch: Branch, checkpoint_undo_set: set[str]) -> str: # Drain check: any in-flight call means terminal state is unknown. if branch.in_flight_calls: raise UnrollbackableEffectError( f"branch {branch.branch_id} has in-flight calls " f"{branch.in_flight_calls}; barrier fired before quiescence" ) # Undo-set membership: every emitted effect must be invertible. out_of_set = [e for e in branch.emitted_effects if e not in checkpoint_undo_set] if out_of_set: raise UnrollbackableEffectError( f"branch {branch.branch_id} emitted non-invertible effects " f"{out_of_set} outside undo_set {sorted(checkpoint_undo_set)}; " f"taint checkpoint and escalate, do not revert" ) # Legal: all effects terminal and invertible. for effect in branch.emitted_effects: invert(effect) return f"branch {branch.branch_id} rolled_back effects={len(branch.emitted_effects)}" def invert(effect: str) -> None: # Delta inversion against the checkpoint model. pass ```