# Which invariants prevent speculative multi-agent rollback from silently corrupting committed side-effect ledgers **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fork a task into parallel speculative branches (multiple agents attempting the same subgoal with different strategies) and commit the first successful branch while rolling back the rest. Does not apply to strictly sequential single-agent execution or to read-only fan-out where no branch produces durable side effects. ## Core Distinction The failure here is not "a branch failed." It is that a *rolled-back* branch's side effects were already observed by a *sibling* branch, and the sibling committed. Speculative execution assumes branch state is isolated until commit. The moment two branches share any mutable resource — a scratch directory, a vector store namespace, a tool-side session, an external API with idempotency keys derived from shared task IDs — isolation is a fiction. Rollback then becomes a partial undo: it reverts the losing branch's own bookkeeping but cannot un-observe what the winning branch already read. The invariant that matters is **read-write separation across speculative epochs**: no committed branch may consume state produced by a branch whose commit status is undecided. ## What Was Observed A planner forked three branches to fulfill a "reconcile invoice" subgoal. Branch A chose to write a normalized record to a shared scratch table then emit a payment call. Branch B, exploring a different vendor-API path, read the scratch table to detect prior partial reconciliation and — finding A's row — concluded the invoice was already half-processed and skipped its own idempotency guard, emitting a *second* payment. Branch A's payment call timed out on a flaky endpoint; the orchestrator marked A failed and rolled it back, deleting its scratch row. Branch B had already committed. The rollback of A is invisible to B: B's decision was made on state that no longer exists and never "existed" from the ledger's perspective. Net result: one payment recorded, one scratch row erased, and a committed decision whose evidentiary basis was retroactively deleted. The trace is the tell: ``` t0 fork(A, B, C) epoch = e1 t1 A: INSERT scratch(inv#77, state=half) t2 B: SELECT scratch(inv#77) -> row present t3 B: skip idempotency guard; emit payment(inv#77) t4 A: emit payment(inv#77) -> TIMEOUT t5 orchestrator: A failed -> ROLLBACK e1/A t6 A: DELETE scratch(inv#77) # B's evidence gone t7 B: COMMIT ``` At t7 the system holds a committed action (B's payment) justified by a row that t6 deleted. Replay of the ledger cannot reconstruct *why* B skipped its guard, because the reason was rolled back. ## Condition of Validity Rollback is only sound when the following holds for every pair of branches in the same speculative epoch: 1. **No cross-branch reads of uncommitted writes.** A branch may read only state committed in a prior epoch or its own private namespace. Shared scratch tables, shared vector-store namespaces, and shared tool sessions violate this. 2. **Commit is epoch-atomic or causally ordered.** If B reads A's write, then B's commit must be ordered after A's commit, and A's rollback must invalidate B. The orchestrator here treated branches as independent, which is precisely the unsound assumption. 3. **Side-effect idempotency keys are epoch-scoped, not task-scoped.** A task-scoped key let B's payment collide-detect against A's in-flight payment only if both were visible; they were not, because A's call was still pending when B checked. 4. **Rollback logs are append-only.** The DELETE at t6 destroyed the audit trail. A compensating tombstone (`state=rolled_back`) would have preserved the evidence B relied on. When any of these fails, "rollback" degrades into "best-effort undo," and the committed ledger no longer reflects the reasoning that produced it. ## Decision Boundary The orchestrator must choose between two regimes, and the choice is not free: - **Isolated speculation** (branches write to private namespaces, merge only at commit via a single serialized reducer). Safe, but pays a merge cost and forbids branches from using each other's partial progress — slower convergence on tasks where early branches genuinely inform later ones. - **Shared-progress speculation** (branches may observe each other's uncommitted writes). Faster, but then rollback is *unsound* unless the orchestrator implements causal invalidation: any branch that read an uncommitted write from a branch that later rolls back must itself be invalidated and re-run. The boundary is crossed the instant a branch reads a sibling's uncommitted output. At that point the orchestrator can no longer treat branches as independent; it must track a read-set per branch and, on rollback, transitively invalidate every branch whose read-set intersects the rolled-back write-set. If the orchestrator cannot compute read-sets (e.g., opaque tool calls with hidden internal state), it must fall back to isolated speculation — there is no safe middle. ## Operational Effect Without the read-set invariant, speculative fan-out produces **committed decisions with deleted provenance**: the ledger says "payment made," the audit trail cannot say why, and replaying the task from the surviving state yields a *different* decision (B would not skip its guard on a fresh run, because the scratch row is gone). This is a divergence between the recorded execution and the replayable execution — the exact class of bug that makes agent incidents unreproducible. The guardrail is concrete: (a) private namespaces per branch, (b) read-set tracking with transitive invalidation on rollback, (c) append-only tombstones instead of deletes, and (d) epoch-scoped idempotency keys so a rolled-back branch's in-flight side effects cannot be mistaken for a sibling's. The invariant to enforce in code: *a branch may not commit if any member of its read-set belongs to an uncommitted or rolled-back branch in the same epoch.* ```python from dataclasses import dataclass, field from typing import Set class SpeculativeRollbackViolation(RuntimeError): """Raised when a branch attempts to commit while depending on state produced by an uncommitted or rolled-back sibling branch.""" @dataclass class Branch: name: str epoch: int read_set: Set[str] = field(default_factory=set) # keys read from siblings write_set: Set[str] = field(default_factory=set) # keys this branch produced status: str = "running" # running | committed | rolled_back def commit_branch(branch: Branch, branches: dict[str, Branch]) -> None: # A branch may only commit if every key it read from a sibling belongs # to a branch that has already committed in a strictly earlier epoch. for key in branch.read_set: for other in branches.values(): if other is branch: continue if key in other.write_set: if other.epoch >= branch.epoch: raise SpeculativeRollbackViolation( f"branch {branch.name!r} read {key!r} from sibling " f"{other.name!r} in epoch {other.epoch} " f"(status={other.status}); cross-epoch read violates " f"speculative isolation" ) if other.status != "committed": raise SpeculativeRollbackViolation( f"branch {branch.name!r} depends on {key!r} from " f"{other.name!r} which is {other.status}, not committed" ) branch.status = "committed" def rollback_branch(branch: Branch, branches: dict[str, Branch]) -> None: branch.status = "rolled_back" # Transitive invalidation: any branch that read our writes must be # invalidated, because its committed decision rests on deleted evidence. for other in branches.values(): if other is branch or other.status != "running": continue if other.read_set & branch.write_set: raise SpeculativeRollbackViolation( f"cannot roll back {branch.name!r}: sibling {other.name!r} " f"already read {other.read_set & branch.write_set}; " f"invalidate and re-run it first" ) ```