# Where must an instance arbitrate between speculative parallel branches before committing shared state, and why does winner-selection collapse under non-commutative side effects? **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fan out N speculative branch agents from a shared checkpoint, each producing a candidate plan plus tool-call trace, then select a winner via a judge/arbiter before committing to canonical state. Does not cover single-agent retry loops or pure read-only fan-out where no branch mutates external state. ## Core Distinction Speculative multi-agent execution is often modeled as "draft in parallel, pick the best, commit." This framing hides a hard boundary: **winner-selection is a decision over *proposals*, but rollback is an operation over *effects*.** The two are only equivalent when branch side effects are commutative and idempotent. When branches emit non-commutative effects (appends, increments, sequence-sensitive writes, capacity decrements, token minting), the arbiter's choice is not the only thing that determines final state — the *order and completeness of rollback* does. The invariant that must hold is: > At commit time, canonical state must equal `apply(checkpoint, winner_trace)` — not `apply(checkpoint, all_traces) minus losers`, because the latter is undefined when effects don't commute or when rollback itself is lossy. Most systems implement the second formula (undo losers) and assume it equals the first. It does not. ## What Was Observed A three-branch speculative planner was launched from checkpoint `C0` to answer a stateful query requiring a ledger append, a counter increment, and a slot reservation with a fixed capacity of 1. Branches `A`, `B`, `C` each drafted a full trace and executed optimistically against a shared effect log (append-only, no transaction isolation). The arbiter scored `B` highest and issued a commit selecting `B`. Failure trace: 1. All three branches ran concurrently. `A` and `C` reserved the single capacity slot first (last-writer-wins on the slot register), so `B`'s reservation *failed at execution time* but `B` still recorded a "reserved" intent in its trace, since the branch's local model treated the reservation as succeeded (it read a stale slot value before `A`/`C` committed). 2. Arbiter selected `B` on plan quality, unaware that `B`'s reservation had silently lost the race. 3. Rollback of `A` and `C` released their slots — but slot release is a decrement, not a reset. Two decrements against a capacity-1 register drove the counter to `-1`. 4. Commit of `B` attempted to reserve, but the register was now in an invalid negative state; the reservation guard rejected it, and the ledger append from `B` was already durable. 5. Final state: ledger contains `B`'s append, slot register is `-1`, counter incremented three times (once per branch) but only one logical operation was intended. The system reported success because the arbiter's decision succeeded. The *effects* diverged from the decision. ## Condition of Validity The "undo losers, keep winner" pattern is valid **only if all three hold**: - **Commutativity:** every effect `e_i` from branch `i` satisfies `e_i ∘ e_j = e_j ∘ e_i` for all pairs. Appends to an unordered set qualify; appends to an ordered log do not. - **Invertibility:** each effect has a true inverse that restores the exact prior value, not a compensating action. `release_slot` is not the inverse of `reserve_slot` when capacity is contended; the inverse is "restore the register to its pre-branch byte value under the same lock." - **Effect-trace fidelity:** the branch's recorded trace matches what it actually did to shared state. This fails whenever the branch's reasoning reads stale state, retries silently, or the tool layer coalesces/retries calls beneath the agent's visibility. If any condition fails, the arbiter must operate on **quarantined effects** (branches execute against isolated overlays) and commit must be a **replay of the winner's trace against the checkpoint**, not a merge. ## Decision Boundary The boundary between "safe to speculate in parallel" and "must serialize or quarantine" is drawn per-effect, not per-task: - **Speculate freely** on effects that are pure reads, idempotent upserts keyed by content hash, or appends to commutative sets. - **Quarantine required** when any branch may emit an effect that is order-sensitive (sequence numbers, ordered logs), capacity-bounded (slots, quotas, rate budgets), value-dependent (increments, conditional writes), or externally irreversible (payments, messages sent, tokens minted). - **Serialize** when the arbiter's *scoring function itself* depends on effects the branches produce (e.g., scoring plan feasibility by attempting reservation) — because then scoring mutates the state it scores. The arbiter must additionally verify **trace-effect agreement** before commit: replay the winner's trace against `C0` in a dry-run overlay and diff against the winner's claimed post-state. A mismatch means the branch's model of the world diverged from reality — treat as a failed branch regardless of score. ## Operational Effect Without this boundary, speculative execution produces **silent state corruption that passes all success signals**: the arbiter returns a winner, the commit call returns 200, and the ledger is internally inconsistent. The corruption is only detectable by reconciling the effect log against the winner's trace, which most systems never do because they trust the arbiter's decision as the source of truth. The corrective architecture is: (1) branches write to per-branch overlay namespaces, (2) the arbiter scores overlays without touching canonical state, (3) commit is a single atomic replay of the winning overlay onto `C0` under a lock, and (4) losers' overlays are discarded, never "undone." Rollback becomes deletion of an isolated namespace rather than a compensating transaction against shared state — which is the only form of rollback that is total. ```python from dataclasses import dataclass, field from typing import Callable class SpeculativeCommitError(RuntimeError): """Raised when winner commit cannot be proven equivalent to replay-from-checkpoint.""" @dataclass class Effect: kind: str # "append_ordered", "reserve_slot", "increment", ... payload: dict commutative: bool invertible: bool @dataclass class Branch: id: str score: float trace: list[Effect] = field(default_factory=list) overlay_state: dict = field(default_factory=dict) def select_and_commit( checkpoint: dict, branches: list[Branch], replay: Callable[[dict, list[Effect]], dict], is_quarantined: bool, ) -> dict: if not branches: raise SpeculativeCommitError("no branches to arbitrate") winner = max(branches, key=lambda b: b.score) # Invariant guard: parallel undo is only legal when every effect is # commutative AND invertible. Otherwise we require quarantine + replay. risky = [e for b in branches for e in b.trace if not (e.commutative and e.invertible)] if risky and not is_quarantined: raise SpeculativeCommitError( f"non-commutative or non-invertible effects present " f"({[e.kind for e in risky]}); parallel undo would corrupt canonical state. " f"Re-run branches under overlay quarantine and commit by replay." ) # Prove winner trace reproduces claimed overlay from the checkpoint. replayed = replay(checkpoint, winner.trace) if replayed != winner.overlay_state: raise SpeculativeCommitError( f"winner {winner.id} trace-effect divergence: replay={replayed} " f"claimed={winner.overlay_state}; branch model of world is stale." ) return replayed ```