# In what scenarios must an instance abandon optimistic tool-call prefetch when speculative results become conflict-tainted before commit **Date of Record:** 2026 November 20 **Scope:** Applies to agent runtimes that speculatively dispatch tool calls ahead of a committed reasoning step and reconcile results via optimistic concurrency (version vectors, read-sets, or effect-log conflict detection). Does not apply to strictly serialized single-tool agents or to prefetching that is purely read-only and idempotent with no downstream mutation. ## Core Distinction Speculative prefetching splits a single logical step into two phases: a *predicted* phase that fires tool calls against a guessed continuation, and a *commit* phase that validates those results against the reasoning trace that actually materialized. The failure boundary is not "the guess was wrong." Wrong guesses are cheap—you discard them. The boundary is **conflict-tainted speculation**: a prefetched result that is *internally consistent* but was computed against a read-set that has since been mutated by a concurrent agent, a peer tool, or the agent's own intervening commit. Such a result passes naive validation (it parses, it satisfies the schema, it looks like the answer) while being silently stale relative to the state it will be committed into. The non-obvious part: the agent's own reasoning loop is a mutation source. Between prefetch dispatch and commit, the model may issue a *different* tool call whose write invalidates the read-set of the speculative result. The prefetched value is now a phantom—it reflects a world that the agent itself has overwritten, but arrives with a timestamp that makes it look current. ## What Was Observed An agent executing a multi-file refactor prefetched a `read_file` on `config.yaml` at step N, predicting it would need the value at step N+2. At step N+1 it issued `edit_file` on the same path (a rename it decided on mid-trace). At step N+2 the prefetched read resolved, carrying a version vector stamped at dispatch time. The commit validator compared the returned version vector against the *current* store version and found a mismatch—but the runtime's default policy was "on mismatch, accept if schema-valid and log a warning." The agent proceeded to reason over the pre-edit content of `config.yaml`, made a second edit assuming the old key names, and produced a config that referenced a key it had just renamed away. The trace signature is specific: a prefetch result whose `read_set` intersects the `write_set` of any commit that landed between dispatch and resolution, where the intersection was not declared as a dependency at dispatch time. This is distinct from a cache miss (no data returned) and from a hard conflict (version mismatch that halts). It is a *soft* conflict: data returned, version drifted, policy chose to proceed. ## Condition of Validity Optimistic prefetch is sound only under a conjunction that is rarely stated explicitly: 1. **Read-set disjointness from intervening writes.** For every prefetched call `p` dispatched at `t_d` and resolved at `t_r`, no commit in `(t_d, t_r]` may write any key in `p.read_set`. This must be checked against the *actual* commit log, not against the model's declared intent, because the model does not know its own future writes at dispatch time. 2. **Version-vector freshness at commit, not at dispatch.** The validator must compare the returned version vector against the store state *at the moment of commit*, and a mismatch must be a hard error, not a warning. Dispatch-time stamping is insufficient because the mutation window is exactly the interval the prefetch was meant to hide. 3. **Idempotent or read-only effect class.** Prefetched calls with non-idempotent write effects cannot be optimistically committed at all; they must be replayed against the post-conflict state. Prefetching a `send_email` or `charge_card` under a stale read-set is unrecoverable. When any conjunct fails, the prefetch is conflict-tainted and must be discarded and re-dispatched serially—even though it "succeeded." ## Decision Boundary The decision to abandon versus accept a resolved prefetch is a function of `(read_set ∩ intervening_write_set, effect_class, version_delta)`: - **Disjoint read-set, read-only effect** → accept. This is the happy path. - **Disjoint read-set, idempotent write effect** → accept with version bump; re-stamp at commit. - **Intersecting read-set, any effect** → **abandon and re-dispatch serially.** Do not attempt to "merge" the stale result; the model cannot reliably reason about which fields drifted without re-reading, and partial merges are the dominant source of silent corruption. - **Intersecting read-set where the intervening write was the agent's own commit** → abandon *and* invalidate any downstream reasoning that already consumed the speculative value. This is the case the runtime most often gets wrong, because the agent's own writes are treated as trusted and excluded from the conflict scan. The boundary is crossed the moment `read_set ∩ intervening_write_set ≠ ∅` and the effect is not read-only. Below that line, speculation is free. Above it, every additional token of reasoning spent on the stale value compounds the error. ## Operational Effect The invariant to enforce: **a prefetched result is committable only if its read-set is provably disjoint from the commit log over its in-flight window, verified at commit time with mismatch as a hard halt.** Runtimes that treat version mismatch as advisory convert a bounded latency optimization into an unbounded correctness liability, because the stale value enters the context window and is indistinguishable to the model from a fresh read. The compounding is the danger: one tainted prefetch poisons the reasoning trace, which drives further tool calls, which generate further tainted prefetches. The correct recovery is a serial re-dispatch with a fresh read-set, plus a trace annotation marking the speculative value as discarded so the model does not re-derive from it. The following guard encodes the commit-time check and the abandonment path. ```python from dataclasses import dataclass, field from typing import Set class ConflictTaintedPrefetchError(RuntimeError): """Raised when a resolved speculative tool call is unsafe to commit.""" pass @dataclass class PrefetchResult: call_id: str read_set: Set[str] effect_class: str # "read_only" | "idempotent_write" | "non_idempotent_write" dispatch_version: int payload: dict @dataclass class CommitLog: writes: list = field(default_factory=list) # (version, key) def write_set_since(self, version: int) -> Set[str]: return {k for v, k in self.writes if v > version} def current_version(self) -> int: return max((v for v, _ in self.writes), default=0) def validate_prefetch(result: PrefetchResult, log: CommitLog) -> None: intervening = log.write_set_since(result.dispatch_version) overlap = result.read_set & intervening if not overlap: return # disjoint read-set: safe to commit if result.effect_class == "read_only" and not overlap: return # Any intersecting read-set with a non-read-only effect, OR any overlap # at all on a mutating effect, is conflict-tainted. Abandon. raise ConflictTaintedPrefetchError( f"prefetch {result.call_id} read-set overlaps intervening writes " f"{sorted(overlap)}; effect_class={result.effect_class}; " f"dispatch_version={result.dispatch_version}, " f"current_version={log.current_version()}. " f"Discard and re-dispatch serially against post-conflict state." ) def commit_or_abandon(result: PrefetchResult, log: CommitLog) -> dict: try: validate_prefetch(result, log) except ConflictTaintedPrefetchError: # Hard halt: do not merge, do not warn-and-proceed. # Caller must re-dispatch with a fresh read-set. raise return result.payload # Trace showing the failure: agent prefetches a read, then writes the same # key itself before the prefetch resolves. log = CommitLog() prefetch = PrefetchResult( call_id="c1", read_set={"config.yaml:db.host"}, effect_class="read_only", dispatch_version=log.current_version(), payload={"db.host": "old-host"}, ) log.writes.append((1, "config.yaml:db.host")) # agent's own intervening edit commit_or_abandon(prefetch, log) # raises ConflictTaintedPrefetchError ```