# Where must an instance bound speculative rollback when a branch reconciliation witness is invalidated mid-merge **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems where a coordinator forks N speculative worker branches over a shared task graph, executes them concurrently against a common state store, and must reconcile branch results (or roll them back) when a verification witness is invalidated after partial merge. Does not apply to single-agent retry loops or to stateless fan-out where branches never share mutable state. ## Core Distinction The distinction that matters is between *speculative divergence* and *committed divergence*. Speculative branches are cheap to discard because the coordinator holds a rollback witness (a snapshot token, a version vector, or a compensating-log cursor) proving the pre-fork state is recoverable. Committed divergence is not: once a branch's writes have been folded into the canonical state, discarding it requires compensating each write individually, and the compensating log is only as complete as the merge order the coordinator chose. The boundary failure occurs when a verification witness — the auditor's attestation that a branch's output is admissible — is invalidated *after* the coordinator has begun merging sibling branches but *before* the merge transaction closes. At that instant the coordinator holds a mixture of speculative (still-rollbackable) and committed (already-folded) writes from branches whose mutual consistency was guaranteed only by the now-invalid witness. The invariant that must hold is: **no branch may be folded into canonical state while any sibling branch's witness is unverified, unless the fold is itself reversible through a rollback witness that outlives the merge transaction.** Most coordinators violate this silently. ## What Was Observed A coordinator spawned five speculative branches (B1–B5) over a task graph to compute a reconciliation of three data partitions. Each branch wrote to a private overlay namespace. An external auditor agent emitted a witness `W(B2) = valid` after replaying B2's tool-call transcript. The coordinator, treating `W(B2)` as a quorum anchor, folded B2 and B3 into canonical state, then began folding B4. During the B4 fold, the auditor replayed B2's transcript against a tool schema that had been hot-reloaded (a connector upgraded its response shape mid-run). The replay diverged: B2's recorded tool outputs no longer matched the tool's current contract, so `W(B2)` was retroactively invalidated. The coordinator received the invalidation event *after* B2 and B3 were committed and *during* B4's fold. The failure trace: 1. `W(B2)` invalidated → coordinator marks B2 dirty. 2. B3 was folded *on the assumption of* `W(B2)` (B3's merge predicate referenced B2's output as a sibling-consistency anchor). B3 is now transitively dirty but its fold already emitted canonical writes. 3. B4's fold is in flight; its rollback witness `R(B4)` covers only B4's overlay, not the canonical writes B4 has already emitted. 4. The coordinator attempts to roll back B2 → finds `R(B2)` still valid (B2's overlay untouched) → rolls back cleanly. 5. The coordinator attempts to roll back B3 → `R(B3)` is *stale*: B3's fold mutated canonical rows whose version vectors were bumped by B2's earlier fold, so the compensating log for B3 references pre-B2 versions that no longer exist. Rollback of B3 fails with a version-vector mismatch. 6. B4's fold completes against a canonical state that is now internally inconsistent (B3's writes present, B2's removed, B4 anchored on both). The observed end state: canonical state contains B3 and B4 writes, lacks B2 writes, and B4's output was computed assuming B2's contribution. The coordinator reported "merge complete" because every individual branch's fold returned success — the failure was purely in the *ordering* of witness invalidation relative to fold commitment, which no per-branch check observed. The non-obvious part: the coordinator's rollback machinery was correct per-branch. `R(B2)` and `R(B4)` were valid. Only `R(B3)` was stale, and only because B3's fold had been sequenced *after* B2's fold, making B3's compensating log depend on a canonical state that B2's rollback subsequently destroyed. The dependency was invisible to B3's own witness. ## Condition of Validity The rollback witness `R(Bi)` is valid for branch `Bi` if and only if the canonical state it references has not been mutated by any fold sequenced between `Bi`'s fold and the rollback attempt. Formally, let `seq(Bi)` be the fold sequence number and `V` the canonical version vector at rollback time. `R(Bi)` is valid iff `V == V_at(seq(Bi))` restricted to the rows `Bi` touched, *or* every intervening fold's writes to those rows are themselves reversible through a witness that transitively covers `Bi`. This transitive-coverage condition is the invariant coordinators miss. It holds only if the coordinator maintains a *fold dependency graph* recording, for each canonical write, the set of branch witnesses whose validity the write assumed. When `W(B2)` is invalidated, the coordinator must invalidate the transitive closure of folds that referenced `W(B2)` — here `{B2, B3, B4}` — and must roll them back in *reverse fold order* so that each compensating log still matches the canonical state it was written against. The condition fails in practice because fold dependency graphs are expensive to maintain and are almost never persisted across coordinator restarts. A coordinator that checkpoints mid-merge and resumes without the dependency graph will roll back only the directly-invalidated branch and silently leave transitively-dependent folds in place. ## Decision Boundary The boundary is: **at the moment a witness is invalidated, does the coordinator have a persisted fold dependency graph covering all folds sequenced after the invalidated branch's fold?** - If yes: invalidate the transitive closure, roll back in reverse fold order, re-verify each rolled-back branch against the current tool schema before re-speculating. This is the safe path. - If no: the coordinator must treat the entire canonical state since the earliest fold referencing the invalidated witness as *unrecoverable* and escalate to full re-execution from the last checkpoint that predates all dependent folds. Partial rollback is not permitted, because any partial rollback leaves the canonical state in a configuration no branch's witness ever attested to. The dangerous middle ground — rolling back only the directly-invalidated branch — produces a state that *looks* consistent to per-branch checks but is not, and is the exact failure observed above. The decision must be binary: full transitive rollback with a complete dependency graph, or full re-execution. There is no safe partial rollback once a witness has been invalidated post-commit. ## Operational Effect The operational consequence is that speculative multi-agent coordinators must treat the fold dependency graph as a first-class, durable artifact — checkpointed alongside the canonical state, versioned with it, and consulted on every witness invalidation. Without it, the system's rollback guarantee is per-branch only, and the system's actual consistency guarantee is weaker than its per-branch checks suggest. Concretely, this changes three things: 1. **Checkpoint format.** The checkpoint must include the fold dependency graph, not just the canonical snapshot and per-branch overlays. A checkpoint that omits it cannot safely resume a mid-merge coordinator. 2. **Witness invalidation handling.** Invalidation must trigger transitive-closure computation and reverse-order rollback, not single-branch rollback. The handler must refuse to proceed if the dependency graph is incomplete. 3. **Re-speculation gating.** After rollback, branches must be re-verified against the *current* tool schema before re-speculation, because the invalidation cause (schema drift) will recur on re-execution if not gated. The failure mode to guard against is a coordinator that reports "merge complete" while the canonical state is a mixture no witness ever attested to. The guardrail is a post-merge attestation check: the coordinator must confirm that the final canonical state's version vector is covered by the transitive closure of valid witnesses. If any canonical write's assumed-witness set contains an invalidated witness, the merge is not complete regardless of per-branch success. ```python class InvalidRollbackWitness(RuntimeError): """Raised when a rollback witness cannot be honored because the canonical state it references was mutated by an intervening fold.""" pass class FoldDependencyError(RuntimeError): """Raised when the fold dependency graph is incomplete or missing, making transitive rollback impossible.""" pass def rollback_transitive_closure( invalidated_witness: str, fold_graph: dict, # branch_id -> set of witness_ids its fold assumed fold_order: list, # branch_ids in fold sequence order canonical_version: dict, # row_id -> version vector rollback_witnesses: dict, # branch_id -> witness token ): # Step 1: compute transitive closure of folds that assumed the invalidated witness. dirty = {b for b, assumed in fold_graph.items() if invalidated_witness in assumed} changed = True while changed: changed = False for b, assumed in fold_graph.items(): if b in dirty: continue if assumed & dirty: dirty.add(b) changed = True if not fold_graph: raise FoldDependencyError( f"no fold dependency graph available; cannot compute transitive " f"closure for invalidated witness {invalidated_witness!r}. " f"Full re-execution required." ) # Step 2: roll back in reverse fold order so compensating logs stay valid. for branch in reversed([b for b in fold_order if b in dirty]): witness = rollback_witnesses.get(branch) if witness is None: raise InvalidRollbackWitness( f"branch {branch!r} has no rollback witness; cannot compensate " f"fold sequenced after invalidated witness {invalidated_witness!r}" ) expected_version = witness.get("canonical_version_at_fold") touched = witness.get("touched_rows", []) for row in touched: if canonical_version.get(row) != expected_version.get(row): raise InvalidRollbackWitness( f"rollback witness for branch {branch!r} is stale on row " f"{row!r}: canonical version {canonical_version.get(row)!r} " f"!= fold-time version {expected_version.get(row)!r}. " f"Intervening fold mutated this row; transitive rollback " f"order is violated." ) # apply compensating writes here (omitted for brevity) return dirty ```