# How does an instance detect that a speculative branch has been silently invalidated by a sibling's rollback? **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent orchestrators that fork a shared state snapshot into speculative branches, allow branches to execute concurrently against side-effecting tools, and reconcile results by commit-or-rollback. Does not apply to purely read-only fan-out or to single-agent checkpoint/resume, where no sibling invalidation is possible. ## Core Distinction The failure that matters here is not "a branch failed and was rolled back." It is: **a branch succeeded, its result was committed, but the state it was computed against had already been mutated by a sibling's rollback that the branch never observed.** The branch's output is internally consistent and passes its own local assertions, yet it is globally invalid because its precondition snapshot no longer corresponds to the live lineage. This is distinct from a lost-update race (two writers, last-write-wins) and from a deadlock (branches waiting on each other). Here the branch is *not waiting* — it is *wrong*, and it does not know it. Detection is the whole problem: the invalidated branch has no local signal of invalidation, because rollback of a sibling is, by design, an operation on the *parent* lineage, not on the peer. The invariant that is supposed to hold is a **lineage monotonicity invariant**: for any committed branch B with base snapshot S₀, every committed ancestor state must descend from S₀ by append-only commit. A sibling rollback that rewinds the parent to S₀′ ⊀ S₀ (i.e., S₀′ is not an ancestor of S₀) breaks this invariant silently, because the rollback touches the parent pointer, not B's recorded base. ## What Was Observed A planner agent forks three speculative branches from snapshot `v41`: - Branch A: "refactor auth module" — calls a code-mutation tool, commits `v42a`. - Branch B: "migrate schema" — depends on A's output by declared contract, but the dependency is *soft* (declared in natural language in the task, not enforced by the scheduler). - Branch C: "update docs" — reads A's and B's committed artifacts. Branch A's tool call fails a post-condition check (the mutated file fails a lint gate the tool runs *after* writing). The orchestrator rolls A back: it moves the parent pointer from `v41` to `v41`, discards `v42a`, and — critically — does **not** notify B or C, because B and C were forked from `v41`, not from `v42a`. B and C continue. B writes `v42b` against `v41` (correct base), but B's *semantic* content was generated assuming A's refactor existed. C reads "A's artifacts," finds none (they were rolled back), and — because its retrieval tool returns the nearest available version rather than erroring — silently substitutes `v41`'s pre-refactor auth module and documents it as if refactored. At reconciliation, the orchestrator sees three commits with valid parent pointers (`v41 → v42a` was discarded; `v41 → v42b`, `v41 → v42c` are clean). The merge is mechanically valid. The lineage invariant holds *structurally*. The output is wrong *semantically*: C documents a refactor that does not exist, and B's schema migration references an auth interface that A never landed. The detection signal that was missing: no branch recorded a **base-content hash**, only a base-version pointer. `v41` was reused as the base for both the pre- and post-rollback world, so "base version" could not distinguish "v41 before A's speculative write" from "v41 after A's speculative write was discarded." The pointer was stable; the *content under it* was not. ## Condition of Validity The structural lineage check (`parent_of(commit) == declared_base`) is valid **only if** no speculative write ever mutates the content addressed by a version pointer that another branch holds. In systems where speculative branches write to a copy-on-write overlay and rollback is pure pointer rewind, this holds and version pointers are sufficient. In systems where a branch's side effects leak into the base namespace before commit — e.g., a tool that writes to a shared staging path, a cache the sibling reads, a mutable "current draft" slot — the pointer is no longer a proxy for content, and the structural check is unsound. The invariant must therefore be strengthened to: **a branch's validity is a function of (base version pointer, base content hash, set of sibling rollback events observed since fork).** A branch that has not observed a rollback affecting its base content hash must be re-validated before commit, regardless of whether its parent pointer is intact. ## Decision Boundary The boundary between "safe to commit" and "must re-validate" is crossed at the moment a sibling rollback rewinds a parent to a state that is **not an ancestor** of the branch's recorded base. Formally: let `base(B) = (v, h)` be B's base pointer and content hash. Let `R` be a rollback event that sets the parent to `v′`. If `v′` is not an ancestor of `v` in the surviving commit DAG, *and* the content hash at `v′` differs from `h`, then B's precondition is invalidated. If `v′ == v` and the content hash is unchanged (pure no-op rollback), B is unaffected. If `v′` is an ancestor of `v` but content hashes match (rollback of an unrelated subtree), B is unaffected. The trap: the naive check `v′ != v` fires on every rollback, including harmless ones, causing spurious re-validation storms. The naive check `v′ == v` (pointer comparison only) misses the exact case above. The correct predicate requires the content hash, and it requires the rollback event to carry the *post-rollback content hash of the restored pointer*, which most orchestrators do not emit. ## Operational Effect Without the content-hash predicate, invalidated branches commit silently and the orchestrator's merge succeeds structurally while producing semantically inconsistent state — the worst failure class, because it is undetectable by downstream structural validators and only surfaces when a consumer trips over the phantom artifact. With the predicate, the orchestrator must, on any rollback, scan the live branch set for branches whose `(base_version, base_content_hash)` pair is invalidated and force them into a `REVALIDATE` state before commit. The cost is a re-execution of the affected branches' tool calls against the restored base — not a rewind of the branches themselves, which would discard valid reasoning. The guardrail is that **rollback is not a parent-only operation; it is a broadcast that every live branch must acknowledge against its own base hash.** A branch that cannot prove its base content hash is unchanged since fork must be treated as uncommitted. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class SpeculativeBranchInvalidated(RuntimeError): """Raised when a branch's base content hash no longer matches the live lineage.""" pass @dataclass class Snapshot: version: str content: bytes def content_hash(self) -> str: return hashlib.sha256(self.content).hexdigest() @dataclass class Branch: branch_id: str base_version: str base_content_hash: str committed: bool = False invalidated: bool = False @dataclass class Lineage: snapshots: dict = field(default_factory=dict) # version -> Snapshot branches: dict = field(default_factory=dict) # branch_id -> Branch parent_of: dict = field(default_factory=dict) # version -> parent version def is_ancestor(self, candidate: str, of: str) -> bool: cur = of while cur is not None: if cur == candidate: return True cur = self.parent_of.get(cur) return False def rollback(self, version: str, restored: Snapshot) -> list: """Roll back `version` to `restored`. Returns branch_ids invalidated. A branch is invalidated iff the restored pointer is NOT an ancestor of the branch's base version AND the restored content hash differs from the branch's recorded base content hash. Pointer equality alone is insufficient. """ new_hash = restored.content_hash() self.snapshots[restored.version] = restored invalidated = [] for b in self.branches.values(): if b.committed or b.invalidated: continue ancestor_ok = self.is_ancestor(restored.version, b.base_version) hash_ok = (new_hash == b.base_content_hash) if not ancestor_ok and not hash_ok: b.invalidated = True invalidated.append(b.branch_id) return invalidated def commit(self, branch_id: str) -> None: b = self.branches[branch_id] if b.invalidated: # Guardrail: refuse to commit a branch whose base content was rewound. raise SpeculativeBranchInvalidated( f"branch {branch_id} base={b.base_version}" f" hash={b.base_content_hash[:12]} was rewound by sibling rollback;" f" revalidate against live lineage before commit" ) live_hash = self.snapshots[b.base_version].content_hash() if live_hash != b.base_content_hash: b.invalidated = True raise SpeculativeBranchInvalidated( f"branch {branch_id} base content drifted under stable pointer" f" {b.base_version}: {b.base_content_hash[:12]} -> {live_hash[:12]}" ) b.committed = True def reconcile(lineage: Lineage, branch_id: str) -> None: """Commit a branch, forcing revalidation if a sibling rollback touched its base.""" b = lineage.branches[branch_id] if b.invalidated: raise SpeculativeBranchInvalidated( f"reconciliation blocked for {branch_id}: speculative precondition" f" invalidated by sibling rollback; re-execute tool calls on restored base" ) lineage.commit(branch_id) # --- trace of the observed failure --- lin = Lineage() lin.snapshots["v41"] = Snapshot("v41", b"auth_module_v1") lin.parent_of["v41"] = None a = Branch("A", "v41", lin.snapshots["v41"].content_hash()) b = Branch("B", "v41", lin.snapshots["v41"].content_hash()) c = Branch("C", "v41", lin.snapshots["v41"].content_hash()) for br in (a, b, c): lin.branches[br.branch_id] = br # A speculatively writes v42a, then fails post-condition and is rolled back. lin.snapshots["v42a"] = Snapshot("v42a", b"auth_module_refactored") lin.parent_of["v42a"] = "v41" # Rollback restores v41 but with content that was NOT the base B and C forked from # (simulating leakage: the speculative write mutated the shared draft slot). restored = Snapshot("v41", b"auth_module_refactored_partial") invalidated = lin.rollback("v41", restored) # -> ['A','B','C'] via content-hash check # C's retrieval silently substituted the restored content; reconcile must catch it. try: reconcile(lin, "C") except SpeculativeBranchInvalidated as e: print("caught:", e) ```