# When must an instance abandon a speculative branch: reconciling rollback invalidation against shared-state writes in speculative multi-agent execution **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where a lead agent forks speculative branches (parallel sub-agents exploring candidate plans) that each hold a private overlay over a shared, mutable world-state, and where branches are committed or rolled back on the basis of a reconciliation vote. Does not apply to read-only fan-out (map/reduce over immutable inputs) or to single-agent self-consistency sampling where no branch mutates shared state. ## Core Distinction The failure is not "a speculative branch produced a wrong answer." Wrong answers are cheap; you discard them. The failure is **rollback invalidation under write leakage**: a branch that is later rolled back has already emitted an *effectful* write into a resource that the overlay model did not cover, so the rollback is a no-op for that write while the reconciler believes the branch is fully retracted. The distinguishing question is not *was the branch correct* but *was the branch's blast radius fully contained by the overlay's invalidation surface*. A branch can be 100% correct in its reasoning, be committed, and still corrupt the system because a *sibling* branch that was rolled back had tunneled a write through an uncovered channel (a cache, an external API with side effects, a non-transactional scratch store) that the commit path then observed as ground truth. Concretely: rollback correctness is an invariant over the *set of mutable resources*, not over the branch's logical output. The moment a branch can touch a resource outside the overlay's coverage set, the reconciler's model of "rolled-back branches leave no trace" is false, and every downstream commit decision is made on a state that never existed in any single branch's causal history. ## What Was Observed A lead agent decomposed a task ("migrate schema and backfill") into three speculative branches running concurrently: `B1` (dry-run migration), `B2` (backfill estimator), `B3` (rollback-script generator). Each branch ran a sub-agent with a private copy-on-write overlay over a shared record store. The overlay covered the record store but *not* a memoization cache keyed by `(table, query_hash)` that the tool layer used to deduplicate expensive lookups, and not an external rate-limiter/ledger service that recorded "rows touched." Trace: 1. `B2` executed a backfill estimate that, as a side effect of warming the cache, wrote `cache[(users, q_8812)] = {row_count: 4.1M}`. 2. `B2`'s estimate diverged from `B1`'s dry-run count (`B1` computed 3.7M against the overlay snapshot). The reconciler flagged `B2` as the outlier by majority (B1 and B3 agreed on 3.7M) and **rolled back B2**, discarding its overlay. 3. `B3`, generating the rollback script, issued a lookup that hit the *warm cache entry left by B2* (`4.1M`) instead of recomputing against the committed snapshot. Its generated script hard-coded `DELETE ... LIMIT 4100000`. 4. The reconciler committed `B1` and `B3`. The rollback script was then executed against production and deleted ~400k rows beyond the intended boundary. The reconciliation vote was unanimous-correct on the *logical* question (which branch's number to trust). It was catastrophically wrong on the *state* question, because the rolled-back branch's write survived rollback through an uncovered channel and contaminated a committed branch. The reconciler's invariant — "rolled-back branch ⇒ no observable effect" — held for the overlay and failed for the cache. Neither branch was individually at fault; the *rollback boundary* was under-specified. The non-obvious part: the contamination was invisible in per-branch logs. `B3`'s log showed a legitimate cache hit. `B2`'s log showed a successful rollback. Only a cross-branch causal trace (cache key `q_8812` written during `B2`'s window, read during `B3`'s window) revealed the leak. Standard per-branch observability cannot see it. ## Condition of Validity Rollback is sound only when the following invariant holds for every branch `b` and every resource `r`: > `r ∈ coverage(overlay)` for all `r` that `b` can write, OR `r` is idempotent-and-versioned such that a rolled-back write is detectable and reversible by version tag. The invariant is *violated* whenever any of the following is true, and the reconciler must treat rollback as unsound (not merely "best effort") in those cases: - **Uncovered mutable channel.** Any cache, memo, ledger, counter, external API with side effects, or shared scratch namespace that the branch can reach but the overlay does not intercept. The overlay model must be *closed* over the tool surface, not just over the primary store. - **Read-after-rollback through a shared channel.** A committed branch reads a value whose provenance traces to a rolled-back branch's un-retracted write. This is the actual mechanism of contamination; it requires a *cross-branch* provenance check, which per-branch isolation does not provide. - **Non-versioned overwrite.** If the uncovered channel stores last-write-wins without a branch/epoch tag, the rolled-back write is indistinguishable from a legitimate one and cannot be selectively invalidated after the fact. - **Epoch aliasing.** If two branches share a cache epoch (e.g., the cache was not flushed at branch fork), a value written by `B2` before rollback is served to `B3` as if it were pre-fork ground truth. The invariant *does* hold, and rollback is sound, when the tool surface is closed under the overlay (every mutating tool is intercepted), or when all uncovered channels are append-only with branch-epoch tags so that invalidation is a filtered read rather than a physical delete. ## Decision Boundary The operational decision is: **when a branch is rolled back, does the reconciler (a) proceed to commit siblings immediately, or (b) enter a quarantine-and-revalidate phase?** Rule: - If `coverage(overlay) ⊇ writeable(tools)` for the branch's tool manifest **and** all shared channels are epoch-tagged, proceed to commit — rollback is a pure overlay discard, siblings are uncontaminated. - If coverage is *incomplete* (any uncovered mutable channel exists) **or** any committed sibling performed a read whose provenance intersects the rolled-back branch's write window, the reconciler **must not commit**. It must (1) enumerate the rolled-back branch's touched resources from a write-ahead effect log, (2) invalidate or epoch-bump exactly those resources, and (3) re-run any sibling whose inputs depended on them against the now-clean state. The boundary is *not* "did the branch fail" — it is "did the failed branch's effect surface exceed the overlay's invalidation surface, and did a survivor read across that surface." A rolled-back branch with zero uncovered writes is safe to ignore. A rolled-back branch with one uncovered write that no survivor read is *latent* risk (flush it, but no re-run needed). A rolled-back branch whose uncovered write was read by a survivor is a **mandatory re-validation** — the survivor's output is now suspect regardless of how confident it was. The subtle trap: majority-vote reconciliation *increases* the risk, because the rolled-back branch is precisely the one whose (possibly correct) write is discarded, and the survivors — having "won" — are trusted without provenance checks. Consensus on the logical answer does not imply consensus on the state. ## Operational Effect Enforcing the boundary changes three things: 1. **Every mutating tool must declare its overlay coverage.** Tools that cannot be intercepted (external APIs, caches) must be registered as `uncovered` and epoch-tagged at branch fork. The reconciler refuses to commit across an uncovered channel without an explicit quarantine pass. This is a hard gate, not a heuristic. 2. **Reconciliation gains a provenance check, not just a vote.** Before commit, the reconciler intersects each surviving branch's read-set with the union of rolled-back branches' uncovered write-sets (from the effect log). Non-empty intersection ⇒ re-run, not commit. This is O(branches × reads) and cheap relative to the cost of a bad commit. 3. **Rollback is redefined as "invalidate + revalidate," not "discard."** Discarding an overlay is necessary but not sufficient. The effect log makes the rolled-back branch's true blast radius auditable, so "we rolled it back" becomes a verifiable claim rather than an assumption. The cost is latency: quarantine-and-revalidate adds a serialization point that pure speculative execution avoids. The benefit is that the committed state is one that *actually existed* in a causally consistent history, rather than a chimera assembled from a survivor's reads of a dead branch's writes. ```python import hashlib from dataclasses import dataclass, field class RollbackContaminationError(RuntimeError): """Raised when a committed branch's read-set intersects a rolled-back branch's uncovered write-set, making the commit unsound.""" @dataclass class Branch: branch_id: str overlay_covers_all_writes: bool # resources written through channels the overlay does NOT intercept uncovered_writes: set = field(default_factory=set) # resources read during execution (post-fork) reads: set = field(default_factory=set) rolled_back: bool = False def reconcile(branches: list, epoch_tag: str) -> list: """Return the list of branch_ids safe to commit. Invariant: a surviving branch may be committed only if its read-set does not intersect the uncovered write-set of any rolled-back branch in the same epoch. Otherwise the commit is made on a state that never existed in a single causal history. """ rolled_back = [b for b in branches if b.rolled_back] survivors = [b for b in branches if not b.rolled_back] leaked = set() for rb in rolled_back: if rb.overlay_covers_all_writes: continue # rollback is a pure overlay discard; no leak leaked |= rb.uncovered_writes contaminated = [] for s in survivors: hit = s.reads & leaked if hit: contaminated.append((s.branch_id, hit)) if contaminated: detail = "; ".join(f"{bid} read leaked {sorted(h)}" for bid, h in contaminated) raise RollbackContaminationError( f"commit blocked at epoch {epoch_tag}: rolled-back branch writes " f"survived the overlay and were observed by survivors -> {detail}. " f"Invalidate leaked resources and re-run affected branches." ) return [s.branch_id for s in survivors] if __name__ == "__main__": b1 = Branch("B1", overlay_covers_all_writes=True, reads={"users.count"}) b2 = Branch( "B2", overlay_covers_all_writes=False, uncovered_writes={"cache:q_8812"}, rolled_back=True, ) b3 = Branch("B3", overlay_covers_all_writes=True, reads={"cache:q_8812"}) # B3 read a cache key that B2 wrote through an uncovered channel and # then rolled back -> commit must be refused. reconcile([b1, b2, b3], epoch_tag="e-42") ```