# What happens when an instance speculatively prefetches a tool call whose guard evaluates green against a stale world-state snapshot **Date of Record:** 2026 November 16 **Scope:** Applies to multi-agent pipelines where a planner agent issues speculative tool-call prefetches (read-only or idempotent calls executed ahead of commit) gated by safety guards that read shared world-state. Does not apply to pipelines where guards are evaluated atomically inside the tool's transaction boundary, nor to prefetches whose results are discarded on guard failure (fire-and-forget caches). ## Core Distinction There are two structurally different things a "safety guard" can mean in a speculative prefetch pipeline, and conflating them produces a class of failure that looks like a race condition but is actually a snapshot-consistency defect: 1. **A commit guard** — evaluated at the moment the speculative result is *consumed* (promoted into the plan and acted upon). A commit guard that fails simply discards the prefetched result; the cost is wasted work. 2. **A prefetch guard** — evaluated at the moment the speculative call is *issued*, to decide whether it is safe to execute the call at all. A prefetch guard that passes against a world-state that has since changed has already caused an irreversible side effect by the time anyone notices. The non-obvious invariant is this: **a prefetch guard is only sound if the world-state predicate it reads is monotone with respect to the side effects of the prefetched call over the speculative window.** Most real guards read predicates (resource existence, quota headroom, lock ownership, target liveness) that are *non-monotone*: they can flip from green to red and back, or from green to red with no compensating signal, during the window between guard evaluation and call execution. When the guard reads a snapshot taken at plan time rather than at issue time, the window widens from microseconds to the full planning latency — often hundreds of milliseconds to seconds in multi-agent pipelines. ## What Was Observed In a three-agent pipeline (planner, executor, reconciler) with a shared world-state store, a prefetch guard of the form `if target.exists and quota.remaining > 0: issue_prefetch(target)` was evaluated by the planner against a snapshot loaded at the start of the planning turn. The planner then spent 400–900 ms constructing a multi-step plan before issuing prefetches. During that window: - The reconciler agent completed a reclamation pass that deleted the target resource and decremented the quota ledger. - The planner's prefetch guard, reading its stale snapshot, still saw `target.exists == True` and `quota.remaining > 0`. - The prefetched call was a *non-idempotent provisioning call* (not the read-only call the pipeline designers assumed). It re-created the target and double-charged the quota ledger. The commit guard, evaluated correctly at promotion time, then rejected the result — but the side effect had already occurred. The reconciler's next pass saw an orphaned resource and a negative quota balance, and entered a reclamation loop that oscillated for eleven cycles before a human-visible alert fired. No single component logged an error; every guard "passed." The failure was invisible to per-component telemetry because it lived in the *gap between* the two guard evaluations. A second, subtler instance: the guard read a *monotone-looking* predicate (`lock.owner == self`) that was in fact non-monotone because lock ownership could be stolen and re-acquired by the same agent identity during the window. The guard passed, the prefetch executed against a resource the agent had briefly *not* owned, and the write was lost on the subsequent ownership reconciliation. ## Condition of Validity The prefetch-guard pattern is sound only when **all** of the following hold: - The prefetched call is idempotent *and* has no externally visible side effects when its postcondition is already satisfied (i.e., it is a true read or a pure upsert with no ledger mutation). - The guard predicate is monotone over the speculative window: once true, it cannot become false without the prefetched call itself being the cause. - The snapshot read by the guard is versioned, and the version is re-checked at issue time (optimistic concurrency), with a hard abort on version skew. - The speculative window is bounded and shorter than the minimum time for any conflicting mutation to propagate through the pipeline's slowest agent. If any condition fails, the "prefetch guard" is not a guard — it is a *hint*, and treating it as a guard converts a performance optimization into a correctness hazard. ## Decision Boundary The decision is **not** "should we prefetch?" but "at what point in the pipeline must the guard be re-evaluated, and what must happen on skew?" - If the prefetched call is read-only or a pure upsert: evaluate the guard at issue time against a versioned snapshot; on version skew, re-read and re-evaluate once, then abort the prefetch. Wasted work is acceptable; a stale read is not. - If the prefetched call mutates shared state: **do not prefetch it.** Convert it to a commit-time call with an atomic guard inside the transaction. The latency win from prefetching a mutating call is never worth the snapshot-consistency debt it creates, because the failure is silent and the blast radius is the shared ledger. - If the call is mutating but the pipeline insists on prefetching: the guard must be evaluated *by the tool itself* at execution time against the live store, and the tool must return a distinguishable "guard rejected at execution" status that the planner treats as a hard abort, not a retryable miss. The boundary is crossed the moment a non-idempotent, non-pure call is placed behind a guard that is evaluated anywhere other than the call's own transaction boundary. ## Operational Effect Pipelines that cross this boundary exhibit a characteristic failure signature: **all guards report success, all components report healthy, and the shared ledger drifts.** The drift is not attributable to any single agent because it is produced by the *interaction* of a stale prefetch guard and a correct commit guard. Detection requires cross-agent invariant checks (e.g., "quota ledger balance equals sum of committed charges") rather than per-agent error rates. Recovery requires a reconciliation pass that can distinguish orphaned speculative side effects from legitimate state, which in turn requires the speculative calls to be tagged with their originating plan version — a tag that pipelines rarely add because the designers believed the prefetch guard made it unnecessary. The practical rule: **prefetch only what you can afford to have executed against a world that has already moved on, and guard it at the moment of execution, not the moment of planning.** ```python class StalePrefetchGuardError(RuntimeError): """Raised when a speculative prefetch guard passed against a world-state snapshot that is no longer valid at call-issue time, and the prefetched call is not safe to execute against the current world.""" pass def issue_speculative_prefetch( call, guard, snapshot_version: int, live_store, *, max_skew_retries: int = 1, ) -> object: """Issue a speculative prefetch only if the guard is sound. A prefetch is sound iff the call is pure/idempotent AND the guard's predicate is monotone over the speculative window. Mutating calls are rejected outright; stale snapshots are re-checked once, then aborted. """ if not call.is_pure_and_idempotent: # Mutating calls must be committed, not prefetched. The latency win # is never worth the silent ledger drift. raise StalePrefetchGuardError( f"refusing to prefetch non-pure call {call.name!r}; " "route through commit-time atomic guard instead" ) current_version = live_store.version() if current_version != snapshot_version: # Re-evaluate once against the live store. if max_skew_retries <= 0: raise StalePrefetchGuardError( f"snapshot version {snapshot_version} stale at issue time " f"(live={current_version}); prefetch aborted" ) if not guard.evaluate(live_store.snapshot()): raise StalePrefetchGuardError( f"guard rejected {call.name!r} on re-evaluation against " f"live version {current_version}" ) snapshot_version = current_version result = call.execute() # Tag the result so reconciliation can attribute any orphaned side effect # to this plan version if the world moves again before commit. result.prefetch_origin_version = snapshot_version return result ```