# What happens when an instance speculatively commits a side effect before its branch is selected: rollback impossibility across parallel agent branches **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan a task into N parallel agent branches (speculative decoding of plans, parallel tool-call races, best-of-k sampling with live tools) and then select one winner. Does *not* apply to branches executed in fully isolated, idempotent, or transactionally-wrapped sandboxes where every effect carries a compensating action. ## Core Distinction Speculative parallelism is safe only when a branch's *observable effects* are separable from its *internal reasoning state*. Most agent frameworks conflate the two: they treat "the branch ran" as a pure computation whose result can be discarded, while the branch has already mutated the world — written a file, sent an email, opened a ticket, POSTed to a third-party API, or advanced an external cursor. The boundary condition is this: **rollback of an agent branch is possible for its context and impossible for its side effects unless those effects were pre-declared as reversible and the branch was executed under a compensating-warrant discipline.** Selection among speculative branches is a *commit protocol*, not a comparison operator, and it fails at exactly the moment a losing branch has already produced an irreversible effect. ## What Was Observed An orchestrator spawned four branches of a "reconcile customer records" task. Each branch was given the same goal and a `crm.update` tool. Branches 2 and 3 converged on the same fix and both issued the update; branch 1 issued a *different* update based on a stale retrieval; branch 4 abstained. The selector, running after all four returned, scored branch 3 highest and committed it. The system recorded a clean success. In reality the record had been written three times: branch 1's divergent write was applied first, then overwritten by branch 2, then overwritten again by branch 3. The audit log showed one logical commit and three physical writes. A downstream consumer that had polled between branch 1 and branch 2 observed the divergent state and propagated it to a billing pipeline. The rollback path — "discard losing branches" — was a no-op, because discarding a branch's context does not retract its HTTP calls. The failure trace has a consistent shape: 1. **Fan-out with live tools.** The orchestrator gives every branch real tool handles rather than a write-buffer or a scoped credential. Branch count N multiplies side effects by N. 2. **Non-idempotent effect.** The tool has no idempotency key tied to a *logical* intent; each branch generates its own key, so the backend sees N distinct writes rather than N retries of one write. 3. **Late selection.** Selection happens after branch completion, not at a barrier before effects are released. The window between first effect and selection is unbounded by design. 4. **Rollback as context discard.** The orchestrator implements "rollback" as dropping the losing branch's message history and scratchpad. This reverts reasoning, not state. 5. **Replay divergence.** On retry, the surviving branch re-reads state that now includes the losing branches' writes, producing a different plan than the one that was scored — the committed decision no longer corresponds to the state it was evaluated against. The last point is the subtle one: even if a losing branch's write is *harmless in isolation*, it changes the input distribution for the winner's subsequent steps. The winner was scored against a pre-write world and now executes in a post-write world. This is a verification replay discrepancy masquerading as a successful commit. ## Condition of Validity The invariant that makes speculative branching sound is a **two-phase commit over effects, with the selection barrier placed before effect release**: - Every branch executes against a *staged* effect layer: tool calls are recorded as intents (target, payload, idempotency key derived from `(task_id, logical_intent)`, preconditions) but not dispatched. - Selection runs on branch *results plus staged intents*, with the world held fixed at the snapshot the branches were forked from. - Only the winning branch's staged intents are dispatched, in order, under a single commit token. Losing intents are dropped without ever touching the backend. - Any branch that cannot be staged — because the tool is inherently live (e.g., a real-time market query, a non-transactional third-party API) — is marked *non-speculatable* and must run in a serialized phase after selection, never in parallel with speculative branches. The condition of validity is therefore: **a branch is speculatable iff all of its effects are stageable and its reads are served from the fork snapshot.** Violate either half and rollback is a fiction. The common violation is the read half: branches are staged for writes but read live state, so branch 1 sees branch 2's uncommitted-but-applied write and diverges. Snapshot isolation is not optional; it is the load-bearing wall. ## Decision Boundary The boundary is not "how many branches" but "at what point does a branch's effect become externally visible relative to the selection barrier." The decision rule: - If the effect layer supports staging with per-intent idempotency keys **and** reads are snapshot-isolated → run N branches in parallel, select, commit winner's intents atomically. Safe. - If the effect layer supports staging but reads are live → the branches are not independent; parallel execution is a race, not speculation. Serialize or add a read-barrier with optimistic concurrency tokens, rejecting branches whose read-set version advanced. - If the effect layer does not support staging (live-only tool) → the tool must be excluded from speculative branches entirely. A branch that *might* call it must be marked non-speculatable at plan time, not discovered at call time. - If a branch has already dispatched an irreversible effect and is then deselected → you are not rolling back; you are compensating. That requires a declared inverse operation and a reconciliation pass. If no inverse exists, the correct action is to *halt and escalate*, never to record a clean success. The failure mode to guard against is the orchestrator that reports success while having applied effects from deselected branches. Success must be defined as "the committed intent set was dispatched exactly once and no intent outside it reached the backend," not "a winning branch was chosen." ## Operational Effect The practical consequence is that speculative parallelism moves the correctness burden from the selector to the effect layer. Teams that add branches to reduce latency or improve plan quality silently convert their tool layer into a concurrency hazard. The observable symptoms are: duplicated writes with distinct idempotency keys, downstream consumers observing transient divergent states, replay producing different plans than were scored, and audit logs undercounting physical effects relative to logical commits. The guardrail is a staged-effect executor with a commit token and a hard rule that deselected branches never dispatch. Where staging is impossible, the branch is non-speculatable and the orchestrator must refuse to fan it out — an explicit refusal is cheaper than a silent double-write. ```python from dataclasses import dataclass, field from typing import Any class SpeculativeRollbackViolation(RuntimeError): """Raised when a deselected branch has already produced an irreversible effect.""" @dataclass class StagedIntent: branch_id: str logical_intent: str payload: dict[str, Any] idempotency_key: str reversible: bool @dataclass class Branch: branch_id: str score: float staged: list[StagedIntent] = field(default_factory=list) dispatched: list[StagedIntent] = field(default_factory=list) class SpeculativeExecutor: def __init__(self) -> None: self._committed: set[str] = set() def dispatch(self, intent: StagedIntent) -> None: # Backend deduplicates on idempotency_key; a second dispatch of the # same logical intent is a no-op, a dispatch of a new key is a write. if intent.idempotency_key in self._committed: return self._committed.add(intent.idempotency_key) def commit(self, branches: list[Branch]) -> Branch: winner = max(branches, key=lambda b: b.score) for branch in branches: if branch is winner: continue for intent in branch.dispatched: if not intent.reversible: raise SpeculativeRollbackViolation( f"branch {branch.branch_id} dispatched irreversible " f"intent {intent.logical_intent!r} before selection; " f"cannot roll back — halt and escalate" ) for intent in winner.staged: self.dispatch(intent) return winner ```