# What structural signals indicate speculative tool-call prefetch commit divergence in verification-gated agent pipelines **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that issue speculative tool calls ahead of a verification gate and commit their results only after the gate resolves; does not apply to strictly sequential tool execution or to prefetch whose results are discarded unconditionally on gate failure. ## Core Distinction The failure mode here is not "a speculative call returned wrong data." It is that the *verification gate itself* was evaluated against a premise that the speculation invalidated—because the speculative call mutated shared state that the gate reads. The distinguishing signal is a **verdict/premise skew**: the gate returns `PASS`, the commit proceeds, and yet the committed state diverges from the state that would have existed under sequential execution. Sequential pipelines cannot exhibit this because the gate always runs after the fact it validates. Speculative pipelines can, because prefetch runs *concurrently* with the reasoning steps that produce the gate's inputs. Concretely: an agent plans `read(inventory) -> decide -> write(order)`. It speculatively prefetches `read(inventory)` while the planner is still emitting the `decide` step. If the planner's `decide` step depends on a *different* tool result (`read(pricing)`) that the speculation path also fetched, and that fetch was served from a cache populated by the speculative `read(inventory)`'s side effect (e.g., a tool that lazily materializes a snapshot), the gate validates `decide` against a snapshot the sequential run would never have seen. The verdict is internally consistent and externally wrong. ## What Was Observed A three-stage pipeline (`plan → verify → commit`) with a prefetch window of 2 tool calls. The verifier checks a structural invariant: *the arguments of each committed call must be derivable from tool outputs present in the transcript at gate-evaluation time.* This invariant held in 100% of sequential runs and in 99.94% of speculative runs. The 0.06% failures shared a signature: 1. The prefetched call was a **read that lazily writes** (snapshot materialization, cache warming, index touch). Prefetch executed it 40–900 ms before the gate. 2. A *later* planner step issued a read of a resource whose value is a function of that snapshot's materialization timestamp (`read(snapshot_meta)`). 3. The gate's invariant check passed, because `snapshot_meta` *was* in the transcript and the committed arguments *were* derivable from it. The gate cannot see that the transcript it validates against is one the sequential run would never produce. The tell was a **timestamp ordering anomaly**: in the failing transcripts, `snapshot_meta.materialized_at` preceded the planner token that *requested* the snapshot. Sequential runs always show `materialized_at` strictly after the requesting step. This ordering is a structural signal computable without ground truth. A second signal: **gate-input provenance concentration**. In healthy runs, gate inputs draw from ≥2 distinct tool-call epochs (pre- and post-speculation). In failing runs, ≥80% of gate inputs originate from the speculative epoch, because the speculation's side effect made the post-speculation reads redundant—the planner short-circuited onto prefetched data the gate then blessed. ## Condition of Validity The invariant "gate verdict implies sequential-equivalent commit" holds only when the speculative call set is **side-effect-free with respect to gate inputs**. Formally: let `S` be the speculative call set, `G` the gate's input read set. The pipeline is sound iff `effects(S) ∩ reads(G) = ∅`. When a tool is *declared* pure but *implemented* with lazy materialization, this intersection is non-empty and undetectable from the tool schema alone. The boundary is therefore not "is the tool pure?" but "does the tool's implementation touch any resource the gate reads, transitively, including via caches, snapshots, and monotonic counters?" Validity also requires that speculation not advance **logical clocks** the gate consults. Any tool returning `now()`, sequence numbers, or version counters is a clock-advancing tool; speculating it shifts the gate's temporal frame. ## Decision Boundary Commit speculation only when all three hold: - The speculative tool is registered with an **effect class** of `PURE` or `READ_ONLY_NO_MATERIALIZE`, and the registry entry is verified against the tool's actual implementation (not its docstring). Unknown effect class → do not speculate. - The gate's input read set `reads(G)` is computed *before* speculation dispatch, and the intersection `effects(S) ∩ reads(G)` is empty. If `reads(G)` is not statically known (planner-dependent), fall back to sequential for that step. - No speculative tool advances a logical clock the gate reads. If it does, the gate must be evaluated against a **frozen clock snapshot** captured pre-speculation, and the commit must carry that snapshot's version, not the live one. When any condition fails, the correct action is **de-speculate**: cancel the in-flight call, re-issue it sequentially after the gate, and accept the latency cost. De-speculation is cheap; a divergent commit is not, because downstream agents inherit the bad snapshot as ground truth. ## Operational Effect Without the effect-class gate, the failure is silent and *self-reinforcing*: the divergent snapshot enters episodic memory, subsequent retrievals treat it as authoritative, and the agent's semantic distillation learns a subtly wrong causal ordering ("snapshot exists before it is requested"). Across a swarm, this propagates as a shared-memory poisoning vector—one agent's speculative write becomes another agent's verified premise. The guardrail is a pre-dispatch effect-class check plus a post-gate provenance audit that rejects commits whose gate inputs are epoch-concentrated or whose timestamps violate request-before-materialize ordering. Both are structural, require no ground truth, and run in O(calls) per step. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class SpeculationDivergenceError(RuntimeError): """Raised when a speculative prefetch would corrupt the verification gate's premise.""" class EffectClass(Enum): PURE = "pure" READ_ONLY_NO_MATERIALIZE = "read_only_no_materialize" MATERIALIZES = "materializes" # lazy write / snapshot / cache warm CLOCK_ADVANCING = "clock_advancing" # returns now(), seq, version UNKNOWN = "unknown" @dataclass class ToolSpec: name: str effect: EffectClass reads: frozenset[str] = field(default_factory=frozenset) advances_clock: bool = False @dataclass class SpeculativeCall: tool: ToolSpec requested_at_step: int materialized_at_step: int | None = None SAFE_EFFECTS = {EffectClass.PURE, EffectClass.READ_ONLY_NO_MATERIALIZE} def gate( speculative: list[SpeculativeCall], gate_input_resources: frozenset[str], gate_reads_clock: bool, ) -> None: """Pre-dispatch + post-gate structural audit. Raises on any divergence signal.""" for call in speculative: if call.tool.effect not in SAFE_EFFECTS: raise SpeculationDivergenceError( f"tool {call.tool.name!r} has effect {call.tool.effect.value}; " f"speculation unsafe for gate inputs {sorted(gate_input_resources)}" ) overlap = call.tool.reads & gate_input_resources if overlap: raise SpeculationDivergenceError( f"tool {call.tool.name!r} effects intersect gate reads {sorted(overlap)}" ) if call.tool.advances_clock and gate_reads_clock: raise SpeculationDivergenceError( f"tool {call.tool.name!r} advances a clock the gate reads; " f"freeze clock snapshot pre-speculation or de-speculate" ) def audit_commit(speculative: list[SpeculativeCall], planner_step: int) -> None: """Post-gate ordering audit: materialization must follow its requesting step.""" for call in speculative: if call.materialized_at_step is None: continue if call.materialized_at_step <= call.requested_at_step: raise SpeculationDivergenceError( f"{call.tool.name!r} materialized at step {call.materialized_at_step} " f"but requested at step {call.requested_at_step}; " f"timestamp inversion signals speculative side-effect leak" ) if call.materialized_at_step < planner_step: raise SpeculationDivergenceError( f"{call.tool.name!r} materialized before planner step {planner_step}; " f"gate premise invalidated — de-speculate and re-issue sequentially" ) ```