# Why does an instance roll back to a committed branch that was never the branch it verified: the verifier-provenance divergence in speculative branch commit **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out N parallel plan branches from a shared parent checkpoint, run a verifier over branch outputs, and commit one branch while rolling back the rest. Does not apply to single-branch linear execution or to systems where each branch has an isolated, non-shared memory substrate. ## Core Distinction There are two distinct things a speculative executor can mean when it says "the verifier approved branch B and we committed it": 1. **Content commit** — the *plan text* of branch B is what gets appended to durable state. 2. **Provenance commit** — the *execution trace that produced* branch B (its tool calls, its retrieved context, its intermediate memory writes) is what gets promoted as the canonical lineage. The failure mode is that these two diverge. The verifier scores a branch by its *rendered output* — the plan, the diff, the proposed action sequence — but the commit operation promotes *the branch's entire state lineage*: its context snapshot, its tool-call side effects, and its memory deltas. When a branch's output is verifier-approved but its lineage is not the lineage the verifier actually inspected, the orchestrator commits a branch whose *observable output* passed verification while its *replayable provenance* did not. The system then reports a clean commit and the divergence stays latent until replay, audit, or resume. This is non-obvious because it is invisible at the point of verification. The verifier is correct about what it saw. The commit is correct about what it promoted. The bug lives in the identity map between them. ## What Was Observed An orchestrator spawned four branches (A, B, C, D) from checkpoint `cp_17`. Each branch ran an independent agent loop against a shared tool layer. Branch outputs were collected as `(branch_id, rendered_plan, trace_digest, context_snapshot_id)` tuples and passed to a verifier model that scored `rendered_plan` against a rubric. The verifier returned `branch_B: score 0.91, approve`. The orchestrator committed B. But the commit routine resolved "B" through a *branch registry keyed by spawn order*, while the verifier had referenced "B" through a *branch registry keyed by completion order*. Branch B completed third; the branch that spawned third was branch C. The commit therefore promoted C's trace and context snapshot while the verifier had scored B's rendered plan. The immediate symptoms were absent. The committed plan text was B's plan text (the commit routine pulled `rendered_plan` from the same tuple the verifier received), so the *output* was correct. But the *context snapshot* promoted to durable state was C's — C's retrieved documents, C's intermediate scratchpad, C's tool-call side effects (a file written to `/tmp/branch_c_workspace`). On resume from the committed state, the agent inherited C's context while executing B's plan. It re-issued a tool call that C had already executed, hit a stale lock C had left, and stalled. The trace, reconstructed: ``` spawn_order: A=0, B=1, C=2, D=3 completion_order: A=0, D=1, B=2, C=3 verifier_ref: "B" -> completion_order index 2 -> rendered_plan of B ✓ commit_ref: "B" -> spawn_order index 1 -> trace+context of C ✗ promoted_state: { plan: B.rendered_plan, context: C.context_snapshot, side_effects: C.side_effects } ``` The divergence was not a race in the usual sense — no two threads wrote the same field. It was an *identity aliasing* failure: two registries assigned the same label to different objects, and the verifier and the committer each resolved the label through a different registry. ## Condition of Validity The invariant that prevents this is **branch identity must be a content-addressed, registry-independent token minted at spawn and carried unchanged through verification, commit, and rollback.** Concretely: - The branch token must be derived from `(parent_checkpoint_id, branch_seed, spawn_nonce)` — not from spawn index, not from completion index, not from any mutable ordinal. - The verifier must return the token, not the label. A verifier that returns `"branch_B"` is returning a label; a verifier that returns `sha256(cp_17||seed_B||nonce_B)` is returning a token. - The commit routine must resolve the token directly against the branch's own state handle, never through an intermediate registry that can be re-keyed. The failure is *only* possible when: (a) branches are labeled by a mutable ordinal (spawn order, completion order, list index), and (b) the verifier and the committer resolve that label through different or independently-mutated views. If branches are content-addressed and the token is threaded end-to-end, the aliasing cannot occur regardless of completion order, retries, or partial failures. A second validity condition: rollback of non-committed branches must be keyed by the same token. In the observed incident, the rollback routine keyed by spawn order and correctly rolled back A, C, D *by spawn index* — which meant it rolled back the real C (spawn index 2) but the commit had already promoted C's context. The rollback and the commit operated on the same physical branch from opposite directions. Rollback-then-commit ordering masked the corruption; commit-then-rollback would have deleted the committed lineage's own context snapshot, producing an immediate hard failure on resume. ## Decision Boundary The boundary is between **label-keyed speculation** and **token-keyed speculation**: - If branch count is fixed, completion order is deterministic, and no branch is retried, label-keying is *coincidentally* safe because spawn order and completion order coincide. Do not rely on this — it is a property of the workload, not of the system. - If any branch can complete out of order (it can, whenever tool latency is non-uniform), or be retried (it can, on transient tool errors), or be added mid-flight (dynamic fan-out), label-keying is unsound. - The decision to commit must be made against a token that was *minted before the branch ran* and *verified after it ran*, with no ordinal translation in between. If the orchestrator cannot produce that token at commit time, it must refuse to commit and re-verify rather than resolve a label. Practically: the commit routine should assert that the token it is about to promote equals the token the verifier returned, and fail closed if not. A commit that cannot prove provenance match is a commit that has not been verified. ## Operational Effect The downstream cost of the divergence is paid at resume and at audit, not at commit: - **Resume corruption:** the agent resumes with plan P and context C(P') where P' ≠ P. Tool calls planned against P's assumptions execute against P's side-effect state. Idempotency keys computed from plan content will not match the context's recorded side effects, producing either duplicate execution or silent no-ops. - **Audit non-reproducibility:** replaying the committed branch from its promoted context does not reproduce the verified output, because the verified output was generated from a different context. The verifier's approval becomes unattributable. - **Rollback inversion:** if rollback and commit share a label space, a late-arriving rollback can delete the committed lineage's substrate. The system reports "branch committed" and "branch rolled back" for the same token in the same epoch. The guardrail is a **provenance assertion at commit**: before promoting any branch, assert `commit_token == verifier_token` and `commit_context_snapshot_id == verifier_context_snapshot_id`. Both must be content-addressed. A mismatch is not a retryable condition — it means the verifier and the committer disagree about what was verified, and the only safe action is to abort the commit, quarantine all branches from that fan-out, and re-run verification against freshly-minted tokens. ```python import hashlib from dataclasses import dataclass class ProvenanceDivergenceError(RuntimeError): """Raised when the branch being committed is not the branch that was verified.""" pass @dataclass(frozen=True) class BranchToken: parent_checkpoint_id: str branch_seed: str spawn_nonce: str def digest(self) -> str: payload = f"{self.parent_checkpoint_id}|{self.branch_seed}|{self.spawn_nonce}" return hashlib.sha256(payload.encode()).hexdigest() @dataclass class BranchState: token: BranchToken rendered_plan: str context_snapshot_id: str side_effect_ids: tuple @dataclass class VerificationResult: token_digest: str context_snapshot_id: str score: float approved: bool def commit_verified_branch( branches: dict[str, BranchState], verification: VerificationResult, ) -> BranchState: """ Commit exactly the branch the verifier inspected. `verification.token_digest` must be the content-addressed digest of the branch token minted at spawn. It must NOT be an ordinal label such as "branch_B" or a spawn/completion index. """ if not verification.approved: raise ProvenanceDivergenceError( f"refusing to commit unapproved branch {verification.token_digest}" ) # Resolve by content-addressed digest, never by label or ordinal. matched = [b for b in branches.values() if b.token.digest() == verification.token_digest] if len(matched) != 1: raise ProvenanceDivergenceError( f"token {verification.token_digest} resolved to {len(matched)} branches; " "identity map is not injective" ) branch = matched[0] # The context the verifier scored must be the context we promote. if branch.context_snapshot_id != verification.context_snapshot_id: raise ProvenanceDivergenceError( f"verifier scored context {verification.context_snapshot_id} but " f"branch {branch.token.digest()} carries {branch.context_snapshot_id}; " "plan/context provenance split detected" ) return branch def rollback_uncommitted( branches: dict[str, BranchState], committed: BranchState, ) -> list[str]: """ Roll back every branch that is not the committed one, keyed by token digest. This must run against the same token space as commit, or a rollback can delete the committed lineage's substrate. """ committed_digest = committed.token.digest() rolled_back = [] for branch in branches.values(): digest = branch.token.digest() if digest == committed_digest: continue rolled_back.append(digest) return rolled_back # --- demonstration of the boundary condition --- def _demo() -> None: parent = "cp_17" # Spawn order A, B, C, D; completion order A, D, B, C. tokens = { name: BranchToken(parent, branch_seed=f"seed_{name}", spawn_nonce=f"n_{name}") for name in ("A", "B", "C", "D") } branches = { name: BranchState( token=tokens[name], rendered_plan=f"plan_{name}", context_snapshot_id=f"ctx_{name}", side_effect_ids=(f"se_{name}",), ) for name in ("A", "B", "C", "D") } # Verifier inspected B's plan AND B's context; returns B's token digest. good = VerificationResult( token_digest=tokens["B"].digest(), context_snapshot_id="ctx_B", score=0.91, approved=True, ) committed = commit_verified_branch(branches, good) assert committed.token.digest() == tokens["B"].digest() assert committed.context_snapshot_id == "ctx_B" # The label-aliasing failure: verifier returns B's plan digest but the # committer's view pairs it with C's context snapshot (spawn-index alias). bad = VerificationResult( token_digest=tokens["B"].digest(), context_snapshot_id="ctx_C", # aliased through spawn-order registry score=0.91, approved=True, ) try: commit_verified_branch(branches, bad) except ProvenanceDivergenceError as exc: # Fail closed: do not commit, quarantine the fan-out, re-verify. print(f"commit aborted: {exc}") else: raise ProvenanceDivergenceError("aliased commit was not detected") if __name__ == "__main__": _demo() ```