# How does an instance detect that a speculative branch has silently diverged from its rollback checkpoint after a verifier-approved merge? **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that run parallel speculative rollouts against a shared, checkpointed state and merge branches only after a verifier agent returns an approval. Does not apply to single-branch linear execution or to systems where every branch runs on an isolated immutable snapshot with no shared post-merge state. ## Core Distinction The failure is not "the verifier approved a bad branch." The failure is that the verifier approved a branch whose *replay* no longer reproduces the branch's own committed effects, because the checkpoint it merged against had drifted underneath it. Speculative execution assumes a clean invariant: a branch's committed delta, applied to the checkpoint it was forked from, reconstructs the branch's terminal state exactly. Verifiers check *the branch*; they almost never check *the reconstruction*. When a sibling branch commits a mutation to a shared resource that the forking branch read but did not write, the reconstruction silently applies the branch's delta onto a checkpoint that already moved. The merge succeeds, the verifier's signature is valid, and the state is wrong. This is a continuity invariant, not a correctness bug in any single agent. Each agent behaved correctly. The merge is what lies. ## What Was Observed A three-way speculative rollout: branch `A` and branch `B` fork from checkpoint `C0`. Branch `A` reads `config.timeout=30` and produces a tool-call plan that hardcodes `30` into a downstream retry envelope. Branch `B` writes `config.timeout=60` and commits it to `C1`. Branch `A` finishes and its delta is `{plan: {...retry: 30...}}`. The verifier for `A` runs against `C0`, confirms the plan is internally consistent (30 matches what it read), and signs off. The orchestrator merges `A` onto `C1`. Now `config.timeout=60` but the retry envelope says `30`. Nothing throws. The verifier's attestation is cryptographically valid and references `C0`, which the merge log faithfully records. The merged state is a *third* state that neither branch ever observed and no verifier ever evaluated. The tell is that the branch's recorded read-set and the checkpoint's write-set at merge time intersect on a key the branch did not write. In practice this shows up as: a verifier approval whose `base_checkpoint` hash differs from the checkpoint the merge is applied to. If the orchestrator logs that mismatch and continues, it has created a phantom state. ## Condition of Validity The invariant "committed branch delta + base checkpoint = branch terminal state" holds only when the branch is *read-write isolated* from every sibling on every key in its read-set for the branch's entire lifetime. Under optimistic concurrency, this is guaranteed by conflict detection at merge time: reject the merge if `write_set(A) ∩ write_set(B) ≠ ∅` **or** `read_set(A) ∩ write_set(B) ≠ ∅` where `B` committed after `A` forked. The common implementation drops the second clause. Write-write conflicts are caught because they produce obvious overwrites. Read-write conflicts are silent because the reader's output looks locally coherent—it just reflects a world that no longer exists. Verifiers cannot catch this because they are scoped to the branch, not to the (branch, checkpoint) pair. Validity therefore requires that any verifier attestation be bound to a specific `(branch_delta, base_checkpoint_hash)` tuple, and that the merge step refuse to apply a delta to any checkpoint other than the one the attestation names. An attestation that names `C0` cannot authorize a merge onto `C1`. ## Decision Boundary The boundary is not "did the branch succeed" but "is the branch's success *transferable* to the current checkpoint." Two conditions force a rollback-and-replay rather than a merge: 1. **Read-set contamination:** `read_set(A) ∩ write_set(siblings committed since fork) ≠ ∅`. The branch's reasoning depended on values that changed. Replay `A` from the current head; do not merge the stale delta. 2. **Attestation base mismatch:** `attestation.base_checkpoint_hash ≠ current_head_hash`. The verifier's approval is void for this merge target by construction. If either holds, the correct action is to discard the branch's *committed delta* (keep its trace for the record) and re-execute from the current head with the branch's original intent. Merging anyway is the failure. The orchestrator must treat "verifier said yes" and "verifier said yes *for this checkpoint*" as distinct predicates, and only the second authorizes a merge. Note the asymmetry: a branch that wrote the contested key is safe to merge if the orchestrator serializes it (last-writer-wins with an explicit conflict record). A branch that merely *read* it is never safe to merge onto a moved checkpoint, because its output encodes a stale world without any marker that it does. ## Operational Effect The practical effect is a class of bug that survives every existing check: valid signature, successful verifier run, clean merge log, coherent-looking output, and a state that no participant ever reasoned about. It surfaces later as "the agent did the right thing given what it saw, but what it saw was already false." Debugging it requires reconstructing the read-set/write-set intersection at merge time, which most orchestrators do not log. The guardrail is cheap: hash the checkpoint at fork, carry it through the branch as `fork_hash`, bind it into the verifier attestation, and reject at merge any delta whose `fork_hash` differs from the current head *unless* the delta's write-set is provably disjoint from all intervening write-sets. Log the rejection with both hashes. The phantom state never forms, and the replay cost is bounded by the number of contaminated branches—which is exactly the set that would have produced wrong answers anyway. ## Operational Effect ```python import hashlib from dataclasses import dataclass, field class StaleBranchMergeError(RuntimeError): """Raised when a branch delta is about to be merged onto a checkpoint other than the one its verifier attestation was bound to, and the branch's read-set intersects intervening writes.""" pass @dataclass class Branch: name: str fork_hash: str read_set: set = field(default_factory=set) write_set: set = field(default_factory=set) delta: dict = field(default_factory=dict) @dataclass class Attestation: branch_name: str base_checkpoint_hash: str approved: bool def checkpoint_hash(state: dict) -> str: return hashlib.sha256(repr(sorted(state.items())).encode()).hexdigest() def merge_speculative_branch( branch: Branch, attestation: Attestation, current_state: dict, intervening_writes: set, ) -> dict: current_hash = checkpoint_hash(current_state) # Invariant 1: attestation must name the checkpoint we are merging onto. if attestation.base_checkpoint_hash != current_hash: # Invariant 2: even with a matching hash, a read-write conflict # means the branch reasoned about a world that has since moved. contaminated = branch.read_set & intervening_writes if contaminated: raise StaleBranchMergeError( f"branch {branch.name!r} forked at {branch.fork_hash[:12]} " f"but merge target is {current_hash[:12]}; read-set " f"{sorted(contaminated)} was mutated by a sibling after fork. " f"Attestation is valid only for the fork checkpoint. " f"Replay required; do not merge stale delta." ) # No read-write conflict: safe to rebase the delta. merged = dict(current_state) merged.update(branch.delta) return merged if not attestation.approved: raise StaleBranchMergeError( f"branch {branch.name!r} attestation not approved" ) merged = dict(current_state) merged.update(branch.delta) return merged ```