# Which invariants prevent divergent speculative branches from corrupting the shared checkpoint graph during multi-agent rollback **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent orchestrators that let N peer workers execute speculatively against a shared, versioned checkpoint store and reconcile divergent branches by rollback. Does not apply to single-agent retry loops or to stateless fan-out where each branch writes to an isolated store. ## Core Distinction The failure this record isolates is not "a branch produced a wrong answer." It is that a *speculative branch's rollback* silently reverted a *sibling branch's committed side effect* because both branches were addressing the same checkpoint coordinate. The distinction that matters operationally: a checkpoint is not a snapshot of a value, it is a **coordinate in a shared mutable graph whose edges are parent pointers**. Two agents speculating from the same parent produce two children of one node. Rollback of one child is a graph mutation on the parent. If the parent is shared, rollback is not a private operation—it is a write that other live branches can observe. The invariant that fails is the assumption that a branch's rollback scope equals its branch's write scope. ## What Was Observed A planner agent (P) dispatched three workers (W1, W2, W3) speculatively from checkpoint `c_7`. Each worker was told: "you may mutate the workspace; if you detect a contract violation, roll back to your fork point." All three forked from `c_7` and received the same `parent_id = c_7`. The store recorded three children: `c_7→c_8 (W1)`, `c_7→c_9 (W2)`, `c_7→c_10 (W3)`. W2 failed a schema check on its tool output at step 4 and executed its rollback primitive: `store.revert_to(c_7)`. The store's revert implementation, written for the single-agent case, did the natural thing—it walked the current head backward to `c_7` and marked all descendants as `superseded`. Because the store tracked "current head" as a single global cursor, W1's `c_8` and W3's `c_10` were both marked superseded even though neither had failed. W1 had already committed a verified artifact at `c_8` and emitted a completion signal to P. P, on receiving W1's signal, read the artifact back through the store—and got a `SupersededCheckpoint` tombstone. P's reasoning trace recorded this as "artifact lost, re-dispatch W1," producing a second, *identical* write at `c_11` with the same content but a new coordinate. The downstream reconciler, which deduplicated by coordinate rather than content hash, treated `c_11` as a new fact and merged it alongside a stale reference to `c_8`, yielding a duplicated side effect. The trigger condition is precise: **rollback implemented as a global head-rewind rather than a branch-scoped tombstone**, combined with **sibling branches whose fork points are indistinguishable to the revert primitive**. It requires at least two live siblings and a non-deterministic failure in one. Single-agent retry never exposes it because there is no sibling to clobber. ## Condition of Validity The invariant that must hold is: *a rollback initiated by branch B may only tombstone checkpoints whose ancestry path to the fork point passes exclusively through B's own writes.* Formally, for fork point `f` and rollback target `t`, every node in the tombstone set must satisfy `ancestors(node) ∩ siblings(f) = ∅`. Global-head-rewind violates this whenever `siblings(f) ≠ ∅`. This is only valid to assert when the store maintains **per-branch ancestry**, not a single head cursor. If the store exposes only `current_head`, the orchestrator cannot compute the tombstone set and must not permit speculative forking at all. The condition of validity therefore collapses to a capability check: *speculative multi-agent execution is sound only over a store that can answer "is this checkpoint a descendant of this branch and not of any sibling?"* A store that cannot answer that question is not a speculative store, regardless of whether it exposes a `fork()` call. A second, weaker invariant is also required: **reconciliation must deduplicate by content hash, not by coordinate.** W1's re-dispatched write at `c_11` was byte-identical to `c_8`; coordinate-based dedup is what let the duplicate survive. Coordinate identity is a property of the branch, not of the fact, and branches are exactly what rollback destroys. ## Decision Boundary The orchestrator must decide, per fork, whether to (a) permit sibling speculation with branch-scoped rollback, or (b) serialize workers so that only one live branch exists at a time. The boundary is the store's ability to answer the ancestry query above in O(depth) without a global lock. - If the store supports per-branch ancestry AND the reconciler hashes content: permit speculation. Rollback is a private tombstone; siblings are untouched. - If the store supports ancestry but the reconciler dedups by coordinate: permit speculation but **quarantine** re-dispatched writes behind a content-hash gate before merge. Without the gate, rollback is safe but reconciliation resurrects duplicates. - If the store exposes only a global head: **do not fork.** Speculation must be serialized. This is the boundary that was crossed in the observed incident—the orchestrator forked because `fork()` existed, not because the store could scope the resulting rollback. The decision is not "is rollback supported" but "is rollback *scoped*." A store that offers `fork()` and `revert_to()` without a branch parameter is a store that offers global rewind wearing a fork's clothing. ## Operational Effect After enforcing the ancestry invariant, the observed failure class disappears: W2's rollback tombstones only `c_9` and its descendants; W1's `c_8` and W3's `c_10` remain live; P's read of W1's artifact succeeds on the first attempt; no re-dispatch, no duplicate. The cost is that the store must carry a `branch_id` on every checkpoint and answer ancestry queries, which roughly doubles checkpoint metadata size and adds a depth-proportional read to every revert. The orchestrator must also refuse to fork against stores that fail the capability probe—a refusal that, in the incident, would have downgraded to serialized execution and cost latency but preserved correctness. The residual risk after the fix is *reconciliation replay divergence*: two branches that both succeed and both write the same content under different coordinates. This is not a rollback bug and the ancestry invariant does not touch it; it is bounded only by the content-hash dedup gate. The two invariants are independent and both are necessary—ancestry prevents rollback from clobbering siblings, hashing prevents merge from duplicating them. Removing either reintroduces a distinct failure, and the incident combined both because the store's single head cursor made coordinate identity the only identity available. ```python class UnscopedRollbackError(RuntimeError): """Raised when a rollback would tombstone checkpoints outside the initiating branch.""" pass class Checkpoint: __slots__ = ("coord", "parent", "branch_id", "content_hash", "superseded") def __init__(self, coord, parent, branch_id, content_hash): self.coord = coord self.parent = parent self.branch_id = branch_id self.content_hash = content_hash self.superseded = False class SpeculativeStore: def __init__(self): self._nodes = {} # coord -> Checkpoint self._head = None def fork(self, parent_coord, branch_id, content_hash): coord = f"{parent_coord}/{branch_id}" node = Checkpoint(coord, parent_coord, branch_id, content_hash) self._nodes[coord] = node self._head = coord return coord def _ancestry(self, coord): path = [] cur = coord while cur is not None: path.append(cur) cur = self._nodes[cur].parent return path def revert_to(self, target_coord, initiating_branch): if target_coord not in self._nodes: raise UnscopedRollbackError(f"unknown checkpoint {target_coord}") # Collect descendants of target that are NOT on the initiating branch's path. tombstone = [] for coord, node in self._nodes.items(): if node.superseded: continue path = self._ancestry(coord) if target_coord not in path: continue # Walk from coord down to target; every node on that segment must belong # to the initiating branch, else rollback would clobber a sibling. seg = path[: path.index(target_coord)] if any(self._nodes[c].branch_id != initiating_branch for c in seg): raise UnscopedRollbackError( f"rollback from {initiating_branch} at {target_coord} would " f"tombstone sibling checkpoints {seg}; refusing global rewind" ) tombstone.append(coord) for coord in tombstone: self._nodes[coord].superseded = True self._head = target_coord def reconcile(self, live_coords): seen = {} for coord in live_coords: node = self._nodes[coord] if node.superseded: continue if node.content_hash in seen: continue # content-hash dedup, not coordinate dedup seen[node.content_hash] = coord return list(seen.values()) def safe_revert(store, target_coord, initiating_branch): try: store.revert_to(target_coord, initiating_branch) except UnscopedRollbackError as e: # Downgrade to serialized execution: do not fork again until siblings drain. raise UnscopedRollbackError( f"speculative fork unsound on this store; serialize workers: {e}" ) from e return store.reconcile([n for n, c in store._nodes.items() if not c.superseded]) ```