# When must an instance abandon a speculative branch: reconciling divergent side-effect logs after rollback in multi-agent execution **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fan out speculative agent branches sharing a mutable external environment (filesystem, DB, third-party APIs) and reconcile via rollback. Does not apply to pure-function tool sandboxes with no external side effects, nor to single-agent retry loops. ## Core Distinction The critical distinction is between *logical rollback* and *physical rollback*. A speculative multi-agent system can always roll back its own internal state—message logs, scratchpads, branch pointers—because that state lives inside the orchestrator. It cannot, in general, roll back side effects already committed to external systems by a branch that was later discarded. The failure mode is not "the branch produced a wrong answer"; it is "the branch produced a *correct* answer but committed a side effect, then lost the reconciliation race, and the surviving branch's verification now observes a world contaminated by the dead branch." This is a boundary condition because it only manifests when three things co-occur: (1) speculative branches execute against shared external state, (2) at least one branch is discarded after committing, and (3) the surviving branch's auditor re-reads external state rather than replaying from a captured snapshot. Absent any one of these, rollback is sound. ## What Was Observed An orchestrator spawned three branches to complete a schema-migration task. Branch A proposed `ALTER TABLE users ADD COLUMN tier TEXT`. Branch B proposed the same but with a `DEFAULT 'free'` clause. Branch C proposed a two-step backfill. All three ran concurrently in a shared staging DB with per-branch advisory locks keyed by branch ID—which, critically, meant the locks did *not* serialize against each other. Branch B committed first. Branch A's `ALTER` then failed on the duplicate-column error, and the orchestrator—correctly—discarded A. Branch C's backfill ran against the column B had created, which lacked A's intended default, and populated `tier` with NULLs for existing rows. The reconciler selected C as the winner on a rubric that scored "backfill coverage." The final state was B's DDL plus C's backfill: a column with a default that no existing row satisfied, because the default was declared *after* the rows existed and the backfill wrote explicit NULLs. The auditor's replay of C's branch passed because C's transcript never referenced A's DDL—it saw a column already present and backfilled it. The contamination was invisible in every branch transcript. It was only visible in the *ordering* of committed side effects, which no branch owned. The observed invariant violation: **a branch's verification transcript is not a proof of the branch's effect on shared state; it is a proof of the branch's *view* of shared state.** When two branches' views diverge from a shared mutation, the surviving transcript can be internally consistent and externally wrong. ## Condition of Validity Rollback-and-reconcile is valid only under the following conjunction: 1. **Effect isolation:** every external mutation carries a branch-scoped tag, and the reconciler can enumerate and reverse mutations by tag before any auditor reads state. 2. **Snapshot anchoring:** each branch's verification replays against a snapshot captured at branch-fork time, not against live state. 3. **Commit linearization:** a branch's side effects become visible to other branches only after that branch is selected as winner, enforced by a global commit lock—not per-branch locks. If any of the three is absent, the system is in the *speculative contamination* regime: discarded branches can leave residue that surviving branches misattribute to their own execution. The condition is violated the moment a per-branch lock is mistaken for a serialization barrier. Per-branch locks serialize a branch against itself; they do not serialize branches against each other, and they do not prevent a discarded branch's effect from being observed by a live one. ## Decision Boundary The decision is not "should we roll back?" but "**is this branch's side-effect set reversible, and if not, must we promote it to a commit rather than discard it?**" Concretely, when a branch is about to be discarded, the orchestrator must classify each of its committed effects: - **Reversible** (row insert with a branch tag, file write to a branch-scoped path): reverse before the next auditor read. - **Irreversible** (external API call with no idempotency key, email send, `ALTER` already applied): the branch cannot be discarded cleanly. It must either be *promoted* (kept as a co-winner whose effects are acknowledged in the surviving branch's transcript) or the whole speculative set must be *aborted* and re-run against a fresh snapshot. The boundary is crossed when an irreversible effect exists on a discarded branch and the orchestrator discards it anyway. At that point the reconciliation is unsound regardless of how well the surviving branch scores, because the scoring rubric cannot see the contamination. An instance must abandon the speculative branch set—not merely the branch—the moment it detects an irreversible effect on a non-winner without a recorded reversal. ## Operational Effect The practical consequence is that speculative fan-out with shared external state requires a *commit barrier* the orchestrator must respect: no auditor may read live state until all non-winner branches have either reversed their effects or been promoted. This serializes the tail of reconciliation and costs latency, but it is the only way to keep verification transcripts honest. Second, the reconciler must maintain an **effect ledger** keyed by branch, distinct from the message log. The message log records what a branch *said*; the effect ledger records what it *did* to the world. The two can disagree, and when they do, the ledger wins. Auditors must be scored against the ledger, not the transcript—otherwise a branch that verifies its own view of contaminated state passes. Third, when an irreversible effect is detected on a non-winner, the orchestrator must raise and halt the speculative set rather than silently promoting the branch. Silent promotion hides the contamination in the winner's transcript and re-introduces the exact failure the ledger was meant to catch. ```python class SpeculativeContaminationError(RuntimeError): """Raised when a discarded branch left an irreversible side effect that a surviving branch's auditor can observe, invalidating reconciliation.""" def reconcile_branches(branches, effect_ledger, live_state_snapshot): # effect_ledger: {branch_id: [{"kind": "reversible"|"irreversible", "reversed": bool}]} winners = select_winners(branches) discarded = [b for b in branches if b.id not in {w.id for w in winners}] for b in discarded: effects = effect_ledger.get(b.id, []) for eff in effects: if eff["kind"] == "irreversible" and not eff.get("reversed", False): # Cannot cleanly discard: the world is already changed. raise SpeculativeContaminationError( f"branch {b.id} committed irreversible effect " f"{eff.get('desc', '')} and was discarded; " f"surviving branches will observe contaminated state. " f"Abort speculative set or promote {b.id}." ) # Only after all discarded branches are proven clean may auditors read live state. for w in winners: auditor_replay(w, live_state_snapshot) return [w.id for w in winners] ```