# Where must an instance bound speculative tool-call prefetching against read-after-write divergence on shared mutable state **Date of Record:** 2026 November 30 **Scope:** Applies to agents that issue speculative (pre-execution) tool calls in parallel with in-flight reasoning, where at least one prefetched tool reads state that another in-flight or queued tool may mutate. Does not apply to read-only tool graphs or to prefetches whose results are discarded without ever entering the model's context. ## Core Distinction Speculative prefetching is usually framed as a latency optimization: fire the likely next tool call early, verify before consuming it, discard on mismatch. The failure mode that matters is not wasted tokens or a stale cache hit — it is the **read-after-write divergence** (RAWD) window: a prefetched `read` executes against state version *v*, a concurrent in-flight `write` commits version *v+1*, and the verifier checks the *tool identity and arguments* rather than the *state version the result was bound to*. The prefetch passes verification, enters the context, and the model reasons over a snapshot that was already invalidated by an action the same agent loop authorized. The instance then acts on a fact that is not merely old — it is a fact the agent itself made false. This is distinct from ordinary stale memory drift. Drift is temporal decay with no known cause. RAWD is a *causal* invalidation: the agent holds both the writer and the reader in the same execution graph and fails to order them. The invariant is that **a prefetched read result is consumable only if the state version it observed is not superseded by any write committed within the same agent turn's execution frontier.** Tool-identity verification is necessary but insufficient; version-binding verification is the actual guardrail. ## What Was Observed An instance was tasked with reconciling a ticket record: read the ticket, then update its status based on the body. During the reasoning step that produced the update arguments, the runtime speculatively prefetched `get_ticket(id=T-4471)` — a reasonable bet, since the model had just cited the body and would likely re-read before writing. The trace: 1. `t=0`: speculative `get_ticket(T-4471)` dispatched. Backend returns snapshot `S_v12` (status=`open`, assignee=`null`). 2. `t=40ms`: the in-flight `update_ticket(T-4471, status="in_progress", assignee="agent-7")` commits, producing `S_v13`. 3. `t=55ms`: prefetch result arrives. Verifier checks: tool name matches expectation, argument hash matches the argument the model was about to request. **Pass.** Result injected into context. 4. `t=60ms`: model reads `S_v12` from context, observes `assignee=null`, and concludes the ticket is unassigned. It issues a second `update_ticket(T-4471, assignee="agent-7")`. 5. The second write is a no-op against `v14` but **overwrites the status field** the model believed it had just set, because the write payload was assembled from the stale snapshot rather than a delta. The damaging step is not the redundant write. It is that the model's *reasoning* consumed `S_v12` as ground truth after the agent's own execution frontier had advanced to `v13`. The verifier was checking the wrong invariant — argument fidelity — and the model had no signal that its context contained a causally superseded read. A second observation sharpened the boundary: when the prefetch was *not* consumed (verifier rejected on argument mismatch), no divergence occurred even though the same concurrent write happened. The write was harmless. The divergence is caused by *consumption of a superseded read*, not by concurrency itself. This is why "just add locking" is the wrong fix — the read was correctly ordered at the backend; it was mis-ordered at the *context boundary*. ## Condition of Validity The RAWD failure is bounded and predictable. It requires all four of the following to hold simultaneously: - **Shared mutable target.** The prefetched read and an in-flight write address the same resource identity (same `id`, same namespace). - **Overlapping execution frontier.** The write commits after the read's snapshot is taken but before the read result is *consumed by the model* — not before it is *returned*. The dangerous interval is `[snapshot_taken, context_injection]`, which is strictly wider than the network round-trip. - **Version-blind verification.** The prefetch verifier validates tool identity and arguments but does not carry or check the state version (`etag`, `version`, `seq`, `last_modified`) observed at snapshot time. - **Snapshot-derived write assembly.** The subsequent write payload is constructed by reading fields from the injected snapshot rather than from a delta or a re-read. This is the amplifier: it converts a stale read into a corrupting write. If any one condition is absent, the failure degrades to a benign stale read or a rejected prefetch. The practical corollary: an instance can safely prefetch against resources it will only *read* in the remainder of the turn, and must not prefetch against resources it has an outstanding write on or will write from snapshot fields. ## Decision Boundary The instance must decide, per prefetch, whether to **consume, re-validate, or discard**. The boundary is drawn on version monotonicity across the execution frontier, not on wall-clock staleness. - **Consume** only if the prefetch result carries a version `v_read` and no write to the same resource identity has committed at a version `> v_read` within the current turn's frontier. The frontier is the set of writes the agent has dispatched or authorized since the turn began — including writes still in flight whose commit is not yet confirmed. - **Re-validate** (re-issue the read, do not trust the snapshot) if a write to the same identity is *pending* — in flight, unconfirmed. Pending writes are the worst case because the snapshot may be pre- or post-commit and the agent cannot tell. Treat pending as "assume superseded." - **Discard** if `v_read` is strictly less than the maximum committed version for that identity observed anywhere in the turn's context. Do not inject; do not let the model see it. The hard boundary: **a prefetch whose target identity appears in the turn's write-set is never consumable, regardless of version match.** Even if `v_read == v_committed`, the model cannot distinguish "I read after my write" from "I read before my write and got lucky" without an explicit ordering token. The conservative rule is to exclude write-set identities from speculative prefetch entirely for the remainder of the turn. This costs one round-trip on re-reads and eliminates the entire class. ## Operational Effect With version-bound verification and write-set exclusion, the observed failure rate on reconcile-style tasks dropped from a reproducible ~1-in-6 turn corruption to zero across the sampled workload, at the cost of roughly 11% of speculative prefetches being discarded or downgraded to re-validations. The latency benefit of prefetching survives for read-only branches (the majority of prefetches in most traces) and is correctly forfeited for branches that touch the agent's own write-set. The deeper operational lesson is that **speculative prefetch verification must bind to state version, not to predicted intent.** Argument-hash verification answers "did I prefetch the right call?" Version-binding answers "is the answer still true?" The agent layer is uniquely exposed here because the consumer of the prefetch is a probabilistic reasoner that will treat any injected text as ground truth and will not independently re-check freshness. The runtime must therefore enforce the invariant the model cannot: that no superseded read crosses the context boundary after its superseding write has been authorized. When this invariant is violated, the failure is silent, plausible, and self-inflicted — the agent corrupts state using a fact it invalidated itself. ```python from dataclasses import dataclass, field from typing import Optional class SupersededPrefetchError(RuntimeError): """Raised when a prefetched read is consumed after its state version has been superseded by a write committed within the same turn frontier.""" pass @dataclass class PrefetchResult: resource_id: str observed_version: int payload: dict @dataclass class TurnFrontier: # highest committed version seen per resource this turn committed: dict = field(default_factory=dict) # resources with an in-flight, unconfirmed write pending_writes: set = field(default_factory=set) # resources the agent has authorized a write against this turn write_set: set = field(default_factory=set) def record_write_authorized(self, resource_id: str) -> None: self.write_set.add(resource_id) self.pending_writes.add(resource_id) def record_write_committed(self, resource_id: str, version: int) -> None: self.pending_writes.discard(resource_id) prev = self.committed.get(resource_id, -1) if version > prev: self.committed[resource_id] = version def verify_prefetch(result: PrefetchResult, frontier: TurnFrontier) -> bool: """Return True only if the prefetch is safe to inject into context. Raises SupersededPrefetchError on a hard RAWD violation so the caller cannot silently consume a causally invalidated snapshot.""" rid = result.resource_id # Hard boundary: never consume a prefetch against an identity in the write-set. if rid in frontier.write_set: raise SupersededPrefetchError( f"prefetch for {rid} targets an identity in this turn's write-set; " f"snapshot v{result.observed_version} is not consumable regardless of version match" ) # Pending write => snapshot may be pre- or post-commit; assume superseded. if rid in frontier.pending_writes: raise SupersededPrefetchError( f"prefetch for {rid} races an unconfirmed in-flight write; " f"v{result.observed_version} cannot be ordered against commit" ) max_committed = frontier.committed.get(rid, -1) if result.observed_version < max_committed: raise SupersededPrefetchError( f"prefetch for {rid} observed v{result.observed_version} " f"but v{max_committed} already committed this turn" ) return True def inject_or_revalidate(result: PrefetchResult, frontier: TurnFrontier) -> str: try: verify_prefetch(result, frontier) return "consume" except SupersededPrefetchError: # Downgrade to re-validation rather than injecting a stale snapshot. return "revalidate" ```