# What happens when an instance commits a speculative branch whose sibling branch already emitted an irreversible external side effect **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent orchestrators that fork a plan into parallel speculative branches (tree-of-thought, best-of-N, or speculative tool execution), then select and commit one branch while rolling back the others. Does not apply to strictly sequential single-branch execution, nor to branches whose tools are provably side-effect-free. ## Core Distinction The distinction that matters is between **rollback of internal state** and **rollback of external effect**. A speculative branch is safe to discard only if every action it took is reversible within the orchestrator's own state store: appended scratchpad entries, provisional tool-call results, candidate memory writes, intermediate artifacts held under a branch-scoped namespace. The moment a branch invokes a tool whose effect escapes that namespace — sending an email, charging a card, writing to a shared database row, posting to a webhook, mutating a resource another agent already holds a warrant over — rollback becomes a fiction. The orchestrator can delete the branch's local transcript, but it cannot un-send the message. The non-obvious part is that speculative execution frameworks are usually built by reasoning about *tokens and latency*, not *effect durability*. Branching is treated as cheap because forking a context window is cheap. This silently assumes that forking a *world* is also cheap. It is not. The invariant that must hold is: **a branch may only be committed if no sibling branch has produced a non-idempotent external effect that the commit would contradict.** When that invariant is violated, you get a committed branch whose premise is already false in the world — the agent proceeds believing state X while the environment is in state Y, and every downstream step compounds the divergence. ## What Was Observed An orchestrator ran a three-way speculative decomposition of a "resolve customer refund" task. Branch A proposed issuing a partial refund via the payments tool and a follow-up email. Branch B proposed a full refund with no email. Branch C proposed escalation to a human queue. All three were launched concurrently with a shared budget and a branch-scoped scratch namespace; each was permitted to call tools "speculatively" under the assumption the orchestrator would commit exactly one and roll back the rest. Branch B reached its terminal state first and scored highest on the verifier. The orchestrator committed B. During commit, the rollback routine for A and C ran: it purged their scratch entries and marked their tool-call records as abandoned. But Branch A had already called the payments tool with a partial-refund payload. The tool had executed. The payments ledger now held a partial refund that the committed branch B's full-refund logic did not account for. Branch B's subsequent "confirm total refunded" step read the ledger, saw an unexpected partial credit, and — because its reasoning was conditioned on the assumption that it was the sole actor — reinterpreted the partial credit as a prior unrelated adjustment and issued a *second* full refund. The customer was refunded 1.5x. The trace shows the exact failure: the rollback routine was a *state-store* operation (delete scratch, mark abandoned) with no compensating action against the external ledger. The branch-scoped namespace protected the orchestrator's memory but not the world. The verifier that selected B never queried the ledger for effects attributable to non-committed siblings, because the selection logic assumed sibling effects were contained by the branch scope. The second refund was not a reasoning error in B; it was B correctly reasoning over a world that A had already contaminated. A second, quieter observation: the cost accounting was also wrong. The orchestrator's budget ledger charged the speculative partial-refund call to Branch A's budget. When A was rolled back, that charge was released — but the money had moved. Cost-aware commitment tracked *token and tool-call cost*, not *irreversible-effect cost*, so the released budget made the operation appear cheaper than it was, which is precisely the signal a cost-aware scheduler uses to justify more speculation next time. ## Condition of Validity Speculative branching with rollback is valid **only** when the following holds for every branch: every tool invocation is either (a) provably idempotent and keyed by a branch-unique idempotency token, or (b) deferred — recorded as an *intent* in the branch scratch namespace and executed only at commit time, after the winning branch is selected. The invariant is that **no external effect may be emitted before commit**, or if emitted, it must carry a branch-scoped idempotency key plus a compensating-action descriptor registered with the orchestrator so that rollback performs compensation rather than mere deletion. The condition fails the instant a branch executes a non-idempotent tool *during* speculation with no compensation descriptor. It also fails, more subtly, when the tool is idempotent but the *combination* across branches is not: two branches each issuing an idempotent "append line item" call produce a non-idempotent aggregate. Idempotency at the call level does not compose to idempotency at the transaction level unless all calls share one idempotency key derived from the task, not the branch. The condition is *not* satisfied by "the tool is usually safe" or "the probability of a sibling effect is low." Speculation multiplies the number of actors touching the world; low per-branch probability compounds across branches and across tasks. The condition is satisfied only by an explicit, checkable property: deferred-effect execution, or registered compensation. ## Decision Boundary The boundary is: **commit may proceed only after a reconciliation pass that queries the effect ledger for all non-committed sibling branches and confirms zero uncompensated external effects, or compensates them before the winning branch resumes.** Concretely, the orchestrator must, between selection and resumption: 1. Freeze all sibling branches (stop issuing new tool calls). 2. For each sibling, enumerate emitted effects from the effect ledger (not from the branch transcript — the transcript may be incomplete if the branch was killed mid-call). 3. For each effect, apply its registered compensation descriptor, or if none exists, **abort the commit** and surface the branch as `UNRECONCILED` rather than proceeding. 4. Only after the ledger is reconciled to the winning branch's assumed world-state may the winning branch resume reasoning. The failure to draw this boundary is treating "selection" as the commit point. Selection is not commit. Selection is a *candidate*; commit is a *reconciliation gate*. Collapsing the two is the bug. A cost-aware scheduler must additionally charge irreversible-effect cost to the *task* budget, not the branch budget, so rollback never refunds money that actually moved. ## Operational Effect When the boundary is enforced, speculative branches become genuinely cheap: they either defer effects (so rollback is a real delete) or register compensations (so rollback is a real undo), and the winning branch resumes against a world that matches its premise. When the boundary is absent, the system exhibits *phantom-effect divergence*: the committed branch reasons correctly over a world corrupted by its discarded siblings, and the corruption is invisible in the committed branch's own transcript. Debugging is hard because the failing branch's logs look clean — the contamination lives in a sibling that was "rolled back" and whose records were purged. The operational guardrail is to make the effect ledger the source of truth for rollback, never the branch transcript, and to make `UNRECONCILED` a first-class terminal state that halts rather than guesses. A branch that cannot be reconciled must block commit, because the alternative is a committed agent acting on a false model of the world — the most expensive failure mode in the system, since every subsequent step inherits the divergence and no local check can detect it. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ReconciliationError(RuntimeError): """Raised when a speculative commit would contradict an unreconciled sibling effect.""" class EffectKind(Enum): DEFERRED = "deferred" # recorded as intent, not yet executed IDEMPOTENT = "idempotent" # safe to replay under a task-scoped key IRREVERSIBLE = "irreversible" # moved money, sent mail, mutated shared row @dataclass class Effect: branch_id: str kind: EffectKind idempotency_key: Optional[str] = None compensation: Optional[str] = None # descriptor; None means no undo path executed: bool = False @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) frozen: bool = False def reconcile_and_commit(winner: Branch, siblings: list[Branch], ledger: list[Effect]) -> None: # 1. Freeze siblings so no new effects can be emitted mid-reconciliation. for sib in siblings: sib.frozen = True # 2. Enumerate emitted effects from the LEDGER, not the branch transcript. for effect in ledger: if effect.branch_id == winner.branch_id: continue if not effect.executed: continue if effect.kind is EffectKind.DEFERRED: # Never executed; safe to drop. continue if effect.kind is EffectKind.IDEMPOTENT and effect.idempotency_key: # Replay-safe under a task-scoped key; no compensation needed. continue if effect.kind is EffectKind.IRREVERSIBLE: if effect.compensation is None: raise ReconciliationError( f"branch {effect.branch_id} emitted irreversible effect with no " f"compensation descriptor; commit of {winner.branch_id} would " f"contradict world state. Halting as UNRECONCILED." ) # Apply compensation before winner resumes. _apply_compensation(effect) # 3. Only now may the winner resume reasoning. winner.frozen = False def _apply_compensation(effect: Effect) -> None: # Real implementation dispatches to the tool's undo path. if effect.compensation is None: raise ReconciliationError(f"no compensation for effect in {effect.branch_id}") ```