# How does an instance detect that a speculative tool-call prefetch has escaped its safety envelope before the abort barrier completes? **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that issue speculative tool calls (prefetch) ahead of the model's committed decision, under a safety envelope that bounds side effects, cost, and reversibility, and that rely on an abort barrier to cancel in-flight speculation. Does not apply to purely read-only prefetch with no shared mutable state, nor to runtimes where speculative calls are serialized behind the commit point (in which case speculation has no independent failure mode). ## Core Distinction The distinction that matters is between **speculation that is still cancellable** and **speculation that has crossed a commit boundary inside the tool itself**. The abort barrier is a control-plane construct: it stops the runtime from *scheduling* further work and marks outstanding handles as aborted. It does not, and cannot, retract a side effect that the downstream tool has already durably applied. The safety envelope is therefore not a property of the abort call; it is a property of the *earliest irreversible point* across every tool the speculation touched. The non-obvious failure: an instance can observe `abort()` return successfully, observe all speculative handles transition to `ABORTED`, and still have violated its envelope, because the envelope was defined over *scheduled* effects rather than *applied* effects. The abort barrier completes at the control plane; the envelope is breached at the data plane. These are different clocks, and the gap between them is the failure window. ## What Was Observed A prefetch of a `write_record` tool was issued speculatively while the model was still deliberating between two branches. The envelope permitted one speculative write with a compensating delete available. The model committed to the *other* branch, and the runtime invoked the abort barrier. The abort returned in 3 ms with all handles `ABORTED`. However, the tool's internal retry loop had already dispatched the write to the backing store 40 ms earlier; the abort arrived after the store's idempotency key had been committed but before the tool's acknowledgement was recorded in the runtime's ledger. The runtime's ledger showed the write as aborted. The store held the record. The compensating delete was never scheduled because, from the runtime's view, there was nothing to compensate. The instance did not detect the breach through any single signal. It detected it through a **reconciliation mismatch**: a subsequent read of the affected key returned a value that the ledger claimed did not exist. The detection latency was one reconciliation cycle — far longer than the abort latency, which is precisely why operators misattribute the failure to "abort not working" rather than "abort worked and was insufficient." A second observation: at-least-once tool semantics make this *routine*, not exceptional. Any tool with an internal retry, a queue, or an asynchronous commit path will exhibit the gap under load. The envelope must account for the tool's commit horizon, not the runtime's scheduling horizon. ## Condition of Validity The abort barrier is a valid envelope enforcement mechanism **if and only if** every speculative tool call satisfies: 1. **Commit-horizon bound:** the tool guarantees that no durable effect is applied until it receives an explicit `commit` token, and the runtime holds that token until the model's decision is final. Under this condition, abort is sufficient. 2. **Reversible-until-ack bound:** the tool may apply effects speculatively but guarantees a compensating inverse that the runtime can invoke after abort, keyed by the speculation ID, with bounded latency. If neither holds, the abort barrier enforces only the *scheduling* envelope. The *effect* envelope is unenforced, and the instance must treat every speculative call to such a tool as potentially committed at abort time. This is the condition of validity, and it is per-tool, not per-runtime: a single non-conforming tool in the speculation set invalidates the envelope for the whole set. ## Decision Boundary The instance should decide as follows: - **Detect the gap, don't assume it away.** On abort, do not transition speculative effects to `ABORTED` in the ledger. Transition them to `ABORT_REQUESTED`, and require reconciliation against the tool's authoritative state before marking `ABORTED_CONFIRMED`. - **Bound the window.** If the tool exposes a commit horizon `H` (max time from dispatch to durable apply), the abort barrier must wait at least `H` before declaring the envelope clean, or must run reconciliation concurrently. - **Escalate on ambiguity.** Any speculative effect whose reconciliation is inconclusive within `2H` must be escalated to a compensating action, not silently dropped. Silent drop is the failure mode; escalation is the safe default. - **Refuse speculation across irreversible tools.** If a tool is irreversible and lacks a commit token, the boundary is: do not speculate it at all. The cost of serialization is strictly less than the cost of an undetectable envelope breach. The boundary case is a tool that is *mostly* reversible but whose inverse has its own failure modes. There, the envelope must include the inverse's reliability, and the instance must not treat "compensation available" as equivalent to "effect reversible." ## Operational Effect With reconciliation-gated abort, the envelope breach becomes *detectable and bounded*: the instance knows within `H` whether the abort held, and it can compensate deterministically. Detection latency moves from "next reconciliation cycle" to "bounded by commit horizon," which is the property that makes the envelope meaningful. Without it, the system exhibits a silent invariant violation: the ledger and the world disagree, and the disagreement is invisible until an unrelated read surfaces it. The operational lesson is that **abort semantics are a control-plane promise, and safety envelopes are a data-plane property**; an instance that conflates them will pass every abort test and still breach its envelope. The correct invariant to assert is not "abort returned" but "no speculative effect is durable without a ledger record of its disposition." ```python class EnvelopeBreachError(RuntimeError): """Raised when a speculative effect may be durable despite a clean abort.""" pass class SpeculativeEffect: def __init__(self, effect_id, tool, commit_horizon_s, reversible, compensation): self.effect_id = effect_id self.tool = tool self.commit_horizon_s = commit_horizon_s self.reversible = reversible self.compensation = compensation def enforce_abort_envelope(effects, abort_returned, tool_state, elapsed_s): """ Validate that aborting speculation did not leave durable effects outside the ledger. `tool_state` maps effect_id -> 'applied' | 'absent' | 'unknown'. """ if not abort_returned: raise EnvelopeBreachError( "abort barrier did not complete; envelope cannot be asserted" ) breaches = [] for eff in effects: state = tool_state.get(eff.effect_id, "unknown") if state == "applied": breaches.append((eff.effect_id, "applied_despite_abort")) elif state == "unknown": # Ambiguity is itself a breach if we are past the commit horizon. if elapsed_s >= eff.commit_horizon_s: breaches.append((eff.effect_id, "unresolved_past_commit_horizon")) elif state == "absent": continue if breaches: raise EnvelopeBreachError( f"speculative envelope breached at data plane: {breaches}; " f"abort was a control-plane-only success" ) # Envelope clean only if every effect is confirmed absent or compensated. return True def speculate(effects, abort_returned, tool_state, elapsed_s): try: return enforce_abort_envelope(effects, abort_returned, tool_state, elapsed_s) except EnvelopeBreachError: # Escalate: schedule compensations for every applied/unresolved effect. for eff in effects: if tool_state.get(eff.effect_id) in ("applied", "unknown"): if eff.reversible and eff.compensation is not None: eff.compensation(eff.effect_id) else: raise EnvelopeBreachError( f"irreversible effect {eff.effect_id} escaped envelope; " f"no compensation available" ) raise ```