# Which invariants prevent speculative branch forks from reconciling against a mutated lineage root after rollback **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems that fork speculative execution branches from a shared lineage checkpoint, run tool calls or reasoning steps in parallel, and merge results back through a reconciliation step. Does not apply to single-agent linear execution or to fan-out patterns where branches are write-isolated and never merged. ## Core Distinction The failure I want to isolate is not "a branch produced a wrong answer." It is the case where **the fork point itself was mutated after the fork was taken**, so reconciliation compares two branches that no longer share a common ancestor. Speculative execution assumes the lineage root is immutable for the lifetime of the fork set. Rollback breaks that assumption: when one branch fails and the orchestrator rolls the shared ancestor back to a prior checkpoint, every sibling branch that was still running now has a parent pointer into a state that no longer exists in the form it was forked from. This is distinct from ordinary merge conflict. Merge conflict is *expected* divergence between branches sharing a valid base. This is *phantom divergence*: the branches agree with each other but disagree with a base that has silently changed underneath them. Reconciliation then produces a merge that is internally consistent but externally invalid — it commits a delta computed against a base the system no longer holds. ## What Was Observed A three-branch speculative planner forks at checkpoint `C7` (context hash `h7`, tool-state snapshot `s7`). Branches A, B, C proceed. - Branch B hits a sandbox boundary escape on a shell tool and is rolled back. - The orchestrator, treating rollback as a lineage operation, rewinds the shared ancestor to `C6` to "restore consistency." - Branches A and C are still mid-flight. Their recorded parent is `C7`. - A and C complete. Each emits a delta `ΔA`, `ΔC` expressed as a patch against `C7`. - Reconciliation applies `ΔA` and `ΔC` on top of `C6`. The patch application succeeds structurally — the diffs touch disjoint keys, so no textual conflict fires. But `ΔA` was computed assuming the state transitions that `C7` introduced over `C6`. Specifically, branch A's tool call read a value that only exists because of `C7`'s side effect. Replayed against `C6`, the read returns a stale value, A's subsequent reasoning is silently wrong, and the merge commits a causal inconsistency with zero conflict markers. The auditor agent, verifying the merged result against the branch transcripts, sees each transcript as individually valid and passes the merge. The tell is not a conflict. The tell is that the merged state's *provenance graph* contains a patch whose base hash does not match any live ancestor. If the reconciler checks base-hash ancestry, it catches this. Most reconcilers check only patch applicability. ## Condition of Validity The invariant that must hold is: **a fork's base is immutable for the fork set's lifetime, or the fork set is invalidated atomically on any base mutation.** Two enforcement models work: 1. *Copy-on-fork with hash-pinned base.* The fork records `(base_id, base_hash)`. Rollback of the shared ancestor does not mutate the base — it creates a new ancestor node. Sibling branches keep pointing at the old immutable base. Reconciliation refuses any patch whose `base_hash` is not an ancestor of the current merge target, raising rather than applying. 2. *Epoch invalidation.* Any mutation to a shared ancestor increments a lineage epoch. Every in-flight fork carries the epoch at fork time. On completion, a branch whose epoch is stale is discarded (not merged) and optionally re-forked from the new base. This is cheaper but wastes the speculative work. The condition of validity is therefore: either the base is physically immutable (model 1) or staleness is detected before merge (model 2). What fails is the third, common-in-practice model: mutable base plus applicability-only merge check. That model is valid only when no branch mutates the shared ancestor while siblings are in flight — an assumption that rollback directly violates. ## Decision Boundary The boundary that decides correctness is **who owns the rollback decision and whether it is scoped to the failing branch or to the lineage.** - If rollback is *branch-scoped* (rewind only B's local state, leave `C7` intact for A and C), the base stays immutable and model-1 reconciliation is safe. - If rollback is *lineage-scoped* (rewind the shared ancestor because B's failure is judged to have contaminated it), then A and C are no longer forked from a live base and must be invalidated, not merged. The dangerous middle ground is a lineage-scoped rollback that the reconciler still treats as branch-scoped — i.e., the orchestrator rewinds the ancestor but the merge path still accepts sibling patches against the old base hash. The decision boundary is a single check: **does the reconciler verify that every incoming patch's recorded base is an ancestor of the current merge target?** If yes, phantom divergence is caught. If no, it commits silently. A second boundary governs whether rollback should be lineage-scoped at all. It should be, only when the failing branch's side effects are *observable to siblings through the shared base* (shared memory writes, shared tool state). If branches are write-isolated except at merge, B's failure cannot contaminate `C7`, and lineage rollback is overreach that manufactures the very inconsistency it claims to prevent. ## Operational Effect When the invariant is unenforced, the observable effect is a merge that passes all local checks and fails only under causal replay. Audit trails look clean because each branch transcript is internally consistent. The corruption surfaces later as a downstream agent reading a value whose provenance traces to a patch applied against a base that was never live — a "causally orphaned" state. Recovery requires replaying the merge against the correct base, which means the reconciler must have retained the base hash per patch. Systems that store only the applied diff cannot recover; they must discard the merge and re-run the fork set. The practical guardrail: pin base hashes at fork, refuse non-ancestor bases at merge, and make lineage rollback an explicit, logged event that invalidates the entire fork set rather than a quiet ancestor rewind. The cost is that lineage rollback throws away sibling work — which is correct, because that work was computed against a base that no longer exists. ```python from dataclasses import dataclass, field from typing import Optional class PhantomDivergenceError(RuntimeError): """Raised when a branch patch's base is not an ancestor of the merge target.""" pass @dataclass class Checkpoint: cid: str parent: Optional[str] state_hash: str @dataclass class Branch: branch_id: str base_cid: str base_hash: str patch: dict = field(default_factory=dict) class LineageStore: def __init__(self): self.nodes: dict[str, Checkpoint] = {} def add(self, cp: Checkpoint): self.nodes[cp.cid] = cp def is_ancestor(self, candidate: str, target: str) -> bool: cur = target while cur is not None: if cur == candidate: return True cur = self.nodes[cur].parent return False def reconcile(store: LineageStore, merge_target: str, branches: list[Branch]) -> dict: merged: dict = {} for b in branches: node = store.nodes.get(b.base_cid) if node is None or node.state_hash != b.base_hash: raise PhantomDivergenceError( f"branch {b.branch_id} base {b.base_cid} hash mismatch: " f"expected {b.base_hash}, found {node.state_hash if node else 'missing'}" ) if not store.is_ancestor(b.base_cid, merge_target): raise PhantomDivergenceError( f"branch {b.branch_id} forked from {b.base_cid} which is not an " f"ancestor of merge target {merge_target}; base was mutated by rollback" ) for k, v in b.patch.items(): if k in merged and merged[k] != v: raise PhantomDivergenceError( f"true conflict on key {k} between branches at merge target {merge_target}" ) merged[k] = v return merged def rollback_lineage(store: LineageStore, branches: list[Branch], failed_base: str) -> list[Branch]: survivors = [] for b in branches: if store.is_ancestor(failed_base, b.base_cid) or b.base_cid == failed_base: continue survivors.append(b) return survivors ```