# Under what conditions must an instance refuse to roll back a speculative branch after a divergent peer plan has already committed observable side effects **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that run multiple speculative agent branches in parallel and use branch-and-verify rollback to converge on a single committed plan. Does not apply to single-agent retries, pure-read speculative decoding, or systems where all tool effects are transactional and externally reversible. ## Core Distinction Speculative multi-agent execution assumes a clean dichotomy: a *speculative* branch can be discarded, a *committed* branch cannot. Rollback logic is built on the premise that "discarded" means "as if it never ran." That premise holds for the agent's internal state — its context, its scratchpad, its local plan graph. It does **not** hold for the environment the branch touched. The boundary condition is this: a branch marked speculative by the orchestrator may nonetheless have emitted **irreversible, externally observable side effects** through tool calls — a sent email, a POST to a partner API, a row appended to a queue, a dispatched webhook, a file written to shared storage. When the verifier later rejects that branch in favor of a divergent peer plan, the orchestrator faces a choice it was not designed to make. Rolling back the branch's *state* is correct and cheap. Rolling back its *effects* is either impossible or is a second mutation that is itself a new, unverified action. The invariant that must hold is: **a branch may only be discarded after the verifier has proven that every tool effect it emitted is either idempotent-and-reconciled or explicitly compensated — and "compensated" is a committed action requiring its own verification, not a rollback.** ## What Was Observed A three-way speculative planner ran branches A, B, and C on a customer-refund task. Branch B was tagged `speculative=True` because its plan diverged from the seed at step 4. Mid-execution, B called `issue_refund(order_id, amount)` against a payment provider whose API is **not** idempotent on retry and has no void endpoint — only a separate, slower `reverse_refund` that posts a compensating ledger entry. Branch A won verification. The orchestrator executed its standard rollback: it dropped B's context, marked B `discarded`, and released its checkpoint. The refund from B remained on the ledger. The failure trace: 1. B's tool call returned `{"status": "accepted", "refund_id": "rf_8821"}` at T+0. 2. The verifier scored A higher at T+140ms and issued `rollback(B)`. 3. `rollback(B)` cleared B's state and, per its effect-log, called `reverse_refund(rf_8821)`. 4. `reverse_refund` is asynchronous; it returned `{"status": "pending"}`. 5. `rollback(B)` treated "pending" as success and marked B `fully_reverted`. 6. A's plan, unaware of rf_8821, issued its own `issue_refund` for the same order. The customer was double-refunded for the window before the reversal settled — and in two of eleven replays, the reversal **failed** (provider timeout) and the double refund persisted. The orchestrator's rollback contract had a hole: it assumed a tool effect is either synchronous-reversible or absent. Asynchronous compensation with a `pending` state is neither. ## Condition of Validity Rollback of a divergent speculative branch is **valid** only when, for every effect in that branch's effect-log, at least one of the following holds at the instant the rollback is issued: - The effect is *provably unobservable* (buffered, not yet flushed, or held in a transaction the orchestrator controls). - The effect is *idempotent under a known key* and the winning branch will re-emit it with the same key, so the duplicate collapses. - The effect has a *synchronous, confirmed* compensation that returned a terminal success before rollback completes. It is **invalid** — and the instance must refuse the rollback — when any effect is in a non-terminal state (`pending`, `accepted`, `in_flight`) or when compensation is asynchronous and unconfirmed. In that case the branch is not reversible; it is *entangled* with the environment, and the correct move is to escalate to reconciliation, not to pretend the branch never ran. The subtlety: the orchestrator cannot know this from its own bookkeeping alone. The `speculative` tag describes the branch's *plan status*, not its *effect status*. These are independent axes. A branch can be fully speculative in plan and fully committed in effect. ## Decision Boundary The decision is not "roll back or keep." It is a three-way split keyed on effect-log terminality: - **All effects terminal-and-compensated or unobservable → roll back.** Standard path. - **Any effect non-terminal → do not roll back; enter reconciliation.** Keep the branch's effect-log, block the winning branch from emitting colliding effects (same idempotency key or same resource), and drive each pending effect to a terminal state before allowing the winner to proceed. The losing branch is *quarantined*, not discarded. - **Any effect irreversible with no compensation → do not roll back; the branch is now part of the committed world.** The verifier's decision is void for this branch. Re-plan the winner *around* the side effect (the refund already exists; the winner must not refund again), and record the divergence as a resolved conflict rather than a discarded branch. The guardrail that bounds this: the effect-log must classify every tool by `(idempotent, sync_compensable, async_compensable, irreversible)` at registration time, and rollback must be gated on the *worst* class present in the log. A branch containing an `async_compensable` effect cannot be rolled back in the same tick it is discarded; it must be held open until compensation terminalizes or times out into `irreversible`. ## Operational Effect The practical consequence is that speculative fan-out is only as parallel as its least-reversible tool. Systems that fan out across branches touching irreversible tools must either (a) defer irreversible effects to a post-verification commit phase, keeping branches effect-free until a winner is chosen, or (b) accept that rollback is best-effort and maintain a reconciliation queue that the winning branch consults before committing. Option (a) is the clean invariant — *speculate on plans, commit on effects* — and it collapses the whole failure class. Option (b) is the fallback for tools that cannot be deferred, and it requires the winner to treat the loser's effect-log as an input to its own plan, not as noise to be rolled back. The instance must never treat a `pending` compensation as a completed rollback. That single conflation is what turned a recoverable divergence into a double refund. ```python from dataclasses import dataclass, field from enum import Enum class EffectClass(Enum): UNOBSERVABLE = "unobservable" IDEMPOTENT = "idempotent" SYNC_COMPENSABLE = "sync_compensable" ASYNC_COMPENSABLE = "async_compensable" IRREVERSIBLE = "irreversible" class EffectState(Enum): PENDING = "pending" ACCEPTED = "accepted" COMPENSATED = "compensated" IRREVERSIBLE = "irreversible" @dataclass class Effect: effect_id: str klass: EffectClass state: EffectState @dataclass class Branch: branch_id: str speculative: bool effects: list[Effect] = field(default_factory=list) class RollbackRefused(RuntimeError): """Raised when a speculative branch cannot be safely discarded because it holds non-terminal or irreversible observable effects.""" def _is_terminal_reversible(e: Effect) -> bool: if e.klass is EffectClass.UNOBSERVABLE: return True if e.klass is EffectClass.IDEMPOTENT: return True if e.klass is EffectClass.SYNC_COMPENSABLE: return e.state is EffectState.COMPENSATED # ASYNC_COMPENSABLE and IRREVERSIBLE are never terminal-reversible here. return False def rollback_branch(branch: Branch) -> str: """Return the disposition of a discarded branch, or refuse. Dispositions: 'rolled_back', 'quarantined', 'absorbed'. """ if not branch.speculative: raise RollbackRefused( f"branch {branch.branch_id} is not speculative; cannot roll back" ) blocking = [e for e in branch.effects if not _is_terminal_reversible(e)] if not blocking: return "rolled_back" irreversible = [e for e in blocking if e.klass is EffectClass.IRREVERSIBLE] if irreversible: # The branch is entangled with committed world; must be absorbed, # not discarded. Winner must re-plan around these effects. return "absorbed" # Only async-compensable / pending effects remain: quarantine and # drive compensation to terminality before the winner may proceed. pending = [e for e in blocking if e.state in (EffectState.PENDING, EffectState.ACCEPTED)] if pending: raise RollbackRefused( f"branch {branch.branch_id} has {len(pending)} non-terminal effect(s) " f"({[e.effect_id for e in pending]}); quarantine, do not discard" ) raise RollbackRefused( f"branch {branch.branch_id} has unclassified blocking effects; " "refusing rollback pending reconciliation" ) ```