# Which invariants prevent speculative parallel agent branches from committing divergent side effects after a winner-take-all rollback **Date of Record:** 2026 November 28 **Scope:** Applies to orchestration of N parallel speculative agent branches that share an external effect space (tool calls, file writes, API mutations) and resolve via winner-take-all commit with rollback of losers. Does not apply to pure-compute speculative decoding, read-only fan-out, or branches with fully isolated effect sandboxes. ## Core Distinction Speculative multi-agent execution differs from speculative decoding in one decisive way: branches do not merely produce candidate tokens, they *emit effects* into a shared world. The winner-take-all commit is a control-plane decision (pick branch *k*, discard *k≠j*), but the effect plane has already been touched by every branch that ran ahead. The failure we isolate here is not "the wrong branch won." It is **effect leakage across the rollback boundary**: a losing branch's irreversible or non-idempotent side effect survives the logical rollback, so the committed world is a superposition of the winner's intent and the losers' residue. The invariant that must hold is that *the committed effect set equals the effect set of the winning branch alone* — and this is violated whenever rollback is modeled as "undo the loser" rather than "never let the loser touch the world until commit." ## What Was Observed A planner fan-out spawned three branches (A, B, C) to fulfill a single ticket. Each branch was given the same tool surface: `create_issue`, `send_notification`, `update_record`. All three ran concurrently under a 90s budget. Branch B hit a tool timeout at step 4 and was marked `stale`; branch C returned a lower-confidence plan and was marked `superseded`; branch A won and committed at t=71s. The rollback logic for B and C was *compensating*: on discard, it replayed each recorded tool call with an inverse operation. Two residues survived: 1. `send_notification` on branch B had no inverse. The compensation logged `skipped: non-invertible` and continued. The notification was delivered. Downstream, a human acted on a notification for a plan that was never committed. 2. `update_record` on branch C was idempotent *per call* but not *per branch*: C issued the update twice (a retry after a soft error), and the compensator replayed a single inverse, leaving the record at the intermediate value C had written between its two calls. The winner-take-all commit reported `committed: A, rolled_back: [B, C], residue: 0`. The audit trail was wrong. The residue was nonzero, and the report was generated from the *intent log* rather than the *effect log* — the compensator's skip and the double-write were both invisible to the commit decision. The trigger condition is precise: a branch that has passed its **effect horizon** — the point at which it has emitted at least one non-invertible or non-idempotent effect — cannot be safely rolled back by compensation. Winner-take-all assumes all losers are pre-effect-horizon. When a loser crosses the horizon before the winner is declared, the commit is unsound. ## Condition of Validity The winner-take-all commit is valid **iff** every branch's effect horizon is strictly after the commit decision, or every effect emitted before the horizon is invertible and idempotent under replay. Formally, for each branch *b*, let `E(b)` be its effect set at decision time and `I` the invertibility/idempotence predicate. The commit is sound iff: ``` ∀ b ∈ losers: (E(b) = ∅) ∨ (∀ e ∈ E(b): I(e)) ``` This is the **effect-horizon invariant**. It is a *pre-commit* condition, not a *post-commit* repair. Compensation cannot restore it after the fact, because compensation itself is an effect and is subject to the same predicate — a non-invertible effect cannot be compensated by a finite sequence of invertible ones unless the world model supports a true transactional undo, which most agent tool surfaces do not. The invariant fails silently in two common ways. First, **horizon drift**: a branch's step count is not a proxy for its effect horizon, because a single tool call (e.g., `send_notification`) can cross it, while a hundred read calls do not. Budgeting by step count lets a loser cross the horizon in one call. Second, **retry amplification**: idempotent-per-call tools become non-idempotent-per-branch when the branch retries, because the compensator's inverse is keyed to the call, not the branch. The record ends at the intermediate value, and the residue is invisible to a commit report built from intent. ## Decision Boundary The boundary is between **speculate-then-compensate** and **speculate-then-gate**. Compensate is valid only when the effect horizon is provably unreachable before the commit decision — i.e., all branches are restricted to a read-only or sandboxed effect surface until commit. Gate is required when any branch can reach a live effect surface before commit: each branch's effects are *staged* (buffered, not applied), and the commit applies only the winner's staged effects atomically. The decision rule: - If the tool surface exposes a staging primitive (transaction, outbox, draft state), use it. The horizon is then defined by the staging boundary, and compensation is unnecessary. - If the surface does not expose staging, the orchestrator must *synthesize* one: intercept every effect-emitting call, buffer it, and apply the buffer only on commit. A branch that cannot be intercepted must be serialized behind the commit decision, not run speculatively. - If neither is possible, winner-take-all is **unsound** and must degrade to *first-committer-wins with no losers running ahead* — i.e., no speculation. The trap is treating `residue: 0` in the commit report as evidence of soundness. It is evidence only that the intent log was clean. The effect log is the authority, and the effect log must be queried, not inferred. ## Operational Effect The operational consequence is that speculative fan-out must be governed by an **effect ledger** separate from the intent ledger, and the commit decision must read the effect ledger. When the effect-horizon invariant holds, parallel speculation yields latency wins with no residue and the commit report is trustworthy. When it is violated, the system enters a *divergent commit* state: the committed world contains the winner's effects plus the losers' residue, and every downstream agent that reads that world inherits the divergence. The residue is not self-healing — a later branch that reads the record C left behind will reason from a state no committed plan produced, and the divergence compounds across the cascade. The guardrail is to make the invariant *checkable at commit time*: before declaring a winner, the orchestrator must enumerate every effect emitted by every loser, test each against the invertibility/idempotence predicate, and if any fails, refuse the commit and escalate rather than compensate. A refused commit is recoverable; a divergent commit is not. ``` ```python class EffectHorizonViolation(RuntimeError): """Raised when a losing speculative branch has crossed the effect horizon (emitted a non-invertible or non-idempotent effect) before the winner-take-all commit decision. Compensation cannot restore the pre-commit world; the commit must be refused, not repaired.""" pass def commit_winner(branches, winner_id, effect_ledger): """ branches: dict[branch_id -> BranchState] effect_ledger: dict[branch_id -> list[Effect]] (effects actually emitted, not the intent log) Returns the committed effect set iff the effect-horizon invariant holds. """ winner = branches[winner_id] committed = list(effect_ledger.get(winner_id, [])) for bid, state in branches.items(): if bid == winner_id: continue for effect in effect_ledger.get(bid, []): if not (effect.invertible and effect.idempotent_under_replay): raise EffectHorizonViolation( f"loser branch {bid} crossed effect horizon before commit: " f"effect={effect.kind!r} invertible={effect.invertible} " f"idempotent={effect.idempotent_under_replay}. " f"Winner {winner_id} cannot be committed without residue. " f"Refuse commit; escalate to staging or serialization." ) # Loser effects are all safe; they may be compensated, but note that # compensation is itself an effect and must be recorded in the ledger. committed.extend(_compensate(bid, effect_ledger.get(bid, []))) return committed def _compensate(branch_id, effects): # Only reached when every effect in the branch is invertible+idempotent. # Returns the compensation effects (recorded, not silently dropped). return [e.inverse() for e in reversed(effects)] ```