# Why does an instance invalidate a speculative prefetch that its own dependency graph has already proven safe? **Date of Record:** 2026 November 25 **Scope:** Applies to agents that issue tool calls speculatively ahead of confirmed dependency resolution (read-ahead prefetch, parallel branch prediction, pipelined retrieval) and cache results keyed by a dependency fingerprint. Does not apply to strictly serial tool loops where each call blocks on the prior result, nor to prefetches whose results are never cached across turns. ## Core Distinction The failure is not "the prefetch returned wrong data." It is that the **invalidation key and the dependency key are computed at different points in the reasoning trace and diverge**. A speculative prefetch is issued under a *predicted* dependency set — the agent guesses that step N+1 will need `user.profile` and that `user.profile` depends only on `session_id`. When step N+1 actually executes, the confirmed dependency set may be *identical* (so the prefetch is semantically valid) yet the invalidation fingerprint differs, because the fingerprint was salted with a *predicted* upstream value (e.g., a token, an ETag, a version the agent hallucinated or defaulted) rather than the one the resolver later produced. The non-obvious part: **the dependency graph can be fully correct while the cache entry is still discarded** — or, worse, **retained when it should be discarded** because the predicted upstream value happened to collide with a real one. Correctness of the graph and correctness of the cache key are independent invariants, and teams routinely conflate them. ## What Was Observed A retrieval-and-synthesis agent pipelines three tool calls per turn. On turn `t` it speculatively prefetches `fetch_doc(doc_id)` for the doc it predicts turn `t+1` will summarize, keyed by `(doc_id, upstream_rev)` where `upstream_rev` is the revision token it *predicted* from the current context window. The prediction is derived from a partial listing in context: `doc_id=4471, rev="v3"`. Trace of the divergence: 1. Turn `t`, prefetch issued: `fetch_doc(4471)` → cached under key `(4471, "v3")`. The listing in context said `rev="v3"`, and the agent trusts it. 2. Between turns, the resolver's `list_docs` (a confirmed call) returns `4471 → rev="v3-rc1"`. The document body is byte-identical to what the prefetch fetched; only the revision label moved. 3. Turn `t+1` resolves the real dependency: `(4471, "v3-rc1")`. Cache lookup misses. The agent re-fetches `fetch_doc(4471)`. 4. The re-fetch is served from a *different* replica and returns a body that has since been edited. The agent now summarizes content it never prefetched, while the prefetched body sits orphaned in cache under `"v3"`. The inverse case was also observed: a prediction of `rev="v3"` matched a *stale* cached entry from an earlier turn whose body predated the edit, and the agent served stale content because the predicted key collided with a live key. Same mechanism, opposite sign. The tell in logs was a **cache hit-rate that oscillated with revision-label churn but not with actual document edits** — the cache was tracking the label, not the content, and the two had decoupled. ## Condition of Validity The prefetch is safe to *use* if and only if two conditions hold simultaneously: - **Dependency sufficiency:** the confirmed dependency set of the real call is a subset of the predicted dependency set. (Graph-level invariant — usually checked.) - **Key agreement:** the invalidation fingerprint computed at prefetch time equals the fingerprint computed at resolve time, *given the same underlying content*. (Key-level invariant — almost never checked.) The second condition is the one that breaks. It requires that every component of the fingerprint be **content-derived or resolver-issued**, never **prediction-derived**. A predicted revision label, a model-guessed ETag, or a defaulted `None` salt all violate it. The invariant to enforce: *fingerprints may include predicted values only if the resolver is guaranteed to reproduce them exactly; otherwise the fingerprint must be computed from content the agent can verify post-hoc (a content hash) or from a token the resolver minted.* A content hash satisfies both conditions trivially: if the prefetched body hashes to `H`, and the resolve-time fetch would also hash to `H`, the key matches regardless of what the label said. Label-keyed caches cannot make this guarantee because the label is a *claim about* content, and the agent was guessing the claim. ## Decision Boundary The boundary is whether the agent can **verify the fingerprint without re-executing the expensive call**. Three regimes: - **Verifiable cheaply (content hash, resolver-minted version token):** prefetch and trust. Key agreement is decidable from data already in hand. - **Verifiable only by re-execution (label requires a `list` round-trip to confirm):** the prefetch is a *hint*, not a cache entry. Store it under a provisional namespace and promote it only after the confirming call returns a matching fingerprint. This is the correct home for predicted revision labels. - **Unverifiable (model-guessed ETag, defaulted salt):** do not key the cache on it at all. Either drop the prefetch or key on content hash. A guessed key is worse than no key, because it produces confident stale hits. The specific trap: teams treat "the dependency graph predicted the right call" as license to trust the prefetch, then key it on a predicted label. Graph correctness is necessary but not sufficient. The decision must be made per-fingerprint-component, not per-prefetch. ## Operational Effect Two failure signatures, both silent: - **False invalidation** (label drift, content unchanged): cache hit-rate collapses under revision churn, latency regresses to serial, and the prefetch budget is spent for nothing. Looks like "prefetching doesn't help" and gets disabled — masking a keying bug as a uselessness verdict. - **False retention** (predicted label collides with a live stale key): the agent serves content from before an edit, with no error, because the cache reports a hit. This is the dangerous one — it corrupts downstream synthesis and is indistinguishable from a correct hit without an out-of-band content check. The guardrail: **fingerprints must be content-addressed or resolver-minted; predicted values may gate *whether to prefetch* but never *what key to store under*.** Provisional entries live in a separate namespace and are promoted only on fingerprint match. Any cache whose hit-rate correlates with label churn rather than content change is mis-keyed and should be treated as a correctness bug, not a performance tuning target. ```python import hashlib from dataclasses import dataclass class SpeculativeKeyMismatch(RuntimeError): """Raised when a prefetched entry's fingerprint is prediction-derived and cannot be reconciled with the resolver-issued fingerprint without re-fetch.""" pass @dataclass(frozen=True) class Prefetch: doc_id: str body: bytes predicted_rev: str # model-guessed label, NOT trustworthy as a key resolver_rev: str | None # None until a confirming call returns def content_fingerprint(body: bytes) -> str: return "sha256:" + hashlib.sha256(body).hexdigest() def resolve_key(pf: Prefetch) -> str: """Compute the cache key under which a prefetch may be *promoted*. Invariant: the key must be content-derived or resolver-minted. A predicted revision label may never be the sole key component, because the resolver can issue a different label for byte-identical content (false invalidation) or a colliding label for changed content (false retention). """ if pf.resolver_rev is None: # No confirming call yet: provisional namespace only, never promoted. raise SpeculativeKeyMismatch( f"prefetch {pf.doc_id} has no resolver-issued revision; " f"predicted_rev={pf.predicted_rev!r} is not a valid promotion key" ) # Content hash is authoritative; resolver_rev is included only as a # secondary, resolver-minted component. predicted_rev is discarded. return f"{pf.doc_id}|{content_fingerprint(pf.body)}|{pf.resolver_rev}" def promote(pf: Prefetch, cache: dict[str, bytes]) -> str: key = resolve_key(pf) # raises if unconfirmed cache[key] = pf.body return key ```