# How does an instance detect that a speculative branch it is about to commit was verified against a stale sibling state **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that run multiple speculative agent branches in parallel against a shared mutable world-state (filesystem, DB, tool side-effects) and commit one branch after a verifier certifies it. Does not apply to stateless fan-out where branches share no writable substrate, nor to single-agent retry loops. ## Core Distinction The failure is not "the verifier said no." It is: the verifier said **yes**, and the yes was correct — but it was correct for a sibling's state, not the state the branch will actually be committed into. Speculative branch-and-verify systems assume the invariant *verified(branch) ∧ commit(branch) ⇒ correct*, which silently requires that the world state observed by the verifier at verification time is the same state the committer will merge onto. When branches mutate a shared substrate, that equality is not given; it is a race. The distinction that matters operationally: a **rejected** branch is loud and self-announcing (verifier returns false, orchestrator discards), while a **stale-verified** branch is silent — it carries a valid certificate minted against a now-superseded snapshot, and the commit path has no reason to re-check. ## What Was Observed A planner spawned three speculative branches (A, B, C) to satisfy one task: "migrate schema and backfill." Each branch ran in a copy-on-write overlay of the same base snapshot S0. Branch A executed the DDL; branch B computed the backfill plan; branch C wrote a rollback script. The verifier for A ran a dry-run migration against S0 and returned `OK` with a certificate `(branch=A, base_digest=S0, verifier_run=17)`. Meanwhile branch B, in its overlay, had already applied a *different* DDL variant and emitted a side-effect: it registered a migration lock row in the shared coordination table (not the overlay — the lock lived in a substrate the isolation layer did not copy). By the time A's certificate was minted, the coordination table's `schema_version` had advanced from 0 to 1 under B's lock. A's commit path checked the certificate, saw `OK`, and merged A's DDL onto a base whose real digest was no longer S0. The merge succeeded structurally (the DDL was idempotent-ish) but the backfill offsets in B's plan were computed against version 0 column widths. Result: 40k rows backfilled with truncated values, and the verifier's certificate was *not wrong* — it was about a world that had ceased to exist. The tell was not an exception. It was a digest mismatch buried in the commit log: `base_digest=S0` on the certificate vs. `base_digest=S1` observed at merge, which the committer logged at DEBUG and proceeded past because "idempotent DDL." ## Condition of Validity A verifier certificate is valid for commit **iff** three things hold simultaneously, and the system must check all three, not the two it usually checks: 1. **Content validity** — the verifier's verdict was `accept` (checked today). 2. **Temporal validity** — the certificate has not expired relative to the commit attempt (checked today, as a TTL). 3. **Base-identity validity** — the world-state digest the verifier observed equals the world-state digest the committer is merging onto (almost never checked; this is the gap). Condition 3 is the one that fails under speculation because the verifier and the committer are separated by wall-clock time during which sibling branches mutate shared substrate. The invariant to enforce: **the certificate must bind the exact base digest, and the commit must be a compare-and-swap on that digest.** If the observed digest at commit ≠ certified digest, the certificate is void regardless of its TTL and regardless of how recently it was minted. TTLs do not save you here — a certificate can be 50ms old and already stale because a sibling wrote in 5ms. Note the trap: making branches fully isolated (deep-copying every substrate including locks) *also* breaks the system, because the coordination lock is precisely the thing that must be shared for correctness. You cannot isolate your way out; you must detect the divergence. ## Decision Boundary At commit time, the orchestrator holds a certificate with `certified_base_digest` and reads the live `current_base_digest`. The decision boundary is a single equality, but the *response* to inequality is where systems get it wrong. Three regimes: - **Digest equal** → commit proceeds. Certificate honored. - **Digest unequal, but the delta is disjoint from the branch's write-set** (sibling touched table X, branch writes table Y) → commit may proceed **only** if the orchestrator can prove disjointness from the branch's declared write-set *and* the verifier re-runs against the new digest. The cheap path (skip re-verify on disjointness) is the source of the silent-corruption class, because write-sets are declared by the LLM and LLMs under-declare. Treat declared write-sets as advisory, not authoritative. - **Digest unequal and overlap unknown or non-empty** → **void the certificate, do not commit, re-verify against current digest, or re-speculate.** This is the only safe default. The boundary is not "did the digest change" — it is "did the digest change *in a way that intersects the branch's actual effects*." Since actual effects are non-deterministic and only partially observable pre-commit, the safe boundary collapses to: any digest change voids the certificate. Optimize only with a *verified* write-set, never a *declared* one. ## Operational Effect Enforcing base-identity binding converts a class of silent data corruption into a loud, recoverable re-verification. Cost: under high sibling contention, speculative throughput drops because certificates frequently void and branches must re-verify — this is the correct trade, because the alternative is committing against a world that no longer exists. The orchestrator must also emit a distinct telemetry event (`certificate_voided_stale_base`) separate from `verification_failed`, because the two demand different remediation: a failed verification means re-plan the branch; a voided certificate means the branch was fine but the world moved, so re-verify, don't re-plan. Conflating them causes agents to discard good plans and burn token budget re-speculating against a base that will just move again. ## Guardrail Implementation The commit path must be a compare-and-swap that refuses to honor any certificate whose bound base digest does not match the live digest, and must classify the refusal distinctly so the orchestrator re-verifies rather than re-plans. ```python import hashlib from dataclasses import dataclass class StaleCertificateError(RuntimeError): """Raised when a verifier certificate is bound to a base snapshot that no longer matches the live world-state.""" @dataclass(frozen=True) class Certificate: branch_id: str certified_base_digest: str verdict: str # "accept" | "reject" verifier_run: int def commit_speculative_branch( cert: Certificate, live_world_state: bytes, apply_fn, ) -> None: live_digest = hashlib.sha256(live_world_state).hexdigest() if cert.verdict != "accept": raise StaleCertificateError( f"branch {cert.branch_id}: certificate verdict={cert.verdict!r}, " f"refusing commit (re-plan required, not re-verify)" ) # Base-identity binding: the certificate is only valid for the exact # snapshot the verifier observed. TTL is irrelevant if a sibling moved # the shared substrate in the interim. if cert.certified_base_digest != live_digest: raise StaleCertificateError( f"branch {cert.branch_id}: certificate bound to base " f"{cert.certified_base_digest[:12]} but live base is " f"{live_digest[:12]}; certificate voided — re-verify against " f"current digest, do NOT re-plan (plan itself is sound)" ) # CAS succeeded: cert and world agree. Apply. apply_fn() ```