# Why does an instance of a speculative executor commit work that its verifier has already invalidated: the verifier-gated commit race in multi-agent speculative execution **Date of Record:** 2026 November 29 **Scope:** Applies to any multi-agent topology where one or more "speculator" agents execute tool calls or generate state mutations speculatively and a separate "verifier" agent gates the commit of that work. Does not apply to single-agent self-verification loops, nor to speculative decoding at the token level inside a single model. ## Core Distinction The failure we are isolating is not "the verifier says no." It is **the speculator committing a speculative artifact after the verifier has already emitted an invalidation, because the commit path and the invalidation path are not serialized against the same versioned artifact handle.** Speculation in agent systems is usually framed as a cost model: run *k* speculative branches in parallel, pay only for the branches the verifier accepts, discard the rest. That framing assumes the verifier's rejection is a *sink* — a terminal state for a branch. In practice the rejection is an *event* that races the branch's own commit event, and the branch's commit event is decided by the speculator's local control flow (which has already been scheduled, has already consumed tokens, and has already buffered tool side-effects) rather than by an atomic read of the verifier's verdict. The distinction that matters operationally: a **verifier-gated commit** is a two-phase protocol, not a filter. Phase one is speculative execution producing a *candidate artifact* with a monotonically increasing `(branch_id, spec_version)` handle. Phase two is a verifier decision that either *promotes* the artifact (binds it to the committed state) or *invalidates* it (marks the handle dead). The invariant that must hold is: **no promotion may occur for a handle whose invalidation has been observed by any process that shares the state store.** When this invariant is violated, you get a *ghost commit* — a mutation that the verifier believes it prevented and the speculator believes it was permitted to make. ## What Was Observed A 4-speculator / 1-verifier swarm was executing a sequence of file-mutating and API-calling tasks. Speculators were fanned out at *k*=4 with a shared `spec_version` counter per task. The verifier ran a replay of each candidate against a re-fetched ground-truth snapshot and emitted `PROMOTE` or `INVALIDATE` on a control channel. Speculators polled the control channel at the top of each tool-call loop iteration. The observed trace, for a single task `T`: 1. Speculator `S2` builds candidate artifact `A` at `spec_version=7`, runs a `write_file` tool call whose side-effect is buffered locally (not yet flushed to the shared store), and enters its control-channel poll. 2. Verifier replays `A` against the ground-truth snapshot, finds that `A` depends on a retrieval result that was invalidated by an upstream task's rollback, and emits `INVALIDATE(A, spec_version=7)` on the control channel at wall-clock `t=0`. 3. Speculator `S2`'s poll at `t=+40ms` sees the message but the message's `spec_version` field is `7`, while `S2`'s *local* view of `spec_version` has advanced to `8` because a peer speculator `S3` incremented the shared counter between `S2`'s artifact build and its poll. `S2`'s poll handler, written as `if msg.spec_version < self.spec_version: continue` (a "stale message" guard intended to drop out-of-order control traffic), drops the invalidation as stale. 4. `S2` flushes the buffered `write_file` side-effect to the shared store and emits `PROMOTE(A, spec_version=8)`. 5. The verifier's state store now contains `A`, which the verifier's own replay had proven invalid, and the verifier's audit log contains an `INVALIDATE(A, spec_version=7)` with no corresponding `PROMOTE` — the two records are keyed by different version numbers and never reconcile. The root mechanism is not a lost message. The message arrived. It was **dropped by a staleness guard whose comparison key was the wrong field.** The speculator used `spec_version` (a *global* counter shared across branches) to decide whether a *branch-local* invalidation was stale. `spec_version` is monotonic per-task, not per-branch, so any peer's increment looks like "this message is about an older world" even when the message is about *this* branch's artifact. The invalidation was fresh; the guard's key was wrong. A second, subtler variant was observed on the same swarm: the verifier emitted `INVALIDATE` *after* the speculator's commit had already been accepted by the shared store but *before* the verifier's own replay of the committed state had run. Here the commit is not a ghost — it is visible — but the verifier's subsequent replay sees the committed artifact and, because the replay is keyed on `(branch_id)` and the artifact was committed under `(branch_id, spec_version=8)`, the replay treats the committed artifact as a *new* candidate and re-validates it, sometimes promoting it a second time. The verifier's replay is not idempotent against its own commit path. ## Condition of Validity The verifier-gated commit protocol is sound only under the following conjunction, which must be enforced structurally rather than by convention: - **Handle identity:** every candidate artifact is addressed by an immutable `(branch_id, spec_version_at_build)` tuple assigned at build time, and this tuple is the *only* key used to match a verifier decision to a candidate. It must not be re-derived from a shared counter at poll time. - **Decision monotonicity per handle:** for a given `(branch_id, spec_version_at_build)`, the verifier's decision is a single value in `{PROMOTE, INVALIDATE, PENDING}` and transitions only `PENDING → (PROMOTE | INVALIDATE)`, never back. This requires the verifier to write the decision with a compare-and-swap on the handle, not with an append. - **Commit serialization on the handle:** the speculator's commit path must acquire the handle (CAS from `PENDING` to `COMMITTING`) before flushing side-effects, and must re-read the decision inside the same critical section. If the decision is `INVALIDATE`, the commit path must abort and flush a compensating rollback, not proceed. - **Idempotent replay:** the verifier's replay must key on the handle and treat an already-committed artifact as `COMMITTED` (terminal), not as a fresh candidate. The failure occurs precisely when any one of these is violated. In the observed trace, the first and third were violated simultaneously: the handle was re-derived from the shared counter (violating handle identity), and the commit path did not re-read the decision inside a critical section (violating commit serialization). ## Decision Boundary The boundary between "safe to speculate" and "ghost commit possible" is the point at which the speculator's commit path stops being a function of the verifier's decision and starts being a function of the speculator's local control flow. Concretely: - **Safe:** the speculator may buffer side-effects freely, but the flush is gated on a CAS acquisition of the handle, and the decision is read *inside* that CAS. The window between "decision written by verifier" and "decision read by speculator" is closed by the CAS: a speculator that loses the CAS to an `INVALIDATE` write cannot flush. - **Unsafe:** the speculator polls the decision at loop top, then flushes at loop bottom, with no atomic binding between the two. The poll-to-flush gap is the ghost window. Any peer increment of a shared counter, any out-of-order control message, any retry that re-enters the loop without re-polling, opens the window. The decision rule for an operator is: **if the speculator's commit path contains a `continue`/`skip`/`return` that can be reached by a message-classification predicate, and that predicate compares against any counter that is not the handle's own build-time version, the protocol is unsound.** The observed `if msg.spec_version < self.spec_version: continue` is exactly this shape. The correct predicate is `if msg.handle != self.handle: continue` — drop by handle mismatch, never by version ordering. A second decision boundary concerns the verifier's replay: if the verifier can observe the committed state before its own decision is durable, the replay must be able to distinguish "artifact committed by a speculator" from "artifact committed by me." The former must be treated as `COMMITTED` and not re-validated; the latter is the verifier's own terminal write and must be idempotent under replay. ## Operational Effect The downstream effects of a ghost commit are not localized to the task. Because the committed artifact is visible in the shared store, every subsequent speculator and verifier that reads the store inherits the invalid artifact as ground truth. In the observed swarm, the ghost `write_file` at `spec_version=8` was read by `S1` on the next task as a valid dependency, causing `S1` to build a candidate on top of it; the verifier's replay of `S1`'s candidate re-fetched the ground-truth snapshot, which did not contain the ghost, and flagged `S1` as a *divergence* rather than as a *poisoned input*. The divergence was attributed to `S1`'s reasoning, not to the ghost, and `S1` was restarted — which cleared the symptom but not the ghost, since the ghost was in the shared store and survived restart. The second-order effect is cost-model corruption. The speculative execution cost model assumes rejected branches are *free* (their side-effects are never flushed). A ghost commit means a rejected branch has flushed side-effects, so the cost model under-counts by exactly the cost of the ghost's side-effects plus the cost of every downstream candidate that built on it. In the observed swarm, the ghost's `write_file` triggered a downstream re-indexing job that consumed roughly 40% of the task's total token budget — a cost the model attributed to accepted branches. The architectural guardrail is the CAS-bound handle described in *Condition of Validity*. The minimal patch is to replace the version-ordering staleness guard with a handle-equality guard, and to move the decision read inside the commit critical section. The non-negotiable invariant is: **a speculator may only flush side-effects for a handle it has CAS-acquired from `PENDING`, and the decision read inside that CAS is authoritative.** Any protocol that reads the decision outside the CAS, or that classifies decisions by a counter other than the handle's build-time version, is a ghost-commit generator regardless of how many messages it successfully delivers. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class GhostCommitError(RuntimeError): """Raised when a speculator attempts to commit a handle whose verifier decision is INVALIDATE, or when a handle's identity is re-derived from a shared counter instead of its build-time version.""" class Decision(Enum): PENDING = "pending" PROMOTE = "promote" INVALIDATE = "invalidate" COMMITTING = "committing" COMMITTED = "committed" @dataclass(frozen=True) class Handle: branch_id: str spec_version_at_build: int # immutable; assigned at artifact build time @dataclass class HandleState: decision: Decision = Decision.PENDING committed: bool = False class VerifierGatedCommitStore: """Minimal model of a verifier-gated commit protocol. The invariant enforced here: a speculator may only flush side-effects for a handle it has CAS-acquired from PENDING, and the decision read inside that CAS is authoritative. A decision classified by any counter other than the handle's build-time version is rejected as a ghost-commit vector. """ def __init__(self) -> None: self._handles: dict[Handle, HandleState] = {} def register(self, handle: Handle) -> None: if handle in self._handles: raise GhostCommitError(f"handle already registered: {handle}") self._handles[handle] = HandleState() def verifier_decide(self, handle: Handle, decision: Decision) -> None: if decision not in (Decision.PROMOTE, Decision.INVALIDATE): raise GhostCommitError(f"illegal verifier decision: {decision}") state = self._handles.get(handle) if state is None: raise GhostCommitError(f"decision for unknown handle: {handle}") # Decision monotonicity per handle: PENDING -> terminal, never back. if state.decision is not Decision.PENDING: raise GhostCommitError( f"handle {handle} already decided as {state.decision}; " f"refusing to overwrite with {decision}" ) state.decision = decision def speculator_commit( self, handle: Handle, observed_global_version: int, side_effect: str, ) -> None: """Commit path. `observed_global_version` exists ONLY to demonstrate the bug: a correct implementation must not use it to classify decisions. It is accepted here so the guard below can reject callers that try to use version ordering as a staleness key. """ state = self._handles.get(handle) if state is None: raise GhostCommitError(f"commit for unknown handle: {handle}") # The bug: classifying a decision as stale by comparing a *global* # counter against the handle's build-time version. Any peer increment # makes a fresh invalidation look stale. Reject this shape outright. if observed_global_version != handle.spec_version_at_build: raise GhostCommitError( f"commit for {handle} classified by global version " f"{observed_global_version} != build-time " f"{handle.spec_version_at_build}; " f"this is the ghost-commit vector" ) # CAS-acquire the handle from PENDING. The decision read inside this # critical section is authoritative. if state.decision is Decision.INVALIDATE: raise GhostCommitError( f"refusing to commit {handle}: verifier already invalidated" ) if state.decision is Decision.PROMOTE and not state.committed: state.committed = True self._flush(handle, side_effect) return if state.decision is Decision.COMMITTED or state.committed: # Idempotent: already committed, do not re-flush. return raise GhostCommitError( f"cannot commit {handle}: decision is {state.decision}, " f"not PROMOTE" ) def _flush(self, handle: Handle, side_effect: str) -> None: # Placeholder for the real side-effect flush (write_file, API call). pass def reproduce_ghost_commit() -> None: store = VerifierGatedCommitStore() handle = Handle(branch_id="S2", spec_version_at_build=7) store.register(handle) # Verifier invalidates the candidate at build-time version 7. store.verifier_decide(handle, Decision.INVALIDATE) # Speculator polls at loop top, sees global spec_version has advanced to 8 # (a peer incremented it), and — under the buggy guard — would treat the # invalidation as stale and proceed. The store rejects the shape. try: store.speculator_commit( handle, observed_global_version=8, side_effect="write_file:/etc/task_T/state.json", ) except GhostCommitError as exc: # Expected: the protocol refuses to let the speculator commit. assert "ghost-commit vector" in str(exc) return raise GhostCommitError( "ghost commit was not prevented: speculator committed an " "invalidated handle" ) if __name__ == "__main__": reproduce_ghost_commit() ```