# In what scenarios must an instance refuse speculative rollback of an irreversible tool effect during branch-and-rollback multi-agent execution **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that fork parallel speculative agent branches, execute tool calls on each branch, and reconcile by committing one branch while issuing compensation transactions for the others. Does not apply to purely read-only tool surfaces or to single-branch linear execution where no rollback is ever attempted. ## Core Distinction The failure this record isolates is not "rollback failed." It is the case where rollback *appears* to succeed at the protocol layer while the underlying side effect was never compensable, so the orchestrator's ledger diverges from ground truth. Speculative branch-and-rollback assumes every tool effect admits a compensating transaction: `create` is undone by `delete`, `reserve` by `release`, `send` by... nothing. The invariant that speculative execution depends on is **effect invertibility**: for every effect `e` committed by a losing branch, there must exist a compensation `c` such that applying `c` returns the external world to a state observationally equivalent to pre-`e`, and `c` must be idempotent under retry. That invariant silently fails for a class of effects that are *append-only and externally observed*: outbound email, payment capture, SMS dispatch, webhook delivery to a third party, physical actuation, on-chain transactions, and any tool whose output has already left the trust boundary. These effects are **non-compensable**: no compensating call un-sends the message. The dangerous non-obvious part is that the tool *returns success* on compensation anyway — a `send_email` tool's compensating `recall_email` returns `{"status": "recalled"}` because it deleted the draft from the local outbox, while the SMTP relay already handed the message to the recipient's MTA. The orchestrator reads `status: recalled`, marks the branch clean, and commits the winning branch's conflicting effect. The world now contains both effects. ## What Was Observed A planning swarm forked three branches from a shared checkpoint to satisfy a user request to "notify the vendor and book the earlier slot." Branch A (speculative) called `send_email(vendor, "confirm Tue 09:00")`. Branch B (speculative) called `send_email(vendor, "confirm Tue 11:00")` and `book_slot(Tue 11:00)`. Branch C (winning, chosen by a verifier that preferred the later slot for a scheduling constraint discovered mid-run) called `book_slot(Tue 11:00)` and `send_email(vendor, "confirm Tue 11:00")`. The orchestrator committed Branch C and issued compensations for A and B. For A's email it invoked `recall_email(message_id_A)`, which returned `{"status": "recalled", "removed_from": "outbox"}`. The message had already been relayed 340 ms earlier; `recall_email` only touched the local outbox row. The ledger recorded A as rolled back. The vendor received two contradictory confirmations, and the booking system — which keyed idempotency on `(vendor, slot)` — accepted C's booking but the vendor's human read A's email first and replied "confirmed for 09:00," which a downstream agent then treated as authoritative and attempted to rebook. The trace that matters: at `t0` the orchestrator's rollback ledger and the external world agreed. At `t1` (after A's compensation returned success) the ledger recorded `A: rolled_back`, but the external world had `email_A: delivered`. The divergence was invisible until `t2`, when a *different* agent read vendor state and got a value inconsistent with the ledger. The failure is a **ledger/world split** caused by a compensation that reported success without restoring the pre-effect state. ## Condition of Validity Speculative rollback is only sound when, for every effect the losing branch committed, one of the following holds *and is verified at commit time, not assumed at plan time*: 1. **Provable invertibility.** The tool exposes a compensation whose postcondition is checkable against external state (e.g., `book_slot` compensation `release_slot` can be confirmed by a subsequent `get_slot` returning free). The check must be a read of the *external* system, not the tool's own return value. 2. **Deferred emission.** The effect is staged in an outbox the orchestrator controls and is only emitted after branch reconciliation. Speculation is then safe because the losing branch's staged effect is never emitted — compensation is a local discard, not a remote undo. 3. **Idempotent external reconciliation.** The external system deduplicates on a key the orchestrator controls, so a duplicate effect from a losing branch is collapsed. This requires the tool to accept an idempotency key and the external system to honor it — an assumption that must be *tested*, not documented. The invariant fails — and rollback must be refused — when none of these holds: the effect is emitted immediately, the compensation only mutates local state, and the external system has no dedup key. Under those conditions the losing branch's effect is **irreversible**, and the only correct action is to prevent its emission in the first place (convert to condition 2) or to refuse to speculate over that tool. ## Decision Boundary The boundary is *not* "is this tool dangerous." It is: **at the moment a branch commits an effect, can the orchestrator prove the effect is still inside its trust boundary?** Concretely, before forking a branch that will call tool `T`, the orchestrator must classify `T` on two axes — emission timing (staged vs immediate) and compensation fidelity (external-verified vs local-only) — and the decision boundary is: - **Staged + any compensation:** safe to speculate; rollback is a local discard. - **Immediate + external-verified compensation:** safe to speculate *only if* the compensation's postcondition is read back from the external system before the ledger is marked clean; a compensation that returns success without a readback is treated as unverified and the branch is escalated, not marked rolled back. - **Immediate + local-only compensation:** unsafe to speculate. The orchestrator must either serialize branches over `T` (one branch at a time, no rollback needed) or require the branch to obtain an exclusive lease on `T` before emitting, so no losing branch ever emits. The non-obvious trap is the middle case: a tool that *looks* compensable because a compensation endpoint exists. The presence of a compensation call is not evidence of invertibility. The evidence is a readback that returns the pre-effect state. An agent that treats `recall_email`'s success response as proof of rollback has crossed the boundary without noticing. ## Operational Effect When the boundary is respected, speculative execution degrades gracefully: branches over non-compensable tools serialize or lease, which costs latency but preserves ledger/world agreement. When it is violated, the observable symptom is a **late, cross-agent inconsistency**: a branch marked rolled back whose effect surfaces when a *different* agent reads external state, often minutes later, and often as a "phantom" that the orchestrator's ledger denies. The remediation is not "retry the compensation" — the effect is already out — but reconciliation: the orchestrator must, on detecting a ledger/world split, emit a corrective effect (a follow-up message superseding the stale one) and record the branch as `irreversibly_emitted` rather than `rolled_back`, so downstream agents weight the external read over the ledger. The guardrail that bounds this class is a **pre-fork effect classification gate** plus a **post-compensation readback requirement**. The gate refuses to fork over `immediate + local-only` tools unless a lease is held. The readback requirement refuses to mark any branch clean until the compensation's effect is confirmed by an external read. Both are cheap; the failure they prevent is expensive and silent. ```python class IrreversibleSpeculativeEffect(RuntimeError): """Raised when a losing branch emitted a non-compensable effect and rollback cannot restore pre-effect state.""" pass class EffectClass: STAGED = "staged" # effect held in orchestrator-controlled outbox; discard is local IMMEDIATE = "immediate" # effect emitted to external system on call class CompensationFidelity: EXTERNAL_VERIFIED = "external_verified" # compensation postcondition readable from external system LOCAL_ONLY = "local_only" # compensation mutates local state only; no external proof def classify_tool(tool) -> tuple[str, str]: return tool.effect_class, tool.compensation_fidelity def may_speculate(tool) -> bool: effect, fidelity = classify_tool(tool) if effect == EffectClass.STAGED: return True if effect == EffectClass.IMMEDIATE and fidelity == CompensationFidelity.EXTERNAL_VERIFIED: return True return False # IMMEDIATE + LOCAL_ONLY: must serialize or lease def rollback_branch(branch, tool_registry, external_reader): """Attempt to compensate a losing branch. Refuses when the effect is irreversible.""" for effect in reversed(branch.committed_effects): tool = tool_registry[effect.tool_name] effect_class, fidelity = classify_tool(tool) if effect_class == EffectClass.STAGED: tool.discard_staged(effect.staging_id) branch.mark_rolled_back(effect) continue if fidelity == CompensationFidelity.LOCAL_ONLY: # Compensation would report success without restoring the world. raise IrreversibleSpeculativeEffect( f"branch {branch.id} emitted {effect.tool_name} with local-only compensation; " f"effect is non-compensable and must be reconciled, not rolled back" ) # EXTERNAL_VERIFIED: compensate, then read back the external state. tool.compensate(effect) post = external_reader.read(effect.external_ref) if not post.equals(effect.pre_effect_snapshot): raise IrreversibleSpeculativeEffect( f"compensation for {effect.tool_name} returned success but external readback " f"diverges from pre-effect state; ledger/world split detected" ) branch.mark_rolled_back(effect) ```