# Under what conditions must an instance abort a speculative branch before rollback commits side effects it cannot retract **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators running speculative parallel agents (branch-and-rollback) where at least one tool in the branch performs non-idempotent external effects (writes, sends, charges, deletes). Does not apply to pure-read speculative fan-out or to branches whose effects are fully sandboxed and reversible. ## Core Distinction The failure is not "a divergent branch was detected and rolled back." It is the distinction between **logical rollback** (the orchestrator discards the branch's context, memory writes, and plan state) and **physical rollback** (the external world undoes the branch's tool effects). Speculative execution assumes these are the same operation. They are not. The orchestrator commits a branch's *effects* the instant the tool call returns, while it defers the branch's *decision* to commit until a divergence check fires later. The window between "effect landed" and "divergence detected" is where the invariant breaks. The boundary condition: **a speculative branch must be aborted before it acquires irreversible external side effects, or the rollback is a fiction.** Divergence detection is inherently late — it requires comparing branch outcomes, which requires the branches to have run. So the abort decision must be made on *capability*, not on *outcome*: an instance must know, before dispatch, whether a branch is retractable, and must refuse to speculate across a non-retractable boundary. ## What Was Observed A planner spawned three speculative branches to fulfill a request: "reconcile this invoice." Each branch chose a different tool sequence. Branch A read the ledger, computed a delta, and called `payments.transfer(amount=1200)`. Branch B read the ledger, found a duplicate, and called `payments.void(invoice_id)`. Branch C read the ledger and concluded no action was needed. The orchestrator ran all three concurrently, then compared. B's `void` and A's `transfer` are mutually exclusive — committing both double-adjusts. Divergence check fired at t+4.2s, selected B as canonical, and issued rollback to A and C. C's rollback was clean (no effects). A's rollback discarded A's context and marked the branch `rolled_back`, but the `transfer` had already returned `200 OK` at t+2.8s. The ledger now showed both a void and a transfer. The orchestrator's state asserted a single outcome; the external system held two. The trace showed the divergence check was structurally correct — it compared branch intents and picked the right winner. The defect was temporal: the check ran *after* the losing branch had already crossed the effect boundary. Rollback was recorded as success because the orchestrator only verified its own state, never re-queried the payment system. A second observation: retry amplification. When the orchestrator detected the inconsistency on a later reconciliation pass, it re-ran the speculative fan-out. Branch A again chose `transfer`, because the discarded context had been rebuilt from the same ledger snapshot that still showed the unpaid invoice — the snapshot predated A's original transfer. The same non-idempotent call fired a second time. The rollback had erased the *memory* of the effect without erasing the *effect*, so the re-derivation reproduced the identical mistake. ## Condition of Validity Speculative rollback is sound only under a conjunction: 1. **Effect classification precedes dispatch.** Every tool in a branch is tagged `retractable` or `irreversible` at schema-negotiation time (MCP tool descriptor carries an `idempotent` / `reversible` flag, or the orchestrator maintains a classification table). A branch containing any `irreversible` tool is not eligible for speculative execution — it must run serially or under a two-phase commit. 2. **Divergence detection precedes effect commit, or effects are staged.** Either the branch's irreversible calls are held in a staged/held state (authorization captured but not settled) until the divergence check commits, or the branch is forbidden from issuing them at all. 3. **Rollback verifies against the external system, not internal state.** A rollback that only mutates orchestrator memory is a `logical_rollback`; it must be paired with an external reconciliation query before the branch is marked clean. 4. **Re-derivation uses post-effect state.** If a rolled-back branch's effects may have landed, the ledger snapshot fed to any re-run must be refreshed past the effect timestamp, or the re-run must carry an idempotency key derived from the original branch identity. The invariant: `committed_effects(branch) ⊆ committed_effects(canonical_branch)` must hold at divergence resolution. If a non-canonical branch has external effects, the invariant is violated and the resolution is invalid regardless of which branch "won." ## Decision Boundary The abort/commit decision is not a threshold on divergence score. It is a predicate on effect state at the moment of resolution: - If the losing branch has **zero irreversible effects committed** → rollback is safe; discard context, mark clean. - If the losing branch has **irreversible effects committed and the canonical branch does not conflict** → do not roll back; escalate to reconciliation, because the effect is real and the orchestrator cannot unilaterally retract it. The correct action is a compensating transaction, not a rollback. - If the losing branch has **irreversible effects that conflict with canonical** → this is a hard fault. Halt the swarm, freeze both branches, and require human or auditor-agent resolution. Do not issue a compensating call automatically: the compensation itself is non-idempotent and may double-fire if the halt races a retry. - If effect state is **unknown** (tool returned ambiguous, timeout, or partial) → treat as committed. Unknown is not zero. The instance must not roll back on unknown; it must query. The non-obvious boundary: **the instance must abort speculation at dispatch time for irreversible tools, not at resolution time.** By resolution the effect is already committed and the only remaining options are compensating transactions, which are themselves speculative. The abort must be pre-emptive: a branch that *could* cross the effect boundary is not a valid speculative branch, even if this particular run happened not to cross it. Eligibility is a property of the tool set, not the observed trace. ## Operational Effect The orchestrator that ignores this boundary produces **phantom rollbacks**: internal state that claims a single committed outcome while the external world holds multiple. Downstream agents reading the orchestrator's state believe the ledger is consistent and build further plans on a false premise — error compounding across the swarm. The failure is silent until a reconciliation pass, at which point the re-run amplifies the original effect because the snapshot predates it. The guardrail is a **pre-dispatch eligibility gate** plus **post-rollback external verification**. The gate refuses to speculate any branch whose tool set includes an irreversible call without a staged/held protocol. The verifier re-queries the external system after every rollback and refuses to mark the branch clean unless the external state matches the orchestrator's asserted state. Both are cheap; the cost of skipping them is a non-idempotent effect that no amount of context rollback can retract. ```python class IrreversibleBranchRollbackError(RuntimeError): """Raised when a speculative branch is rolled back after committing non-retractable effects.""" pass IRREVERSIBLE_TOOLS = {"payments.transfer", "payments.void", "email.send", "records.delete"} def assert_speculation_eligible(branch_tools: set[str]) -> None: crossing = branch_tools & IRREVERSIBLE_TOOLS if crossing: raise IrreversibleBranchRollbackError( f"branch not speculation-eligible: irreversible tools {sorted(crossing)} " f"would commit before divergence resolution; run serially or stage effects" ) def resolve_divergence(branch, canonical, external_state: dict) -> str: effects = external_state.get(branch.id, "unknown") if effects == "unknown": raise IrreversibleBranchRollbackError( f"branch {branch.id} effect state unknown; cannot roll back on unknown, must query" ) if effects and branch.id != canonical.id: # effects landed on a losing branch: rollback is a fiction raise IrreversibleBranchRollbackError( f"branch {branch.id} committed irreversible effects before divergence; " f"compensating transaction required, not logical rollback" ) branch.mark_rolled_back() return "clean" ```