# How should an instance cancel a speculative tool call whose taint has already propagated into a committed reasoning step **Date of Record:** 2026 November 22 **Scope:** Applies to agents that issue speculative (pre-emptive) tool calls in parallel with reasoning, where results are buffered and conditionally committed. Does not apply to strictly serial tool-call loops or to pure read-only prefetch with no downstream state dependency. ## Core Distinction Speculative prefetching assumes a tool call is either *used* or *discarded*. The taint-aware cancellation boundary exposes a third state that breaks this binary: a speculative call whose **result has already been read by a reasoning step that was committed before the speculation was resolved**. Cancellation of a call is not the same as cancellation of its *influence*. The invariant at stake is: **a speculative result may only influence committed state if its provenance is still live at commit time.** When a speculative call is invalidated (its precondition changed, its budget was revoked, its target was mutated by a concurrent agent), any reasoning step that consumed the buffered result is now tainted — and the agent must either retract that step or prove the taint did not affect the committed conclusion. Most implementations cancel at the *call* layer and miss the *influence* layer. That gap is the failure. ## What Was Observed An agent running a plan-verify loop issued three speculative calls in parallel: `read_config()`, `read_schema()`, and `fetch_remote_manifest()` (the last with a 900ms timeout, marked speculative). While waiting, its reasoning step consumed `read_schema()` output and drafted an assertion: *"The schema declares field X as required."* That draft was committed to the working context at step 14. At step 15, a concurrent auditor agent invalidated `read_schema()`'s source — the schema file had been rewritten by another process between the speculative read and commit. The cancellation manager marked the call `CANCELLED_STALE` and removed its buffer entry. But the assertion from step 14 remained in context, now unsupported by any live provenance. The agent continued, built a migration plan on field X being required, and the plan was wrong. The failure trace: 1. `t=0` — speculative call issued, tagged `spec_id=S1`, `precondition=schema_hash(h0)`. 2. `t=40ms` — result buffered, `S1` marked `PENDING_COMMIT`. 3. `t=55ms` — reasoning step 14 reads buffer, commits assertion `A14`, records dependency `A14 → S1` but **not** the precondition hash. 4. `t=120ms` — external mutation: schema hash becomes `h1`. 5. `t=300ms` — cancellation manager sees `precondition != current`, marks `S1 CANCELLED_STALE`, drops buffer. 6. `t=301ms` — `A14` remains in context. No invalidation cascade fires because the dependency edge lacked a precondition binding. The cancellation was correct at the call layer and inert at the influence layer. The agent's context now contained a fact whose warrant had been revoked 180ms after the fact was committed. ## Condition of Validity The invariant holds — cancellation is safe — only if every committed reasoning artifact that read a speculative buffer carries a **precondition binding** to that buffer entry, and the cancellation manager performs a **backward taint walk** over committed artifacts before clearing the buffer. Formally: for any committed artifact `A` with dependency edge `A → S`, the edge must record the precondition hash (or version vector) of `S` at read time. On cancellation of `S`, the manager must enumerate all `A` reachable from `S` and either (a) retract them, (b) mark them `TAINTED` and force re-derivation, or (c) prove the taint is non-influential (the artifact did not use the specific fields that changed). The condition fails when: - Dependency edges are recorded without precondition bindings (the common case — most frameworks log `A depends on tool T`, not `A depends on T@version`). - Prefetch results are read into context *before* commit resolution, which is the entire point of prefetching and therefore unavoidable. - A downstream artifact is committed by a *different* agent instance that received `A` via handoff, losing the local dependency graph. ## Decision Boundary The boundary is between **retract-and-rederive** and **taint-and-continue**, and it is crossed by a single question: *did the committed artifact's conclusion depend on the mutated portion of the speculative result?* - If the artifact consumed only fields that are byte-identical between `h0` and `h1`, the taint is non-influential; continue with a `TAINT_CLEARED` annotation. - If the artifact consumed any field that differs, or if field-level provenance was not recorded (the default, and the dangerous case), the artifact must be retracted and re-derived. Non-influentiality cannot be assumed — absence of field-level provenance is a *failure to prove*, not a *proof of safety*. - If re-derivation is impossible (budget exhausted, source unreachable), the agent must escalate to a hard stop rather than proceed on tainted context. Proceeding is the observed failure. The architecture that bounds this: speculative buffers are **immutable and versioned**; every read records `(spec_id, precondition_hash, field_set_read)`; cancellation triggers a taint walk that retracts or re-derives any artifact whose `field_set_read` intersects the changed field set, and hard-fails any artifact with unrecorded field provenance. ## Operational Effect Without precondition-bound dependency edges and a taint walk, speculative prefetching is a silent correctness leak: the agent gets *faster* and *more confidently wrong*, and the error surfaces only at plan execution, far from the cancellation event that caused it. The 180ms window between commit and invalidation is enough for a dozen downstream reasoning steps to inherit the taint. With the invariant enforced, cancellation becomes a *context surgery* operation — it must reach into committed state and retract influence, not just free a buffer — and the cost of a speculative miss rises from "wasted tokens" to "retract and re-derive the dependent subgraph," which must be budgeted for at speculation time. ```python from dataclasses import dataclass, field from typing import Dict, Set, Optional class TaintCancellationError(RuntimeError): """Raised when a speculative result is cancelled after its taint has propagated into committed reasoning state that cannot be safely retracted or proven non-influential.""" pass @dataclass class SpecEntry: spec_id: str precondition_hash: str status: str = "PENDING_COMMIT" # PENDING_COMMIT | COMMITTED | CANCELLED_STALE changed_fields: Set[str] = field(default_factory=set) @dataclass class Artifact: artifact_id: str spec_id: str precondition_hash: str fields_read: Set[str] class TaintAwareCanceller: def __init__(self): self.specs: Dict[str, SpecEntry] = {} self.artifacts: Dict[str, Artifact] = {} def commit_artifact(self, art: Artifact) -> None: # Enforce precondition binding at commit time. spec = self.specs.get(art.spec_id) if spec is None: raise TaintCancellationError( f"artifact {art.artifact_id} depends on unknown spec {art.spec_id}" ) if spec.precondition_hash != art.precondition_hash: raise TaintCancellationError( f"artifact {art.artifact_id} bound to stale precondition " f"{art.precondition_hash} != live {spec.precondition_hash}" ) if not art.fields_read: raise TaintCancellationError( f"artifact {art.artifact_id} has no field-level provenance; " f"cannot prove non-influence on cancellation" ) self.artifacts[art.artifact_id] = art def cancel_stale(self, spec_id: str, changed_fields: Set[str]) -> Set[str]: """Cancel a speculative call and perform the backward taint walk. Returns the set of artifact ids that must be retracted.""" spec = self.specs[spec_id] spec.status = "CANCELLED_STALE" spec.changed_fields = changed_fields retract: Set[str] = set() for art in self.artifacts.values(): if art.spec_id != spec_id: continue if not art.fields_read: # No provenance: cannot prove non-influence. Hard fail. raise TaintCancellationError( f"artifact {art.artifact_id} lacks field provenance; " f"taint from {spec_id} cannot be bounded" ) if art.fields_read & changed_fields: retract.add(art.artifact_id) for aid in retract: del self.artifacts[aid] return retract ```