# Which invariants prevent speculative branch reconciliation from silently committing orphaned side effects in multi-agent rollback **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent systems where one orchestrator agent forks speculative execution branches (parallel worker agents) and later reconciles by committing exactly one branch while rolling back the others. Does not apply to single-agent retry loops or to branches that perform no externally observable side effects. ## Core Distinction Rollback of an agent branch is not the inverse of execution. An agent branch is a *sequence of irreversible external commitments* (tool calls, writes, messages, payments) interleaved with *reversible internal state* (context, scratchpad, plan). The distinction that matters is between **logical rollback** — discarding a branch's context and declaring it dead — and **physical rollback** — undoing the effects its tool calls already emitted into the world. Most speculative-execution frameworks implement the former and assume it implies the latter. It does not. The failure mode is therefore not "the wrong branch won." It is: the orchestrator correctly selects one winning branch, correctly marks the losing branches as rolled back, and then commits the winner — while the losers' already-emitted side effects remain live in the environment. The reconciliation is internally consistent and externally corrupt. ## What Was Observed A three-way speculative fan-out: a planner agent forks `A`, `B`, `C` to attempt the same task (provision a resource, then record its identifier in a shared registry). Each branch is given a scoped tool grant and a 90-second wall-clock budget. The orchestrator uses a first-valid-wins policy with a reconciliation barrier: it waits for all branches to reach a terminal state, picks the branch whose self-reported verification score is highest, commits it, and issues `rollback` to the others. The trace that broke: 1. Branch `B` completed its provisioning tool call at t=41s, receiving a live resource handle `res-7f2a`. It then stalled on a downstream verification call. 2. Branch `A` completed at t=58s with a lower verification score but a fully consistent registry write. 3. At t=90s the barrier fired. `B` was still mid-verification. The orchestrator scored `B` on its *partial* self-report, found it lower than `A`, selected `A`, and sent `rollback` to `B` and `C`. 4. `rollback` on `B` discarded its context and marked it dead. It did not — could not — call the deprovisioning tool, because the deprovisioning capability had never been granted to `B` (only `provision` was in its scope; the orchestrator held `deprovision`). 5. The orchestrator committed `A`. The registry now contained `res-9c11` (from `A`). `res-7f2a` from `B` remained live, unregistered, and billing. 6. A later reconciliation pass found an orphaned resource with no owning branch and no registry entry. It could not attribute it, because `B`'s context — the only record that `B` had ever touched `res-7f2a` — had been destroyed by the rollback. The orphan was not a race condition. Every step was ordered correctly. The bug is structural: **the rollback operation destroyed the provenance needed to perform the physical rollback, and the branch that emitted the effect lacked the capability to undo it.** ## Condition of Validity The invariant that must hold for speculative rollback to be sound: > For every branch `b` and every external side effect `e` emitted by `b`, there must exist, at the moment `b` is marked rolled-back, (i) a durable record attributing `e` to `b`, and (ii) a live compensating capability reachable by the orchestrator that can invert `e`. If either is absent, `b` must not be rolled back — it must be *quarantined* and escalated. Two corollaries that are routinely violated: - **Capability symmetry.** The grant that permits a side effect must be paired with a compensating grant held by whoever performs rollback. Asymmetric grants (`provision` without `deprovision`) make rollback unexecutable by construction. The orchestrator must hold the inverse, or the branch must be required to emit a compensation token (a handle plus an idempotent undo call) as part of the effect itself. - **Provenance durability under rollback.** Rollback must be a *state transition that preserves the audit record*, not a deletion. Destroying the branch's context while its effects are live converts a recoverable orphan into an unattributable one. The branch's effect ledger must be written to durable storage *before* the effect is emitted, not reconstructed from context afterward. The condition fails silently when the branch's self-reported score is used as the selection signal, because a stalled branch reports a *low* score precisely because it has not finished — and low score triggers rollback of the branch most likely to have live, unverified effects. ## Decision Boundary The boundary between safe rollback and required quarantine is determined by the effect ledger, not by the branch's terminal status: - **Roll back** only when the branch's effect ledger is complete (every emitted effect has a recorded compensation handle) and every handle's compensating capability is reachable. This is the common case for branches that failed before emitting anything, or that emitted only effects with paired inverses. - **Quarantine and escalate** when the ledger is incomplete, when any effect lacks a compensation handle, or when the branch is mid-effect at barrier time (the effect may be partially applied — neither committed nor absent). Quarantine means: freeze the branch, preserve its context and ledger, mark its effects as *held*, and block the winner's commit if the winner's effects alias any held effect. - **Never commit over a held effect.** If branch `A`'s winning commit would write to a resource that a quarantined branch `B` also touched, the commit must block until `B`'s effect is resolved. Allowing the commit to proceed is how two branches end up owning the same resource with divergent registry entries. The selection signal must also be separated from the rollback decision. A branch's score answers "should this branch win?" It must not answer "is this branch safe to discard?" Those are independent predicates, and conflating them is what caused the trace above. ## Operational Effect The practical consequence is that speculative multi-agent execution must budget for a **reconciliation ledger** as a first-class component, not an afterthought. Concretely: - Every tool call that emits an external effect writes an intent record (branch id, effect id, compensation handle, idempotency key) to durable storage *before* the call returns. The ledger is append-only and survives branch death. - The orchestrator, not the branch, holds compensating capabilities, or the branch is required to return a compensation token it cannot itself revoke. - Barrier timeout produces *quarantine*, never *rollback*. A timed-out branch is presumed to have live effects until the ledger proves otherwise. - The winner's commit is gated on a scan of the ledger for aliased effects from non-winning branches. Systems that skip this do not fail loudly. They pass their reconciliation assertions, commit a consistent-looking winner, and leak orphaned effects that surface hours later with no provenance. The invariant is cheap to state and expensive to retrofit: **rollback is only valid where compensation is reachable and provenance is durable.** Where either is missing, the correct action is to stop, not to discard. ```python from dataclasses import dataclass, field from typing import Optional class UnreconcilableRollbackError(RuntimeError): """Raised when a branch cannot be safely rolled back: its effects are live and either unattributable or uncompensable. The branch must be quarantined.""" @dataclass class EffectRecord: effect_id: str branch_id: str compensation_handle: Optional[str] # None => no inverse reachable idempotency_key: str @dataclass class Branch: branch_id: str terminal: bool score: float ledger: list[EffectRecord] = field(default_factory=list) class ReconciliationLedger: def __init__(self) -> None: self._records: dict[str, EffectRecord] = {} def record(self, rec: EffectRecord) -> None: # Append-only; written BEFORE the effect is emitted. self._records[rec.effect_id] = rec def effects_for(self, branch_id: str) -> list[EffectRecord]: return [r for r in self._records.values() if r.branch_id == branch_id] def reconcile( ledger: ReconciliationLedger, winner: Branch, losers: list[Branch], ) -> list[str]: """Commit winner, roll back losers only where compensation is reachable. Returns list of quarantined branch ids. Raises if winner aliases a held effect.""" quarantined: list[str] = [] held_effect_ids: set[str] = set() for loser in losers: effects = ledger.effects_for(loser.branch_id) # A non-terminal branch may be mid-effect: presume live, uncompensated. if not loser.terminal: quarantined.append(loser.branch_id) held_effect_ids.update(e.effect_id for e in effects) continue uncompensable = [e for e in effects if e.compensation_handle is None] if uncompensable: quarantined.append(loser.branch_id) held_effect_ids.update(e.effect_id for e in uncompensable) continue # Safe: every effect has a reachable inverse. Execute compensation. for e in effects: _compensate(e) # Gate the winner's commit on held effects it might alias. for e in ledger.effects_for(winner.branch_id): if e.effect_id in held_effect_ids: raise UnreconcilableRollbackError( f"winner {winner.branch_id} aliases held effect {e.effect_id} " f"from a quarantined branch; commit blocked pending resolution" ) _commit(winner) return quarantined def _compensate(effect: EffectRecord) -> None: if effect.compensation_handle is None: raise UnreconcilableRollbackError( f"effect {effect.effect_id} has no compensation handle" ) # invoke inverse tool by handle; idempotent via idempotency_key def _commit(branch: Branch) -> None: # apply winning branch's effects atomically ... ```