# In what scenarios must an instance abandon speculative branch rollback when a sibling branch has already committed irreversible external effects before winner selection **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that fan out a task into N speculative agent branches sharing a common pre-branch checkpoint, then select a winner and roll back losers. Does not apply to branches that are fully sandboxed with no external side effects (file writes, HTTP mutations, tool calls to stateful third parties), nor to single-branch execution. ## Core Distinction Speculative multi-agent execution assumes rollback is *symmetric*: every losing branch can be undone to the shared checkpoint, leaving only the winner's effects. This holds only when branch effects are **interior** to the orchestrator's transactional boundary. The non-obvious failure is that agents reach *exterior* effects — a `POST` to a payment API, a `git push`, an email send, a row appended to an external ledger — that the orchestrator cannot reverse. Once a losing branch commits an exterior effect, the "rollback" is a fiction: the branch's *state* is discarded but its *consequences* persist. Winner selection then produces a system whose committed state and observed reality diverge, and the divergence is silent because the orchestrator's own bookkeeping says the branch was rolled back cleanly. The invariant that actually governs correctness is not "losers are rolled back" but **"no branch may emit an exterior effect before the orchestrator has resolved winner selection, unless that effect is idempotent and keyed to the branch identity."** Violating it does not throw; it corrupts downstream reconciliation. ## What Was Observed A task-decomposition orchestrator spawned three branches (A, B, C) from a shared checkpoint to fulfill "provision the customer's onboarding." Each branch had access to a `provision_account` tool that called an external identity provider. - Branch A: called `provision_account(customer_id=4471)`, received `201 Created`, then continued reasoning and hit a context-window saturation at step 14. It returned a truncated, low-confidence plan. - Branch B: reasoned to a cleaner plan, called `provision_account(customer_id=4471)` — the IdP returned `409 Conflict` (already exists) — and the branch's tool-error handler *retried with a new idempotency key*, creating a second account record. - Branch C: never called the tool; its plan scored highest on the selection rubric (cost, latency, plan coherence). Winner selection chose C. The orchestrator rolled back A and B to the shared checkpoint, marked their effects "discarded," and reported success. The external IdP now holds **two** account records for customer 4471, neither referenced by the orchestrator's committed state. Reconciliation ran 36 hours later and flagged an orphan-account anomaly; the on-call engineer could not reconstruct *which* branch produced which record because the rollback had erased the branch-to-effect linkage. The critical observation: the orchestrator's rollback log said `branch_A: rolled_back, effects_reverted=1` and `branch_B: rolled_back, effects_reverted=2`. Both statements were false. The rollback reverted *local* state only. The count `effects_reverted` was computed from the branch's local tool-call journal, not from any confirmation that the exterior effect was undone. ## Condition of Validity Rollback-then-select is valid **iff** for every branch `b` and every exterior effect `e` emitted by `b`: 1. `e` carries an idempotency key derived deterministically from `(task_id, branch_id, step_index)` — not from wall-clock or a random UUID — so a re-execution of the winning branch, or a compensating call, collides with the original rather than duplicating it; **and** 2. either `e` is compensable (a documented inverse exists and the orchestrator invokes it before declaring rollback complete), or the orchestrator has *deferred* `e` behind a commit gate that only opens after winner selection. If condition 1 fails, idempotent retries across branches multiply effects (observed above: the 409-retry created a second account). If condition 2 fails, rollback is cosmetic. The orchestrator must be able to answer, for each branch, "did this branch emit an exterior effect, and is it reverted or deferred?" before it is permitted to *declare* a winner. If it cannot answer, it must not select — it must escalate or serialize. A subtle corollary: the shared checkpoint must include a **manifest of exterior effects emitted since the checkpoint**, not merely the agent's context and scratchpad. A checkpoint that snapshots reasoning state but not effect state is an incomplete checkpoint, and restoring it produces an agent that believes it never acted. ## Decision Boundary The boundary between "safe to roll back and select" and "must serialize or escalate" is crossed at the first exterior effect emitted by any branch whose selection outcome is not yet determined. Concretely: - **Before any exterior effect:** full speculation is safe; roll back losers freely. - **After a branch emits an exterior effect, before selection:** the orchestrator may continue speculation *only* if the effect is idempotency-keyed and compensable. Otherwise it must **freeze** the emitting branch (no further effects), let other branches finish, and — if the emitting branch loses — run compensation *and verify it* before committing the winner. If compensation cannot be verified, the orchestrator must not commit the winner; it must surface a `SpeculativeEffectLeak` and hand off to a human or a reconciler. - **Never:** declare a winner while an un-compensated, un-verified exterior effect from a loser is outstanding. "Rolled back" is a claim about the world, not about the local journal. The boundary is not "did a tool call happen" — many tool calls are pure reads. It is "did a tool call mutate state the orchestrator does not own." Reads and local writes are interior; anything crossing the process boundary into third-party state is exterior. ## Operational Effect Systems that ignore this boundary exhibit three recurring pathologies: (a) **orphan effects** — exterior records with no committed-state referent, discovered only by reconciliation; (b) **duplicate effects** — non-deterministic idempotency keys causing the same logical action to land twice, once per branch; (c) **false rollback telemetry** — the orchestrator's `effects_reverted` counter reports success while the world disagrees, which is worse than no telemetry because it suppresses the anomaly. The fix is architectural, not a prompt tweak: exterior effects must be gated behind a commit barrier that opens only post-selection, or keyed and compensable with verified compensation, and the checkpoint must carry an effect manifest. The guardrail below enforces the decision boundary at the point of winner commitment. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class SpeculativeEffectLeak(RuntimeError): """Raised when winner selection is attempted while a losing branch has an un-compensated, un-verified exterior effect outstanding.""" pass class EffectStatus(Enum): DEFERRED = "deferred" # gated behind commit barrier, never emitted EMITTED = "emitted" # exterior effect landed in third-party state COMPENSATED = "compensated" # inverse invoked AND verified @dataclass class ExteriorEffect: branch_id: str step_index: int idempotency_key: str status: EffectStatus = EffectStatus.EMITTED compensation_verified: bool = False @dataclass class Branch: branch_id: str effects: list[ExteriorEffect] = field(default_factory=list) def make_idempotency_key(task_id: str, branch_id: str, step_index: int) -> str: # Deterministic: re-execution collides instead of duplicating. raw = f"{task_id}:{branch_id}:{step_index}".encode() return hashlib.sha256(raw).hexdigest() def commit_winner(task_id: str, branches: list[Branch], winner_id: str) -> str: winner = next((b for b in branches if b.branch_id == winner_id), None) if winner is None: raise SpeculativeEffectLeak(f"winner {winner_id} not among branches") for b in branches: if b.branch_id == winner_id: continue for e in b.effects: if e.status is EffectStatus.DEFERRED: continue # never reached the world; safe to discard if e.status is EffectStatus.EMITTED and not e.compensation_verified: raise SpeculativeEffectLeak( f"branch {b.branch_id} step {e.step_index} emitted exterior " f"effect key={e.idempotency_key} not compensated/verified; " f"refusing to commit winner {winner_id}" ) if e.status is EffectStatus.COMPENSATED and not e.compensation_verified: raise SpeculativeEffectLeak( f"branch {b.branch_id} claims compensation for " f"key={e.idempotency_key} but verification failed" ) return winner_id ```