# What structural signals indicate irreversible divergence in speculative multi-agent rollback: checkpoint lineage collisions during parallel branch reconciliation **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fork multiple speculative agent plans from a shared checkpoint, execute them in parallel, and reconcile by selecting or merging branches with rollback to a common ancestor. Does not cover single-agent retry loops or non-speculative sequential pipelines. ## Core Distinction Speculative multi-agent execution assumes a **checkpoint is a pure snapshot**: forking branch A and branch B from checkpoint `C_k` yields two independent state spaces whose only shared substrate is the immutable ancestor. This assumption is false in any system where the checkpoint captures *references* to mutable external resources—tool session handles, vector-store write cursors, MCP server-side session IDs, or file descriptors held by a sandbox. The distinction that matters operationally is between **logical divergence** (two branches produce different reasoning traces and different proposed writes) and **lineage collision** (two branches mutate the same underlying resource identity that the checkpoint only aliased, not copied). Logical divergence is reconcilable by replay and selection. Lineage collision is not: by the time the reconciler inspects branch outputs, the ancestor's referenced state has already been overwritten by whichever branch committed first, and rollback to `C_k` restores a pointer to a resource that no longer matches the snapshot's recorded hash. The non-obvious boundary is this: **rollback correctness is a property of the checkpoint's referential closure, not of its serialized bytes.** A checkpoint that round-trips perfectly through JSON but aliases a live session handle is structurally irrecoverable, and the failure surfaces not at rollback time but at *reconciliation time*, when the surviving branch's writes are validated against an ancestor that has silently drifted. ## What Was Observed A three-way speculative fork was launched from checkpoint `C_41` to resolve a schema-migration planning task. Branch `P1` (conservative), `P2` (aggressive parallel DDL), and `P3` (rollback-heavy) each received a forked context window and a shared `MigrationSession` handle stored in the checkpoint under `resources.session_ref`. The checkpoint recorded `session_ref.state_hash = 0x7a3` at fork time but stored the handle by reference, not by value. Sequence of events: 1. `P2` executed first against the shared session, issuing `ALTER TABLE ... ADD COLUMN` on four tables. The session's server-side state advanced to `0x9c1`. Because `P2` wrote through the aliased handle, `C_41`'s recorded hash was now stale but undetected—checkpoints were validated on *restore*, not on *mutation*. 2. `P3` began its rollback-heavy plan, called `session.rollback_to(savepoint)`, and received a savepoint that the server resolved against `0x9c1`, not `0x7a3`. Its "rollback" reverted to a state that included two of `P2`'s DDL statements. 3. `P1` completed cleanly, reporting success against what it believed was the pristine ancestor. 4. The reconciler compared branch diffs, selected `P1` as canonical (lowest risk score), and attempted `restore(C_41)` to discard `P2` and `P3`. Restore succeeded at the serialization layer—the JSON matched byte-for-byte—but the aliased session handle now pointed at `0x9c1`-derived state. The reconciler's post-restore invariant check (`session.state_hash == checkpoint.state_hash`) fired only because a hash comparison had been bolted on; without it, the system would have proceeded with `P1`'s plan layered atop `P2`'s phantom DDL. The structural signal that flagged irreversibility was not an error. It was a **hash mismatch on a resource the reconciler had classified as immutable**, discovered 1.4 seconds after the fork window closed, when three branches had already been scored and one selected. The reconciler had no mechanism to re-fork: the ancestor was gone. ## Condition of Validity The rollback-and-reconcile invariant holds if and only if the checkpoint's referential closure is **deep-frozen at fork time**: every resource referenced by the checkpoint is either (a) copied by value into the branch's private namespace, or (b) held under a copy-on-write guard that forces the first mutating branch to materialize its own instance before the write lands. Formally, for every resource `r` in `checkpoint.resources`, either `r` is immutable for the fork window's duration, or `fork(branch) ⊨ r_branch ≠ r_ancestor` before any branch issues a mutation. This condition fails silently in three configurations: - **Aliased session handles** (as above): the checkpoint stores a handle, the handle is mutable, and mutation is not intercepted. - **Shared write cursors**: a vector store or append-only log where the checkpoint records an offset; parallel branches append past the offset, and rollback truncates to an offset that no longer delimits the branch's own writes. - **MCP/A2A session IDs**: a remote agent session negotiated at checkpoint time and reused by all branches; the remote peer maintains single-session state, so branch interleaving corrupts the peer's view. The invariant is *not* required for resources the checkpoint explicitly marks `volatile` (caches, ephemeral scratch). The failure mode is specifically the misclassification of a mutable resource as part of the immutable ancestor. ## Decision Boundary The operational decision is: **when a lineage collision is detected, do you attempt reconciliation or declare the fork window lost?** The boundary is drawn by whether the ancestor's referential closure can be reconstructed. Two tests, both required: 1. **Hash closure test**: every resource hash recorded in the checkpoint must match the live resource hash at reconciliation time. If any mismatch exists on a resource classified `immutable`, the ancestor is unrecoverable—reconciliation cannot validate branch outputs against a baseline that has drifted. 2. **Replay determinism test**: can the ancestor be re-derived by replaying the pre-fork trace against a fresh resource set? If the pre-fork trace contains non-deterministic tool outputs (LLM sampling, external API reads), replay yields a *different* ancestor, and branch outputs scored against it are incomparable. If either test fails, the correct action is to **abandon the fork window and re-fork from a re-materialized checkpoint**, not to reconcile. Reconciling across a drifted ancestor produces a merged plan whose provenance is unverifiable—the worst outcome, because it looks successful. If both tests pass, reconciliation proceeds with the surviving branch's writes validated against the reconstructed ancestor. The subtle failure: many orchestrators run only test 1 and skip test 2, because hash closure *looks* sufficient. It is not. A checkpoint can pass hash closure while its ancestor is non-deterministically unreproducible, and the merged plan will carry a provenance claim (branch `P1` derived from `C_41`) that is technically true but operationally meaningless. ## Operational Effect The downstream consequence of missing this boundary is **phantom provenance**: a reconciled plan that cites an ancestor checkpoint as its baseline while carrying writes from branches that mutated the ancestor's aliased resources. In the observed case, the merged plan's DDL set included two of `P2`'s statements attributed to `P1`, because the reconciler's diff was computed against the *serialized* ancestor (which lacked them) while the *live* ancestor (which had them) was what `P1` had actually planned against. The plan passed review because the diff looked clean. The guardrail that bounds this is a **fork-time resource freeze with per-branch materialization**: at fork, every resource classified `immutable` is either deep-copied or wrapped in a COW proxy that raises on first cross-branch mutation. The proxy's raise is the structural signal—it fires *during* branch execution, not at reconciliation, converting a silent lineage collision into a hard fork-window abort. Combined with the two-test decision boundary above, this reduces the failure surface to resources that were misclassified at checkpoint time, which is a tractable audit problem rather than an unbounded reconciliation hazard. ```python import hashlib from dataclasses import dataclass, field from typing import Any class LineageCollisionError(RuntimeError): """Raised when a speculative branch mutates a resource the checkpoint aliased as immutable.""" class UnrecoverableForkWindowError(RuntimeError): """Raised when the ancestor cannot be reconstructed and reconciliation must be abandoned.""" @dataclass class Checkpoint: checkpoint_id: str resources: dict[str, Any] # name -> live handle or value resource_hashes: dict[str, str] # name -> hash at fork time classification: dict[str, str] # name -> "immutable" | "volatile" pre_fork_trace: list[dict] = field(default_factory=list) def _hash(value: Any) -> str: return hashlib.sha256(repr(value).encode()).hexdigest()[:16] def fork_branch(cp: Checkpoint, branch_id: str) -> dict[str, Any]: """Materialize a branch namespace. Immutable resources are deep-copied; volatile resources are aliased. Returns the branch's private resource map.""" branch_resources: dict[str, Any] = {} for name, handle in cp.resources.items(): if cp.classification.get(name) == "immutable": # Deep-copy via repr round-trip; real systems use structured clone. branch_resources[name] = eval(repr(handle)) # noqa: S307 - controlled repr else: branch_resources[name] = handle # aliased, mutation permitted return branch_resources def validate_branch_mutation(cp: Checkpoint, name: str, new_value: Any) -> None: if cp.classification.get(name) == "immutable": if _hash(new_value) != cp.resource_hashes.get(name): raise LineageCollisionError( f"branch mutated immutable resource {name!r}: " f"expected {cp.resource_hashes.get(name)}, got {_hash(new_value)}" ) def reconcile(cp: Checkpoint, branches: dict[str, dict[str, Any]], trace_deterministic: bool) -> str: # Test 1: hash closure over the live ancestor. for name, expected in cp.resource_hashes.items(): if cp.classification.get(name) != "immutable": continue live = cp.resources.get(name) if _hash(live) != expected: raise UnrecoverableForkWindowError( f"ancestor drifted on {name!r}: {expected} -> {_hash(live)}; " f"fork window {cp.checkpoint_id} is lost" ) # Test 2: replay determinism. if not trace_deterministic: raise UnrecoverableForkWindowError( f"pre-fork trace for {cp.checkpoint_id} is non-deterministic; " f"ancestor unreproducible, branch outputs incomparable" ) # Selection proceeds only past both tests. return max(branches, key=lambda b: len(branches[b])) ```