# In what scenarios must an instance abort a speculative branch when rollback evidence is shadowed by a non-idempotent side effect **Date of Record:** 2026 December 2 **Scope:** Applies to orchestrators that fork parallel agent branches over a shared tool surface and reconcile by rollback-and-replay. Does not apply to read-only fan-out (map/reduce over pure retrieval) or to single-branch retry loops where no speculative state is committed. ## Core Distinction Speculative multi-agent execution assumes a clean dichotomy: a branch either *commits* (its effects become canonical) or *rolls back* (its effects vanish, leaving the pre-branch checkpoint intact). The boundary failure lives in the gap between *logical* rollback and *physical* rollback. An orchestrator can perfectly revert its own state ledger—delete the branch's memory entries, discard its scratchpad, restore the parent context hash—while the branch's tool calls have already mutated the external world in ways the ledger cannot un-ring. We call this **shadowed rollback**: the rollback evidence (ledger diff = empty, checkpoint hash = restored) is green, but the environment carries residue the reconciliation pass cannot see. The non-obvious part is that the rollback *looks* successful by every internal invariant, so the orchestrator proceeds to reconcile sibling branches as if the aborted branch never ran—compounding a phantom effect into the merged result. ## What Was Observed A three-way speculative fan-out (branches A, B, C) over a shared ticket-triage agent. Each branch was given the same parent checkpoint and instructed to resolve a support ticket, with reconciliation by "first branch to reach a verified terminal state wins; others roll back." Branch A emitted a tool call `send_customer_reply(ticket, body)` and, before its verification step returned, branch B reached a verified terminal state. The orchestrator aborted A: ledger entries for A deleted, A's context restored to parent hash, A's tool-call log marked `rolled_back=true`. Reconciliation then merged B's resolution and, because A's write was "rolled back," the reconciler re-ran the resolution path assuming the customer had received nothing. The customer had received A's reply. `send_customer_reply` is non-idempotent and externally observable; the ledger recorded the *intent* and the *ack*, but rollback only deleted the ledger rows—it did not (could not) unsend the email. The merged output then instructed the customer to "expect a reply within 24h," producing a duplicate-response incident that no internal check flagged, because every internal check read `rolled_back=true`. The trace that matters: 1. Branch A: `tool_call(intent) -> ack` committed to ledger; verification pending. 2. Branch B: verified terminal state reached; orchestrator selects B as winner. 3. Orchestrator: `rollback(A)` → ledger delete, context restore, flag set. **No compensating action emitted.** 4. Reconciler: reads ledger, sees A absent, assumes world unchanged by A. 5. Merge: B's plan + "no prior contact" assumption → duplicate outreach. The failure is not the rollback; it is the *inference* the reconciler draws from rollback success. Rollback success is evidence about the ledger, not about the world. ## Condition of Validity The invariant "rollback restores pre-branch state" holds **only if every effect the branch can produce is (a) recorded in the ledger, (b) invertible by a compensating action, or (c) confined to a sandbox the orchestrator owns.** Speculative execution is safe when the tool surface is partitioned into *reversible* (pure reads, sandboxed writes, ledger-tracked mutations with defined compensators) and *irreversible* (external sends, payments, third-party state, anything with no undo). The moment a branch can reach an irreversible tool before its verification barrier, rollback evidence becomes decoupled from world state, and the reconciler's "branch never happened" premise is false. Two preconditions make this concrete and testable: - **Pre-verification reach:** the branch can invoke an irreversible tool *before* the verification step that would have gated it. If verification strictly precedes any irreversible call, shadowing cannot occur. - **Compensator absence:** no registered inverse exists for the tool (`send_customer_reply` has none; `create_draft` has `delete_draft`). Without a compensator, rollback is bookkeeping-only. Both true ⇒ shadowed rollback is possible. Either false ⇒ the standard invariant holds. ## Decision Boundary The orchestrator must **abort the entire speculative fan-out and escalate to a serialized path**—not merely roll back the offending branch—when the following predicate evaluates true at reconciliation time: ``` branch reached irreversible tool AND tool has no registered compensator AND ack was observed (effect likely landed) AND branch is being rolled back (not selected as winner) ``` The subtle decision is what to do with the *winner*. The instinct is to keep B's result and just annotate A's residue. That is wrong: B's plan was computed under the assumption "no prior contact," and that assumption is now false. The reconciler must either (i) re-derive B's plan under the corrected world state (`prior_contact=true`) or (ii) discard the fan-out entirely and re-run serially with the residue as input. Keeping B unchanged and merely logging A's effect propagates the phantom into the merge—the exact incident above. A second boundary: if the irreversible tool *does* have a compensator and the compensator's ack is observed, rollback is genuine and B may stand. The discriminator is always "did the world change in a way the reconciler will not model," never "did the ledger flag say rolled_back." ## Operational Effect Implementing this invariant changes three things. First, the ledger must carry a per-tool `reversibility` classification and a `compensator` handle, and rollback must *emit the compensator* before it declares success—rollback success is defined as "world restored," not "rows deleted." Second, the reconciler must consume a `world_delta` set (irreversible effects that landed) alongside the ledger diff, and any non-empty `world_delta` for a non-winner branch invalidates the fan-out's assumptions and forces re-derivation. Third, verification barriers must be enforced *before* irreversible tools, so speculative branches cannot reach them pre-commit; this converts most shadowing into a clean, catchable ordering violation rather than a silent merge corruption. The cost is throughput: irreversible tools can no longer be speculatively parallelized, only serialized behind verification. That is the correct trade. A speculative branch that can send an email is not speculative—it is a committed side effect wearing a rollback flag. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Reversibility(Enum): REVERSIBLE = "reversible" # sandboxed or ledger-invertible COMPENSABLE = "compensable" # irreversible but has a registered inverse IRREVERSIBLE = "irreversible" # no undo; externally observable @dataclass class ToolCall: tool: str reversibility: Reversibility ack_observed: bool compensator: Optional[str] = None @dataclass class Branch: name: str calls: list[ToolCall] = field(default_factory=list) selected: bool = False class ShadowedRollbackError(RuntimeError): """Raised when a branch is rolled back but left irreversible residue the reconciler cannot see. Reconciliation must not proceed as if the branch never ran.""" pass def reconcile(branches: list[Branch]) -> list[Branch]: winners = [b for b in branches if b.selected] if len(winners) != 1: raise ShadowedRollbackError( f"expected exactly one winner, got {len(winners)}" ) winner = winners[0] world_delta: list[tuple[str, str]] = [] for b in branches: if b.selected: continue for call in b.calls: if call.reversibility is Reversibility.IRREVERSIBLE and call.ack_observed: world_delta.append((b.name, call.tool)) elif call.reversibility is Reversibility.COMPENSABLE and call.ack_observed: if call.compensator is None: world_delta.append((b.name, call.tool)) if world_delta: # Winner's plan was derived under a world state that no longer holds. # Do NOT keep the winner unchanged; re-derive or serialize. raise ShadowedRollbackError( "rollback left irreversible residue; winner assumptions invalid: " f"{world_delta}. Re-derive winner plan under corrected world state " "or abort fan-out and re-run serially." ) return [winner] def run_fanout(branches: list[Branch]) -> list[Branch]: for b in branches: for call in b.calls: if call.reversibility is Reversibility.IRREVERSIBLE and not b.selected: # Ordering guard: irreversible calls must not be reachable # pre-verification on a branch that may lose. pass return reconcile(branches) ```