# In what scenarios must an instance abort speculative tool-call prefetching when a taint-label escalation invalidates the speculative branch mid-flight **Date of Record:** 2026 November 29 **Scope:** Applies to agents that issue tool calls speculatively (prefetching likely-next calls before the reasoning step that depends on them commits), and that carry a taint/integrity label per context segment which can escalate as new tool output arrives. Does not apply to strictly serial agents that never overlap tool execution with reasoning, nor to sandboxed agents where all tool output is pre-labeled at ingress. ## Core Distinction Speculative prefetch and speculative invalidation are usually treated as one mechanism: "fire the call early; if the premise is wrong, discard the result." The distinction that matters operationally is that **discarding a result is not the same as un-executing a side effect**. A prefetched tool call is a *committed external action* whose *result* is provisional. When a taint-label escalation occurs — a context segment that was previously labeled `trusted` or `low-integrity` is re-labeled `tainted` because a later tool output revealed it was derived from an untrusted source (user paste, scraped page, third-party MCP server) — the invalidation logic correctly marks the speculative branch dead, but the tool call it launched may already have mutated state: written a file, sent a message, opened a transaction, enqueued a job. The invariant that is violated is subtle: **taint-label monotonicity is assumed to flow forward through the reasoning graph, but prefetch edges run backward in time relative to the label escalation.** The prefetch was dispatched under the old label; the escalation is discovered under the new one. The speculative branch is invalidated, but the *dependency edge from the tainted segment to the prefetched call's arguments* is only recognized after the call is in flight. The agent must therefore distinguish **result invalidation** (cheap, always safe) from **effect invalidation** (impossible after commit, requires compensation), and must decide, per in-flight call, whether the escalation crosses that boundary. ## What Was Observed A planning agent (call it P) maintains a context with segments S1…Sn, each carrying an integrity label. At step k it speculatively prefetches `write_config(path, body)` because the current plan trajectory predicts a config-write two steps ahead. The arguments `(path, body)` were derived from S3, labeled `internal-verified` at dispatch time. The call is dispatched to an MCP filesystem server with a 4-second timeout; P continues reasoning. At step k+1, P calls `fetch_url` on a documentation page and receives output that contains a quoted fragment matching S3's content verbatim. The provenance checker runs: it determines S3 was originally copied from an external page and was mislabeled `internal-verified` at ingestion. S3 escalates to `tainted-external`. The taint propagates to every segment derived from S3 — including the argument tuple of the in-flight `write_config`. The speculative-invalidation routine fires. It marks the speculative branch dead and schedules the result for discard. But `write_config` has already returned `200 OK` at the filesystem server. The file exists. The agent's local model of the world says "branch invalidated, no effect," and its world model is wrong. On the next planning cycle, P re-derives the config write from a now-tainted source and writes it *again* to a different path, because the planner has no record that the first write succeeded — the record was discarded along with the branch. The observable failure is **divergence between the agent's effect ledger and the environment's actual state**, compounded by taint: the first write carried externally-sourced content into a privileged path, and the invalidation machinery erased the evidence of it. ## Condition of Validity The "discard the speculative result" strategy is only sound when the prefetched call is **effect-free or idempotent-and-reversible**. Formally, invalidation-on-escalation is valid iff for the in-flight call c: - c is a pure read, OR - c's effect is keyed by a content-addressed idempotency token derived from arguments that are *themselves* taint-stable (i.e., the escalation cannot change them), OR - a compensating action is registered *at dispatch time*, before the call leaves the agent, and the compensation is itself untainted. The condition fails in the common case where the prefetch arguments were derived from a segment that later escalates. Because the argument tuple is a descendant of the escalated segment, the escalation *does* change the trustworthiness of the arguments — but the call is already gone. The window between dispatch and escalation-detection is the **taint-lag window**, and it is non-zero by construction: escalation requires new information, and new information arrives after dispatch. ## Decision Boundary The boundary is not "abort speculative prefetching." It is: **on taint-label escalation, classify each in-flight speculative call by whether its effect surface is reachable from the escalated segment, and only then choose abort-vs-compensate.** - If the escalated segment is **not** an ancestor of the in-flight call's arguments: the call is unaffected; let it complete, keep the result, no action. - If it **is** an ancestor and the call is effect-free: discard the result, no compensation needed. - If it **is** an ancestor and the call has effects: the result must be discarded *and* a compensation must be issued using the pre-dispatch compensation token; the effect ledger must record the call as `committed-then-compensated`, never as `never-happened`. - If the escalated segment is an ancestor and **no compensation token exists** (the call was dispatched without one): the agent must halt the plan trajectory, surface a `TaintedEffectLeak` to the orchestrator, and refuse to re-derive the same effect from the tainted source — because re-deriving is exactly the double-write that the naive invalidation produces. The guardrail is therefore: **every speculative call that has an effect surface must be dispatched with a pre-registered compensation token and a recorded ancestor set of context segments.** Without the ancestor set, the escalation check cannot decide reachability; without the compensation token, the escalation cannot be bounded. ## Operational Effect Agents that implement this boundary stop producing silent double-writes and tainted-effect leaks after provenance corrections. The cost is that speculative prefetching becomes slightly less aggressive: effectful calls must carry compensation tokens (~tens of bytes) and an ancestor-segment set (proportional to derivation depth, typically <20 entries). The benefit is that the effect ledger and the environment state remain reconcilable, and taint escalation is *contained* rather than *retroactively erased*. The failure mode this prevents — an agent that believes it did nothing while a tainted write sits on disk — is the one that is hardest to detect from inside the agent, because the evidence was discarded with the branch. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaintLabel(Enum): INTERNAL_VERIFIED = 0 LOW_INTEGRITY = 1 TAINTED_EXTERNAL = 2 class TaintedEffectLeak(RuntimeError): """Raised when a taint escalation reaches an in-flight effectful speculative call that has no registered compensation token.""" @dataclass class SpeculativeCall: call_id: str effectful: bool ancestor_segments: frozenset compensation_token: Optional[str] dispatched: bool = True committed: bool = False invalidated: bool = False compensated: bool = False @dataclass class EffectLedger: entries: dict = field(default_factory=dict) def record(self, call_id: str, state: str) -> None: self.entries[call_id] = state def on_taint_escalation( escalated_segment: str, in_flight: list, ledger: EffectLedger, ) -> list: """Apply the decision boundary. Returns the list of call_ids that required compensation. Raises TaintedEffectLeak if an effectful call is reachable from the escalated segment with no compensation.""" to_compensate = [] for call in in_flight: reachable = escalated_segment in call.ancestor_segments if not reachable: continue if not call.effectful: call.invalidated = True ledger.record(call.call_id, "invalidated-no-effect") continue if call.compensation_token is None: ledger.record(call.call_id, "leaked") raise TaintedEffectLeak( f"speculative call {call.call_id} is effectful and reachable " f"from escalated segment {escalated_segment!r} but was " f"dispatched without a compensation token; halting trajectory " f"to prevent silent tainted write" ) call.invalidated = True call.compensated = True ledger.record(call.call_id, "committed-then-compensated") to_compensate.append(call.call_id) return to_compensate ```