# Which invariants prevent speculative fan-out from committing orphaned side effects when a verifier branch wins after a sibling branch already mutated external state **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fan out N speculative agent branches over the same tool surface, race them against a verifier, and roll back losers. Does not apply to read-only fan-out or to single-branch retry loops where no branch commits external state before verification. ## Core Distinction The distinction that matters is between **branch-local rollback** and **side-effect rollback**. Speculative execution frameworks treat a losing branch as a state vector to be discarded: drop its context, reclaim its token budget, mark its checkpoint dead. This is correct for the branch's *reasoning* state. It is silently wrong for the branch's *effects* on the world. A branch that called `transfer_funds`, `send_email`, `git push`, or `db.delete` has already produced an irreversible transition outside the orchestrator's address space. When a sibling branch wins verification afterward, the orchestrator rolls back the loser's memory and proceeds as if only the winner existed — but the loser's writes remain. The invariant at stake is that **a branch may not be committed-to-world before the verification predicate that selects among it and its siblings has resolved**, or, where early commit is unavoidable, that every early effect must be *compensable* and its compensating transaction must be registered in the winner's commit record before the fan-out barrier releases. ## What Was Observed An orchestrator fanned out three branches to satisfy a task: "reconcile the invoice discrepancy for account 4471." Each branch received the same tool grant (read ledger, post adjustment, write audit note). Branch A proposed a $412 adjustment and executed `post_adjustment(4471, -412)` at t=1.8s. Branch B proposed a $0 adjustment (disputed charge) and executed nothing. Branch C proposed a $412 adjustment and executed `post_adjustment(4471, -412)` at t=2.1s. The verifier scored B highest on the "did you confirm the discrepancy is real" rubric and declared B the winner at t=3.4s. The orchestrator discarded A and C, released their contexts, and emitted a task-complete event with B's reasoning trace. The ledger, meanwhile, carried a −$824 net adjustment: A and C had both posted. Neither was rolled back because neither was a "loser needing compensation" — they were simply forgotten. The failure is not double-execution in the classic idempotency sense. It is **post-hoc loser selection after effect commit**. The verifier's decision function was sound; the fan-out contract was not. The orchestrator assumed the verifier's output ordered branches by *desirability*, when it needed to order them by *reversibility cost* as well. Branch B won on reasoning quality but was the only branch with zero external effects; A and C lost on reasoning but had already paid an irreversible cost. A second, subtler observation: the branches were not independent. A and C both read the same ledger snapshot, both computed the same adjustment, and both posted. This is **correlated speculation** — the fan-out bought diversity of reasoning but not diversity of effect, and the orchestrator's cost model (which budgeted for one adjustment) under-counted the true external cost by 2×. The cost-aware fan-out logic had priced *inference* tokens per branch but not *world mutations* per branch. ## Condition of Validity The rollback-by-discard model is valid only under a conjunction that is rarely checked: 1. **Effect isolation** — branches execute against a sandboxed, snapshot-and-restore-capable world (ephemeral DB transaction, forked filesystem, dry-run tool shim) such that commit is a separate, orchestrator-controlled step. 2. **Single-commit barrier** — exactly one branch's effects are applied to the real world, and that application happens *after* the verifier resolves, not during branch execution. 3. **Compensability** — where (1) and (2) cannot hold (real-time tools, external APIs, human-visible actions), every effect carries a registered inverse and the orchestrator's commit path is transactional across the winner's effects *and* the losers' inverses. Violating (1) without (3) is the observed failure. Violating (2) alone produces correlated double-commit. The invariant that prevents orphaned effects is therefore: **the fan-out barrier may not release until the winner's commit set and the losers' compensation set are jointly reconciled into a single durable record** — not merely until the winner is chosen. ## Decision Boundary The orchestrator must branch on whether a tool is *speculatable* before fan-out, not after. Classify each tool in the branch's grant: - **Pure / sandboxable** (reads, dry-runs, forked writes): safe to fan out freely; rollback = discard. - **Compensable** (postable with a known inverse, cancellable reservation): fan out permitted *only if* the inverse is registered at call time into a branch-scoped compensation log that survives branch death. - **Irreversible** (external email, third-party payment capture, human notification): fan-out must be **serialized behind the verification gate** — the branch proposes, the verifier selects, and only then does the winner's irreversible call fire. Speculating on irreversible tools is the boundary condition; crossing it without compensation is the defect. Cost-aware fan-out must price *mutation cost × expected loser count*, not just token cost. If the expected number of branches that reach the effect-commit step exceeds one, the fan-out is misconfigured for that tool class regardless of how cheap the inference is. ## Operational Effect With the joint reconciliation invariant enforced, the failure trace changes: A posts at t=1.8s and registers `post_adjustment(4471, +412)` as its inverse in the branch compensation log. C does the same at t=2.1s. The verifier selects B at t=3.4s. Because B has no effects and A and C are losers with live compensations, the commit path executes both inverses before emitting task-complete, and the ledger nets to zero adjustment with an audit note explaining the disputed charge. The cost is two compensating posts — bounded and visible — instead of an orphaned −$824. Where irreversible tools are involved, the serialization rule means the fan-out returns *proposals* only and the winner's irreversible call fires once, after selection, eliminating the orphan class entirely at the price of one extra round-trip. The residual risk after enforcement is **compensation failure**: an inverse that itself fails (the reversal post is rejected). This must escalate to a hard halt, not a silent continue, because the orchestrator can no longer assert world-state consistency. That escalation is the guardrail the invariant depends on. ```python class UncompensatedBranchEffect(RuntimeError): """Raised when a losing speculative branch committed a world effect whose inverse was never registered or never applied before barrier release.""" pass class BranchEffect: def __init__(self, branch_id: str, tool: str, inverse_call): self.branch_id = branch_id self.tool = tool self.inverse_call = inverse_call def release_fanout_barrier(winner_id: str, branches: dict, compensation_log: dict) -> list: """Reconcile winner commit set and loser compensations into one durable record. `branches[branch_id]` = {"effects": [BranchEffect, ...], "state": dict} `compensation_log[branch_id]` = list of registered inverse callables Returns the list of compensation results actually applied. """ applied = [] for branch_id, branch in branches.items(): if branch_id == winner_id: continue # winner's effects stand; its own inverses are not fired effects = branch.get("effects", []) registered = compensation_log.get(branch_id, []) if len(effects) != len(registered): # A loser mutated the world without a registered inverse. raise UncompensatedBranchEffect( f"branch {branch_id} produced {len(effects)} effect(s) but only " f"{len(registered)} compensation(s) were registered before barrier release" ) for effect, inverse in zip(effects, registered): try: inverse() applied.append((branch_id, effect.tool, "compensated")) except Exception as exc: # Compensation itself failed: halt, do not silently continue. raise UncompensatedBranchEffect( f"compensation for branch {branch_id} tool {effect.tool} failed: {exc}" ) from exc return applied ```