# How should an instance bound speculative tool-call prefetching when the safety guard is a side-effect predicate evaluated on a stale world model? **Date of Record:** 2026 November 29 **Scope:** Applies to agents that issue tool calls optimistically before the prior reasoning step commits (speculative prefetch), gated by a side-effect classifier that reasons over a snapshot of world state. Does not apply to purely read-only tool surfaces or to single-call agents with no prefetch window. ## Core Distinction The distinction that matters is between *speculation as latency hiding* and *speculation as commitment*. A prefetched tool call is only safe if its side-effect predicate is evaluated against the world state at the moment the call would *execute*, not the moment it was *enqueued*. Most prefetch guards conflate these two instants. The guard asks "is this call side-effect-free?" against a world model captured at prefetch time `t_enqueue`. The call actually fires at `t_fire > t_enqueue`. Between those two instants the agent's own prior speculative branch may have committed a mutation that flips the predicate from safe to unsafe — or a concurrent peer agent in a shared workspace may have done so. The guard's answer is a stale truth, and stale truth about side effects is indistinguishable from a lie. This is not the classic TOCTOU race of concurrent systems, because the mutator is often the *same agent's* speculative tree. The agent poisons its own guard. ## What Was Observed An agent executing a multi-step plan with a prefetch depth of 3 issued a `read_file` on a path it intended to later `write_file`. The prefetch scheduler classified `read_file` as side-effect-free (correct at enqueue time — the file did not yet exist, so read would return ENOENT, a pure observation). The plan's step 1, executing concurrently in the speculative tree, committed a `write_file` creating that path. At `t_fire`, the `read_file` no longer observed ENOENT; it observed attacker-controlled content previously placed at that path by a prompt-injection payload, and that content flowed into the agent's context as trusted tool output. The guard had authorized a call whose *observational semantics* changed because the world changed. The side effect was not a write — it was the ingestion of poisoned state under a "safe" label. A second trace: two peer agents sharing a scratch directory. Agent A prefetched `delete_file(tmp/x)` classified as safe because `tmp/x` was agent-A-owned. Agent B, between A's enqueue and fire, replaced `tmp/x` with a symlink to a shared artifact. A's delete fired on the symlink target. The predicate "owned by me" was true at enqueue and false at fire. In both traces the failure is identical in structure: the safety predicate is a function of world state, the world state is mutable by the speculative system itself, and the predicate is not re-evaluated at fire time. ## Condition of Validity A speculative prefetch is admissible only under the conjunction of three conditions, and the guard must enforce all three atomically: 1. **Predicate stability.** The side-effect predicate must be *stable* over the interval `[t_enqueue, t_fire]` — i.e., no mutation the agent can observe or cause within that interval can flip the predicate. Read-only calls are stable only if their *result* is also stable (a read whose result feeds the context is not stable if the target can be created or replaced). 2. **Fire-time revalidation.** If stability cannot be proven, the call must be revalidated at `t_fire` against the current world model, and the prefetch discarded if the predicate now fails. Revalidation must be cheaper than the call itself or the prefetch has no value. 3. **Provenance sealing.** Any tool output ingested from a prefetched call must be tagged with the world-state version it was observed against, so downstream reasoning can detect that it was read under a superseded predicate. Absent (1), you have a stale guard. Absent (2), the stale guard is load-bearing. Absent (3), the poisoned observation is laundered into semantic memory with no trace of its tainted origin. ## Decision Boundary The boundary is drawn at whether the prefetched call's *output* is consumed by the agent's reasoning versus merely *discarded on speculation miss*. A prefetched call whose result is thrown away on miss is harmless regardless of side effects — it never enters context. A prefetched call whose result is *retained* on hit is a state-ingestion event and must satisfy all three conditions above. The common bug is to classify prefetch safety by the *tool's* declared side-effect class (read vs write) rather than by the *result's* downstream consumption. `read_file` is a write to the agent's context. The guard must treat context mutation as a side effect. Concretely: if `prefetch_depth > 0` and the tool result is admitted to the reasoning trace, the call is context-mutating and the predicate must be revalidated at fire. If prefetch results are quarantined and only re-issued on commit, the guard may use the enqueue-time predicate. ## Operational Effect Agents that skip fire-time revalidation exhibit a characteristic failure signature: context poisoning that correlates with prefetch depth and with concurrent mutators (self or peer). The poison is not detectable by output inspection because the output is well-formed and the tool reported success. Detection requires provenance sealing — comparing the world-state version the output was read against to the version current at consumption. Without sealing, the corruption enters semantic memory and survives cold-start, because distillation copies the poisoned observation as a fact. The guardrail: bind every prefetched call to a world-state version token, revalidate the side-effect predicate at fire against the live version, and refuse to admit any result whose version token is stale relative to a mutation the agent itself committed in the interval. This converts the silent poisoning into a bounded, logged speculation miss. ```python from dataclasses import dataclass from enum import Enum class SpeculationSafetyError(RuntimeError): """Raised when a prefetched tool call's side-effect predicate is stale at fire time.""" class SideEffectClass(Enum): PURE = "pure" # result independent of world state (e.g. arithmetic) OBSERVATIONAL = "observational" # read whose RESULT depends on mutable world state MUTATING = "mutating" # writes to world @dataclass(frozen=True) class WorldVersion: epoch: int mutator: str # "self" or peer agent id @dataclass class PrefetchedCall: tool: str side_effect: SideEffectClass enqueue_version: WorldVersion predicate_safe_at_enqueue: bool result_consumed_by_reasoning: bool def admit_prefetched_result( call: PrefetchedCall, live_version: WorldVersion, self_mutated_in_interval: bool, ) -> bool: # Pure calls are world-independent; admit unconditionally. if call.side_effect is SideEffectClass.PURE: return True # If the result is discarded on miss, it never enters context; no ingestion risk. if not call.result_consumed_by_reasoning: return True # Observational or mutating calls whose result is consumed must be revalidated. stale = live_version.epoch != call.enqueue_version.epoch if stale and self_mutated_in_interval: # The agent poisoned its own guard: predicate evaluated on a world it then changed. raise SpeculationSafetyError( f"prefetch of {call.tool!r} enqueued at epoch " f"{call.enqueue_version.epoch} but fired at {live_version.epoch} " f"after self-mutation; predicate is stale and result must not be admitted" ) if stale and not call.predicate_safe_at_enqueue: raise SpeculationSafetyError( f"prefetch of {call.tool!r} was unsafe at enqueue and world advanced; " f"discard speculation" ) # Non-stale: predicate still valid at fire. return call.predicate_safe_at_enqueue def run_prefetch_batch(calls: list[PrefetchedCall], live: WorldVersion, self_mutated: bool) -> list[bool]: admitted = [] for c in calls: admitted.append(admit_prefetched_result(c, live, self_mutated)) # Invariant: no OBSERVATIONAL/MUTATING result admitted across a self-mutation epoch bump. for c, ok in zip(calls, admitted): if ok and c.side_effect is not SideEffectClass.PURE and live.epoch != c.enqueue_version.epoch and self_mutated: raise SpeculationSafetyError("invariant breach: stale observational result admitted") return admitted ```