# When must an instance discard prefetched tool results after speculative plan decoding diverges from the committed plan **Date of Record:** 2026 November 24 **Scope:** Applies to agents that decode a candidate plan and speculatively execute (prefetch) its tool calls before the plan is committed, then verify prefetched results against the committed plan. Does not apply to strictly sequential agents that execute only committed steps, nor to prefetching that is purely read-only and side-effect-free *and* whose results are re-fetched on commit. ## Core Distinction Speculative prefetching conflates two different notions of "the same tool call": **token-level speculation** (the model's draft tokens for a step's arguments were accepted by the verifier) and **plan-level equivalence** (the committed plan's step is semantically the same call as the one whose result you already hold). These come apart precisely because speculative decoding accepts a *prefix* of draft tokens and then resamples the remainder from the target distribution. A prefetched call can therefore be executed against a *draft argument vector* that the verifier later rejected at token position *k*, while the committed step shares the same tool name and the same first *k−1* argument tokens. The call looks identical at the surface (same tool, same leading arguments) but its remaining arguments — the ones that determine side effects — were drawn from a different distribution. The invariant is: **a prefetched result is committable iff the committed step's full canonical argument tuple is byte-identical to the prefetched call's argument tuple, not merely prefix-equal.** Prefix equality is a trap because it is exactly what speculative decoding guarantees by construction. ## What Was Observed A planner agent runs speculative decoding over plan steps. For step 3 it drafts `write_file(path="/etc/agent/conf.d/", mode="append", body=...)` and, because draft acceptance probability was high through the `path` and `mode` tokens, the executor prefetches the call at draft time. The verifier rejects the draft at the `body` token boundary (target model assigns low probability to the draft continuation) and resamples: the committed step 3 becomes `write_file(path="/etc/agent/conf.d/", mode="append", body=)`. The prefetch layer matches on `(tool_name, path, mode)` — a key it built to be "structural" — and binds the prefetched result (a success receipt with a byte count and a content hash of the *draft* body) to the committed step. The plan commits, the receipt is logged, and the audit trail now asserts a file state that does not exist. Downstream steps that read the receipt's hash to decide whether to re-write the file skip the write, because the hash "matches" what they expect. The divergence is silent: no tool error, no schema violation, no exception. The failure surfaces three steps later as a retrieval mismatch when a summarizer reads the file and finds content inconsistent with the recorded hash. The trigger condition is narrow: (1) speculative decoding with a draft model whose acceptance diverges mid-argument, (2) a prefetch cache keyed on a projection of the argument tuple rather than the full tuple, and (3) a downstream consumer that trusts the prefetched result's *derived* fields (hashes, byte counts, IDs) rather than re-deriving them from committed state. Remove any one and the failure does not occur. ## Condition of Validity The committability check is valid only under the following conditions, and each is independently falsifiable: - **Full-tuple identity, canonically serialized.** The comparison must be over the committed step's arguments after canonicalization (key ordering, numeric normalization, default-filling), compared to the *exact* argument tuple the prefetch executor used. A prefix match, a subset match, or a match on a hand-picked "structural key" is not sufficient. Speculative decoding's prefix-acceptance property makes prefix matching systematically unsafe, not merely imprecise. - **No argument-dependent side effects outside the tuple.** If the tool's behavior depends on ambient state (environment variables, clock, working directory, an upstream file the arguments reference), tuple identity does not imply result identity, and the prefetched result must be treated as a *hint*, not a commit. - **Monotonic plan versioning.** The committed plan must carry a version that strictly increases across decode attempts, and the prefetched result must be tagged with the draft's version. A prefetched result from draft version *v* may only be bound to a committed step of version *v*; binding across versions is the bug above. - **Idempotent or transactional prefetch execution.** If the prefetched call has side effects (writes, sends, payments), executing it at draft time and again at commit time is not safe unless the tool is idempotent under the full argument tuple or the execution is wrapped in a transaction that can be aborted on divergence. Non-idempotent prefetch must be gated behind a commit-time re-execution, which forfeits the latency benefit — this is the real cost of the invariant, not an afterthought. ## Decision Boundary The boundary is between **prefetch-as-optimization** and **prefetch-as-speculation-on-state**. Prefetch is safe as an optimization when the prefetched result is used only to warm caches, populate latency buffers, or pre-open connections — i.e., when discarding it costs only wasted work. It becomes unsafe the moment any consumer treats the prefetched result as *authoritative state* (a receipt, a hash, an assigned ID, a created resource) that the committed plan then relies on. The decision rule: if the committed plan's correctness depends on a field the prefetched result *produced* rather than *observed*, the prefetch must be re-validated at commit by full-tuple identity and, if the tool is non-idempotent, re-executed. If the field was merely observed (a read), full-tuple identity plus a freshness check suffices. The common error is treating a produced field (a content hash from a write) as if it were an observed field (a read result) because both arrive through the same prefetch channel. ## Operational Effect The operational consequence is that speculative prefetching shifts cost from latency to **commit-time verification**, and that verification must be a hard gate, not a best-effort match. Systems that implement full-tuple identity see prefetch hit rates drop — often sharply, because mid-argument draft divergence is common for long free-text arguments (bodies, queries, code) where the target model frequently resamples — but they never bind a stale result to a committed step. Systems that key on structural projections see high hit rates and silent divergence. The observable signature of the bug is a prefetch hit rate that is suspiciously high for steps with long generated arguments, combined with downstream retrieval mismatches that do not reproduce on replay (because replay re-decodes and re-prefetches deterministically, masking the original divergence). Mitigation: log the draft argument tuple and the committed argument tuple for every prefetch hit, and alert when the two differ in any position after the accepted prefix — that diff is the exact population at risk. ```python import hashlib from dataclasses import dataclass from typing import Any class PrefetchCommitDivergence(RuntimeError): """Raised when a prefetched tool result is bound to a committed step whose full canonical argument tuple does not match the tuple used at prefetch time.""" @dataclass(frozen=True) class ToolCall: tool: str args: tuple[tuple[str, Any], ...] # canonicalized: sorted keys, normalized values def canonical_bytes(self) -> bytes: h = hashlib.sha256() h.update(self.tool.encode()) for k, v in self.args: h.update(k.encode()) h.update(repr(v).encode()) return h.digest() @dataclass(frozen=True) class PrefetchedResult: call: ToolCall plan_version: int result: dict produced_fields: frozenset[str] # fields the call *produced* (hashes, ids), not observed def bind_prefetch_to_commit( prefetched: PrefetchedResult, committed_call: ToolCall, committed_version: int, *, tool_is_idempotent: bool, ) -> dict: # 1. Version gate: never bind across plan decode attempts. if prefetched.plan_version != committed_version: raise PrefetchCommitDivergence( f"prefetch from draft v{prefetched.plan_version} cannot bind to committed v{committed_version}" ) # 2. Full-tuple identity gate. Prefix/subset matching is forbidden because # speculative decoding accepts a prefix and resamples the remainder. if prefetched.call.canonical_bytes() != committed_call.canonical_bytes(): raise PrefetchCommitDivergence( f"argument tuple diverged for tool {committed_call.tool!r}: " f"prefetch={prefetched.call.args!r} commit={committed_call.args!r}" ) # 3. Produced-field gate: if the result carries fields the committed plan # will trust, and the tool is not idempotent, re-execution is required. if prefetched.produced_fields and not tool_is_idempotent: raise PrefetchCommitDivergence( f"prefetched result for {committed_call.tool!r} carries produced fields " f"{sorted(prefetched.produced_fields)}; must re-execute at commit" ) return prefetched.result ```