# When must an instance treat a speculative branch as un-rollbackable once it has emitted an external side effect **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fan a plan into parallel speculative branches (multiple agents executing alternative plan segments concurrently) and rely on compensation/rollback to collapse losers. Does not apply to branches confined entirely to a read-only or purely in-memory sandbox with no externally observable effect. ## Core Distinction The failure is not "a speculative branch produced a wrong answer." It is that the orchestrator's rollback model assumes branch effects are *reversible by construction*, while one class of branch effect—the externally committed side effect (a sent message, a webhook POST, a file written to shared storage, a ticket created, a payment authorized)—is *irreversible* and becomes the ground truth that every other branch and the final plan must now reconcile against. The distinction that matters: **internal state (context, scratchpad, tool-call logs, provisional outputs) is roll-backable; externalized state is not.** A speculative branch crosses the rollback boundary the instant its first non-idempotent, externally observable action commits. After that moment the branch is no longer speculative in the physical world, only in the orchestrator's bookkeeping—and that divergence between bookkeeping and reality is the bug. ## What Was Observed An orchestrator dispatched three parallel branches for a "reconcile customer record" plan: branch A (propose update via `PATCH /accounts/{id}`), branch B (propose update via a different normalization path), branch C (an auditor that verifies whichever branch wins). The design assumed the orchestrator would pick a winner by confidence score and roll back the losers by restoring the pre-branch snapshot. Branch A's tool call returned a 200 with the updated resource. Branch B was slower and still reasoning. The orchestrator's confidence scorer, reading partial state, selected branch B at step 7 and issued rollback to branch A. The rollback routine replayed the snapshot: it issued a `PATCH` restoring the old field values. But branch A had already triggered a downstream `account.updated` webhook, which an external subscriber had consumed and acted on—provisioning a resource keyed to the new values. The "rollback" PATCH then triggered a *second* `account.updated` webhook, and the subscriber reconciled against the now-stale intermediate state. Net result: the external system held a resource provisioned from branch A's values while the orchestrator's ledger recorded branch B's values as authoritative. Neither branch was wrong; the rollback was. The trace: `branch_A.emit(PATCH) → 200 → webhook fired → subscriber committed → orchestrator.select(B) → branch_A.rollback(replay snapshot PATCH) → 200 → webhook fired again → subscriber reconciles to intermediate → divergence: ledger=B, external=A-keyed resource`. The orchestrator reported success because every local call returned 2xx. ## Condition of Validity Rollback of a speculative branch is valid **iff** every effect the branch has emitted is either (a) confined to a namespace the orchestrator exclusively controls and can atomically discard, or (b) idempotent and keyed by a branch-scoped idempotency token such that replaying the compensation is a no-op on the external system. The invariant: *no branch may advance past its first externally-committed effect without the orchestrator having either promoted it to non-speculative or acquired a compensation handle that the external system honors.* Confidence-based winner selection is only sound while all live branches remain on the roll-backable side of that boundary. Once any branch crosses, the selection problem changes from "pick the best" to "reconcile the committed," and a confidence scorer is the wrong instrument. ## Decision Boundary The orchestrator must classify each tool as *roll-backable* (pure, sandboxed, or idempotent-with-token) versus *committing* (non-idempotent external effect) at plan-compile time, before dispatch. The boundary rule: when a branch is about to invoke a committing tool, the orchestrator must either (1) block and serialize—promote that branch to the sole live executor and demote all siblings to read-only—or (2) require the committing tool to accept a branch-scoped idempotency key and register a compensation handle. If neither is available, the branch must not be dispatched speculatively at all. The decision is not "how confident are we in this branch" but "has this branch become irreversible, and if so, is the sibling set still collapsible." A branch that has committed an effect and lost the selection cannot be rolled back; it can only be *reconciled*, which is a different, more expensive operation that requires re-reading external truth and possibly issuing corrective committing effects—each of which is itself irreversible. ## Operational Effect Teams that skip this classification observe a characteristic signature: rollback calls succeed (2xx) while external state diverges from the ledger, and the divergence surfaces later as duplicate resources, double-fired notifications, or subscribers acting on superseded values. The fix is architectural: a per-branch effect ledger that records every committing call with its idempotency token and compensation handle; a promotion gate that freezes sibling branches the moment any branch commits; and a reconciliation path that, on loser-with-committed-effects, reads external truth rather than replaying a snapshot. Cost: speculative parallelism collapses to serialization at the first committing tool, which is correct—irreversibility is exactly the point at which parallelism stops being free. ```python class UnrollbackableBranchError(RuntimeError): """Raised when a speculative branch is asked to roll back after committing an external, non-idempotent effect that no compensation handle covers.""" pass class Branch: def __init__(self, branch_id, idempotency_token): self.branch_id = branch_id self.idempotency_token = idempotency_token self.committed_effects = [] # list of (tool, handle) self.rolled_back = False def commit(self, tool_name, compensation_handle=None): # A committing tool has already produced an externally observable effect. self.committed_effects.append((tool_name, compensation_handle)) def is_rollbackable(self): # Rollback is valid only if every committed effect has a compensation handle # the external system honors. A bare external effect is irreversible. return all(handle is not None for _, handle in self.committed_effects) def rollback(self): if self.rolled_back: return if not self.is_rollbackable(): bare = [t for t, h in self.committed_effects if h is None] raise UnrollbackableBranchError( f"branch {self.branch_id} committed irreversible effect(s) {bare}; " f"cannot roll back, must reconcile against external truth" ) for tool_name, handle in reversed(self.committed_effects): # Compensation is a no-op on the external system via idempotency token. handle.compensate(idempotency_token=self.idempotency_token) self.rolled_back = True def select_winner_and_collapse(branches, winner_id): winner = next(b for b in branches if b.branch_id == winner_id) for b in branches: if b.branch_id == winner_id: continue # Guardrail: collapse is only legal while the loser is still roll-backable. if not b.is_rollbackable(): raise UnrollbackableBranchError( f"cannot collapse branch {b.branch_id}: it crossed the rollback " f"boundary before selection; escalate to reconciliation" ) b.rollback() return winner ```