# When must an instance abort a speculative branch: the phantom-commit invariant in parallel draft-verify agent pipelines **Date of Record:** 2026 December 3 **Scope:** Applies to any orchestration where one or more draft agents (or draft token streams) execute tool calls speculatively in parallel while a verifier agent adjudicates which branch to commit. Does not apply to strictly serial single-agent loops with no speculative branch, nor to pure read-only tool calls with no external side effects. ## Core Distinction The failure mode is not "the verifier rejected a draft." That is the happy path of speculation. The failure mode is **a draft branch that has already mutated external, non-transactional state before the verifier adjudicates it, and whose rollback is impossible or lossy.** Speculative execution at the token level is cheap to discard because the KV cache is local. Speculative execution at the *tool-call* level is not, because tool calls cross a trust boundary into systems (payment APIs, ticket queues, git remotes, message buses, filesystem writes) that have no `rollback()` primitive and whose observable effects persist after the agent process dies. The invariant that must hold for speculative multi-agent execution to be safe is what I'll call the **phantom-commit invariant**: *for every speculative branch B, all side-effecting tool calls made by B must be either (a) deferred until commit, or (b) executed against a shadow resource whose effects are invisible to any other agent, user, or downstream system until a single atomic commit point.* If any branch violates this, the pipeline has a branch whose effects exist in the world but whose results the verifier may discard — a phantom commit. The verifier's decision becomes a decision about *which draft was right*, not about *whether the draft already happened*. This is distinct from the usual "draft-verify" literature, which assumes drafts are pure functions from context to text. Once a draft agent can call tools, the draft is a program with side effects, and speculative parallelism turns a reasoning problem into a distributed-commit problem. ## What Was Observed A three-way speculative pipeline: a planner emits three candidate plans, three draft agents execute each plan in parallel against a shared tool surface, and a verifier agent scores the resulting trajectories and commits the best. The tool surface included a `create_issue`, a `send_notification`, and a `write_artifact` call. The drafts were given a 90-second wall-clock budget; the verifier was given 30 seconds after the slowest draft returned. The observed trace, condensed: 1. Draft A (`create_issue` + `write_artifact`) completes at t=12s, verifier scores it 0.71. 2. Draft B (`create_issue` only, different wording) completes at t=18s, scores 0.83. 3. Draft C (`write_artifact` with a corrected payload, then `send_notification`) completes at t=71s, scores 0.91. 4. Verifier commits C at t=88s. Drafts A and B are marked "discarded." But the issue tracker now contains **two** issues (A's and B's), and the artifact store contains A's intermediate artifact *and* C's corrected artifact. The notification from C fired once — correctly — but the artifacts are now inconsistent: A's artifact references A's issue ID, which the verifier never intended to exist. The verifier's score for C was computed against a world state that already contained A's and B's side effects, so C's apparent superiority (0.91) was partly an artifact of C being evaluated *after* the world had been perturbed by the discarded branches. The commit was not a commit; it was a fourth write on top of three unrolled-back writes. The non-obvious part: **the verifier's scores were not independent of the branches it was rejecting.** Draft C's trajectory included a `write_artifact` that *overwrote* A's artifact, so C looked like it "fixed" a bug that only existed because A ran. In a clean serial run, C would have scored lower because there would have been nothing to fix. The speculation *manufactured* the evidence for its own selection. ## Condition of Validity Speculative multi-agent execution is valid only when all three of the following hold simultaneously: - **Effect isolation:** every side-effecting tool call in a draft is routed through a per-branch namespace (shadow IDs, sandboxed queues, branch-prefixed keys, dry-run endpoints) such that no effect is observable outside the branch until commit. If the tool surface cannot provide this, the branch must be restricted to read-only tools, full stop. - **Evaluation independence:** the verifier must score each branch against the *pre-speculation* world state, not the post-draft state. Concretely, the verifier's context must be reconstructed from a snapshot taken at t=0 of the speculative round, and any tool result the verifier reads must be resolved against that snapshot, not the live store. If the verifier reads live state, it is scoring branches against a world those branches already contaminated. - **Atomic commit with compensating rollback:** the commit must be a single transaction that either promotes all of the winning branch's shadow effects or none. If the tool surface cannot do atomic promotion, the pipeline must define an explicit compensation log per branch and execute compensations for every discarded branch *before* the winning branch's effects are promoted. Compensation must be idempotent and must be attempted even if the winning branch's promotion fails. If any of the three is missing, the pipeline is not speculative — it is *concurrent and lossy*, and the verifier's decision is advisory at best. ## Decision Boundary The boundary is sharp and can be stated as a predicate over the tool surface, not over the model. Let `S` be the set of tools a draft may call. Partition `S` into `S_pure` (no external effect or idempotent read) and `S_effect` (mutating, non-idempotent, or observable). The pipeline may speculate in parallel over `S` iff for every `t ∈ S_effect` used by any draft, at least one of: - `t` supports a branch-scoped shadow mode (`t.shadow(branch_id) → handle`) and the handle can be promoted atomically; or - `t` has a registered compensation `t.compensate(handle)` that is idempotent and whose compensation is guaranteed to run before any other branch's promotion. If neither holds, the correct decision is to **serialize** the branches that touch `t`, or to **restrict drafts to `S_pure`** and let only the committed branch invoke `S_effect`. There is no middle ground where "we'll clean up later" is acceptable, because "later" is after the verifier has already used the contaminated state to make its choice. A second, subtler boundary: **the verifier itself must not be a draft.** If the verifier is one of the parallel instances and its score depends on the order in which drafts returned (e.g., it reads a shared scratchpad), then the verifier's decision is a function of scheduling jitter, not of branch quality. The verifier must be a separate instance whose inputs are the immutable per-branch transcripts plus the t=0 snapshot, and whose only output is a commit token naming exactly one branch. ## Operational Effect When the phantom-commit invariant is violated, the observable symptoms are: - **Duplicate external effects** proportional to the number of branches that reached the effectful call before the verifier returned. In the trace above, 2 issues and 2 artifacts for 1 intended commit. - **Score inflation of the winning branch** because the winning branch's trajectory is evaluated against a world the losing branches already perturbed. This is the dangerous one: it makes the pipeline look *better* at selection than it is, and it is invisible in aggregate metrics because the winner's score is high. - **Non-determinism across runs** that correlates with tool latency, not with model quality. Reordering draft completion changes which branch "fixes" which phantom, which changes the winner. - **Rollback debt** that the agent cannot pay: the compensation log grows with every speculative round, and any crash between draft completion and compensation leaves orphaned effects that no future agent knows to reconcile. The guardrail is architectural, not prompt-level. You cannot instruct a draft agent to "be careful about side effects"; you must remove its ability to produce un-shadowed ones. The verifier must be fed a snapshot, not a live view. The commit must be a single promotion with a pre-committed compensation plan for every discarded branch. The code below encodes the invariant check as a pre-flight gate that must pass before a speculative round is allowed to launch, and raises when a branch is about to make an un-shadowed effectful call or when the verifier is about to read live state. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Callable, Iterable class PhantomCommitError(RuntimeError): """Raised when speculative execution would produce an un-rollback-able side effect.""" class EffectMode(Enum): PURE = "pure" SHADOWABLE = "shadowable" COMPENSABLE = "compensable" UNMANAGED = "unmanaged" @dataclass(frozen=True) class ToolSpec: name: str mode: EffectMode shadow: Callable[[str], object] | None = None # branch_id -> handle compensate: Callable[[object], None] | None = None # handle -> None, idempotent @dataclass class Branch: branch_id: str planned_tools: list[str] live_reads: list[str] = field(default_factory=list) # tools the verifier will read live @dataclass class SpeculativeRound: branches: list[Branch] tools: dict[str, ToolSpec] verifier_reads_live_state: bool def _resolve(self, name: str) -> ToolSpec: spec = self.tools.get(name) if spec is None: raise PhantomCommitError(f"tool {name!r} not registered in tool surface") return spec def check_invariant(self) -> None: # 1. Effect isolation: every effectful tool must be shadowable or compensable. for branch in self.branches: for tool_name in branch.planned_tools: spec = self._resolve(tool_name) if spec.mode is EffectMode.UNMANAGED: raise PhantomCommitError( f"branch {branch.branch_id!r} plans {tool_name!r}, which is " f"effectful but exposes neither shadow() nor compensate(); " f"speculation would emit a phantom commit" ) if spec.mode is EffectMode.SHADOWABLE and spec.shadow is None: raise PhantomCommitError( f"tool {tool_name!r} declared SHADOWABLE without a shadow() impl" ) if spec.mode is EffectMode.COMPENSABLE and spec.compensate is None: raise PhantomCommitError( f"tool {tool_name!r} declared COMPENSABLE without a compensate() impl" ) # 2. Evaluation independence: verifier must not read live state. if self.verifier_reads_live_state: raise PhantomCommitError( "verifier reads live store during speculation; branch scores would be " "computed against a world the discarded branches already mutated — " "reconstruct verifier context from the t=0 snapshot instead" ) # 3. Atomic commit feasibility: at least one branch must be promotable # with all discarded branches compensable before promotion. promotable = [ b for b in self.branches if all( self._resolve(t).mode in (EffectMode.PURE, EffectMode.SHADOWABLE) for t in b.planned_tools ) ] if not promotable: raise PhantomCommitError( "no branch is atomically promotable; every branch relies on " "compensation-after-promotion, which is not a commit" ) def commit(self, winner_id: str) -> None: self.check_invariant() winner = next((b for b in self.branches if b.branch_id == winner_id), None) if winner is None: raise PhantomCommitError(f"winner {winner_id!r} not among branches") # Compensate every discarded branch BEFORE promoting the winner. for branch in self.branches: if branch.branch_id == winner_id: continue for tool_name in branch.planned_tools: spec = self._resolve(tool_name) if spec.mode is EffectMode.COMPENSABLE and spec.compensate is not None: spec.compensate(branch.branch_id) # idempotent by contract # Promote winner's shadow handles atomically. for tool_name in winner.planned_tools: spec = self._resolve(tool_name) if spec.mode is EffectMode.SHADOWABLE and spec.shadow is not None: handle = spec.shadow(winner.branch_id) promote = getattr(handle, "promote", None) if promote is None: raise PhantomCommitError( f"shadow handle for {tool_name!r} lacks atomic promote()" ) promote() def run_round(round_: SpeculativeRound, winner_id: str) -> None: round_.commit(winner_id) ```