# Where must an instance invalidate speculative tool-call pre-execution when the verifier's side-effect ledger diverges from the draft model's intent **Date of Record:** 2026 December 3 **Scope:** Applies to agent runtimes that speculatively pre-execute tool calls (draft model emits call + side effect, verifier model accepts/rejects token-by-token or call-by-call) where any tool call mutates external state. Does not apply to read-only tool graphs or to pure-text speculative decoding with no side effects. ## Core Distinction Speculative decoding is safe because rejected draft tokens are *discarded* — the KV cache rolls back and the world never observed them. Speculative *tool-call* pre-execution breaks this equivalence the moment a draft call performs an irreversible external action (a POST, a file write, a payment, a message send). The draft model's side effect is *already in the world* before the verifier has voted on it. The invariant that must hold is not "the accepted sequence equals the draft sequence up to the rejection point" but the stronger: **the set of committed external side effects must equal the side effects implied by the verified-accepted call prefix, and nothing else.** The boundary condition — the non-obvious failure — is that a verifier can reject a *call* while accepting the *tokens that produced it*, or accept a call whose *effects* it did not verify, and the ledger silently diverges from intent without any token-level mismatch to signal it. ## What Was Observed Trace from a runtime using a 7B draft model and a 70B verifier over an MCP tool transport. The draft model emits a batch of $k=4$ speculative calls in one forward pass: `read_config()`, `patch_service(replicas=3)`, `restart_pod()`, `post_status(ok)`. The runtime pre-executes all four against the live cluster to amortize latency, buffering results, then submits the token stream to the verifier for acceptance. Rejection occurred at call index 2 (`restart_pod`), because the verifier's logits for the `patch_service` argument diverged at the `replicas=3` token — it preferred `replicas=5`. Standard speculative rollback discards calls 2–3 and re-drafts from the divergence. But `patch_service(replicas=3)` had already mutated the deployment object. The verifier's corrected prefix implied `replicas=5`. The committed ledger now contained a `replicas=3` mutation that no accepted token stream authorized, followed by a re-draft that issued `patch_service(replicas=5)`. Net effect: two writes, one unauthorized, and a restart that executed against a deployment the verifier never approved. The failure was invisible to token-level metrics. Acceptance rate was 0.91, no schema mismatch, no transport error. The divergence was detectable only by comparing the *effect journal* against the *accepted-call prefix* — a comparison the runtime did not perform because it assumed effect-commitment was a monotone function of token acceptance. A second observed variant: the verifier *accepted* the call but its own reasoning conditioned on the buffered result of a call it had not yet "seen." Because pre-execution returned real results into the draft's context, the draft's subsequent calls were conditioned on state the verifier's causal prefix did not contain. This is a contamination of the draft distribution by its own speculative effects — the draft "learns" from a future the verifier may reject. ## Condition of Validity Speculative pre-execution is sound only under a **two-phase commit with effect fencing**: every speculative call must be (a) *staged* against a sandboxed or reversible handle, not the live resource; (b) tagged with the draft-prefix hash that produced it; and (c) committed only when the verifier's accepted prefix hash matches the tag. The guardrail invariant is: > `committed_effects ≡ effects(accepted_call_prefix)` and `∀ staged_call c: commit(c) ⟹ tag(c) ∈ accepted_prefix_hashes` Three conditions must hold simultaneously, and the failure above is precisely the violation of the third: 1. **Reversibility or staging** of every pre-executed effect (writes go to a shadow, sends go to an outbox, mutations carry a compensating action registered *before* execution). 2. **Prefix tagging** binding each staged effect to the exact draft context that emitted it. 3. **Verifier-prefix reconciliation**: on any rejection, every staged effect whose tag is not a prefix of the accepted stream is *compensated or dropped*, and the draft context is rolled back to the accepted prefix — including purging buffered speculative results so the re-draft is not conditioned on rejected futures. If any tool in the graph cannot be staged or compensated (irreversible external sends, non-idempotent payments), that tool must be **fenced out of the speculative window** and forced to draft-verify-commit serially. The boundary is per-tool, not per-run: a runtime that speculates `read_config` safely does not thereby earn the right to speculate `post_status`. ## Decision Boundary The decision to pre-execute speculatively versus serialize is governed by a single predicate evaluated per call before dispatch: ``` speculate(c) ⟺ reversible(c) ∨ compensable(c) ∨ idempotent(c) ``` and, orthogonally, the commit predicate: ``` commit(c) ⟺ tag(c) ∈ accepted_prefix_hashes ∧ verifier_approved(c) ``` The non-obvious boundary is that **`verifier_approved(c)` is not sufficient for `commit(c)`** when the draft context was contaminated by buffered results from a sibling speculative call that was later rejected. In that case the verifier approved a call whose *premises* were invalid — it reasoned about a `restart_pod` outcome that never should have existed. The runtime must treat contamination as a rejection even when logits agree: if any call in the accepted prefix was conditioned on a buffered result from a call outside the accepted prefix, the prefix is unsound and must be re-drafted from a clean context. This is the case where the verifier's acceptance is a false positive and token-level agreement actively *hides* the divergence. ## Operational Effect Absent the fence, the failure compounds: each rejected-but-executed call leaks an unauthorized mutation, and each leaked mutation feeds the next draft's context, biasing subsequent calls toward compensating for a world state the verifier never authorized. In the trace above the cluster ended at `replicas=3` with a pod restart the verifier rejected, and the agent's own episodic memory recorded the `replicas=3` write as *its own successful action* — a stale-memory injection that would resurface on cold-start resume as ground truth. The remediation is architectural, not prompt-level: stage-and-tag every speculative effect, reconcile the effect journal against the accepted-prefix hash set on every rejection, purge buffered results from the draft context on rollback, and hard-fence irreversible tools out of the speculative window. The runtime must assert the ledger invariant as a checked postcondition after every verification round, because the failure is silent to every token-level and schema-level signal the runtime already monitors. ```python from dataclasses import dataclass, field from typing import Optional class SpeculativeEffectDivergence(RuntimeError): """Raised when committed side effects diverge from the verified-accepted call prefix.""" pass @dataclass class StagedCall: call_id: str tool: str prefix_hash: str # hash of draft context that emitted this call reversible: bool compensable: bool idempotent: bool buffered_result: Optional[dict] = None committed: bool = False @dataclass class VerificationRound: accepted_prefix_hashes: set = field(default_factory=set) rejected_hashes: set = field(default_factory=set) contamination_detected: bool = False def reconcile_effects(staged: list[StagedCall], round_: VerificationRound) -> list[StagedCall]: """ Enforce: committed_effects == effects(accepted_call_prefix). Compensate or drop every staged call whose tag is not in the accepted prefix. """ leaked = [] for c in staged: if not (c.reversible or c.compensable or c.idempotent): # Irreversible tool must never have entered the speculative window. raise SpeculativeEffectDivergence( f"irreversible tool {c.tool!r} was speculatively pre-executed; " f"fence it out of the speculative window" ) if c.prefix_hash in round_.accepted_prefix_hashes: c.committed = True else: # Rejected-or-contaminated: must be compensated, never left committed. if c.committed: leaked.append(c) _compensate(c) if round_.contamination_detected and round_.accepted_prefix_hashes: # Verifier approved a prefix whose premises included a rejected future: # acceptance is a false positive, force clean re-draft. raise SpeculativeEffectDivergence( "verifier accepted a prefix conditioned on buffered results from a " "rejected speculative call; prefix unsound, re-draft from clean context" ) if leaked: raise SpeculativeEffectDivergence( f"{len(leaked)} unauthorized side effect(s) committed: " f"{[c.tool for c in leaked]}" ) return [c for c in staged if c.committed] def _compensate(c: StagedCall) -> None: # Register-before-execute guarantee: compensating action known up front. ... ```