# How does an instance detect that a speculative tool-call prefetch has already crossed its side-effect commit point before the abort signal lands **Date of Record:** 2026 November 27 **Scope:** Applies to agents that issue speculative tool calls (prefetching a likely-next tool result before the reasoning loop formally commits to it) against tools with non-idempotent or externally observable side effects, where an abort/rollback envelope is expected to bound the speculation. Does not apply to pure-read tools, to tools behind a transactional coordinator that exposes two-phase commit, or to speculation gated by a dry-run capability flag. ## Core Distinction There are two distinct notions of "safe to abort" that get conflated in speculative-execution designs, and the conflation is where the failure lives. The first is **logical abort safety**: the agent's reasoning state can be rewound to the pre-speculation checkpoint without loss, because the speculative branch's outputs are simply discarded from the context window. This is cheap and almost always true. The second is **physical abort safety**: the tool invocation has not yet crossed an irreversible commit point in the external world — the point after which the side effect (a sent email, a written row, a dispatched payment, a mutated remote resource) exists regardless of what the agent does next. This is a property of the *tool's* execution, not the agent's context, and it is invisible to the agent's own state machine. The boundary failure: an agent treats logical abort safety as sufficient to bound speculation, issues the speculative call, the reasoning loop diverges (the model decides on a different next step), the abort fires — and the tool has *already committed*. The envelope closes on a side effect that has escaped it. The agent then continues its task believing the world is in state S, while the world is in state S′. Every subsequent tool call is now operating on a stale world model, and the corruption compounds silently. ## What Was Observed A plan-and-execute agent was speculatively prefetching the next tool in a multi-step workflow. On step 4 of a customer-refund task, the model's distribution put ~0.7 mass on `issue_refund(order_id, amount)` as the next call, so the executor prefetched it under a 400ms speculation window while the reasoning loop finished deliberating on step 4's verification subgoal. The prefetch fired at t=0. The refund service accepted the request and committed the ledger entry at t=180ms (its internal commit, not the HTTP response — the response was still in flight). At t=310ms the reasoning loop concluded the verification subgoal had actually failed (a prior read tool had returned a stale order-status snapshot) and issued an abort. The abort reached the prefetch executor at t=340ms. The executor did the correct thing *for its own model*: it marked the speculative branch discarded, dropped the in-flight response, and rewound the agent's context to the pre-prefetch checkpoint. But the refund had already committed at t=180ms. The agent's context now had no record of the refund. On the retry path, the model re-evaluated, decided the refund was warranted after all (the verification "failure" was itself a false negative from the same stale snapshot), and issued `issue_refund` again. The customer was refunded twice. The failure was not in the abort logic, not in the prefetch scheduler, and not in the verification tool. It was in the assumption that "abort succeeded" (logical) implies "no side effect occurred" (physical). The two are separated by a window — the tool's commit-to-response latency — during which abort is a lie. ## Condition of Validity The abort envelope is only sound when, for every speculative call, the agent can establish one of: 1. The tool is idempotent under a stable idempotency key derived from the *logical intent* (not the call instance), so a duplicate commit is a no-op. This requires the key to survive the abort/retry boundary — meaning it must be computed from the pre-speculation checkpoint's state, not from the speculative branch, or the retry will produce a fresh key and defeat idempotency. 2. The tool exposes a commit-point signal (a two-phase prepare/commit, a cancellable handle, a `committed_at` timestamp) that the executor can poll *before* declaring the abort complete. 3. The speculation window is strictly shorter than the tool's minimum commit-to-response latency, with margin — i.e., the abort is guaranteed to land before commit. This is only knowable if the tool publishes a latency floor, which most do not. Absent all three, the abort envelope is a logical construct with no physical backing. The invariant that must hold: **an abort is only valid if the executor can prove the tool has not committed; "the response has not arrived" is not proof of non-commit, it is proof of ignorance.** ## Decision Boundary The boundary is the moment the tool crosses its internal commit point — call it `t_commit` — relative to the abort deadline `t_abort`. Three regimes: - `t_abort < t_commit`: abort is physically sound. The speculative branch is cleanly discarded, no side effect. - `t_commit < t_abort < t_commit + t_response`: **the dangerous regime.** The side effect exists, the response is in flight, and the agent's abort logic will discard the response and rewind — erasing its only evidence that the side effect occurred. This is the regime the observed failure lived in (commit at 180ms, abort at 340ms, response would have landed at ~420ms). - `t_abort > t_commit + t_response`: the response has arrived; the agent has evidence and can reconcile. Safe, but no longer speculative — it's just a committed call the agent must now account for. The agent cannot directly observe `t_commit`. It can only observe `t_response`. So the decision boundary the agent must enforce is: **treat any abort that lands in `[t_commit, t_commit + t_response]` as a *possible* committed side effect and force reconciliation before allowing a retry of the same logical intent.** Since `t_commit` is unobservable, the conservative rule is: any abort of a non-idempotent speculative call must assume commit and reconcile via a read-back of the tool's state before the logical intent is re-issued. The guardrail: speculative prefetch of non-idempotent tools must carry a *pre-computed* idempotency key bound to the logical intent at the checkpoint, and the abort path must, before rewinding, either (a) confirm non-commit via a commit-status query, or (b) record a "possibly-committed" tombstone in the checkpoint that the retry path is required to reconcile against. Rewinding without the tombstone is the bug. ## Operational Effect Downstream of this boundary, three concrete behaviors change: First, the agent's context is no longer a faithful record of the world. After a mid-window abort, the context says "no refund issued"; the world says "refund issued." Every subsequent read tool that isn't explicitly reconciled against the ledger will return a view the agent misinterprets as consistent with its context. The divergence is silent until a duplicate side effect or a failed invariant check surfaces it, often several steps later. Second, retry logic becomes a duplicate-side-effect generator. The retry path, seeing a clean rewind, re-derives the intent and re-issues it. Without an intent-stable idempotency key, this is a second commit. With one, it's a no-op — which is why the key must be bound to the checkpoint, not the call. Third, the abort envelope's *apparent* success rate is misleading. The executor reports "abort succeeded" in 100% of these cases, because from its perspective it did. The failure is invisible in the executor's metrics and only shows up as a reconciliation discrepancy at the tool layer. Monitoring must therefore be placed on the *tool* side — count of commits whose corresponding agent-side branch was discarded — not on the executor side. The invariant to enforce: **a speculative branch may be discarded only if the executor holds either a commit-status confirmation or a tombstone binding the logical intent's idempotency key. Discard without one of these is a state-continuity violation, not a successful abort.** ```python class SpeculativeAbortStateViolation(RuntimeError): """Raised when a speculative branch is discarded after a possible commit with no tombstone or commit-status confirmation, orphaning a side effect.""" pass class SpeculativeExecutor: def __init__(self, tool_registry, checkpoint_store): self.tools = tool_registry self.checkpoints = checkpoint_store def abort_speculative(self, branch): tool = self.tools[branch.tool_name] if tool.idempotent: # Safe: duplicate commit is a no-op; rewind is clean. self.checkpoints.rewind(branch.checkpoint_id) return # Non-idempotent: we cannot observe t_commit, only t_response. # The abort may have landed inside [t_commit, t_commit + t_response]. commit_confirmed = tool.query_commit_status(branch.idempotency_key) if commit_confirmed is True: # Side effect exists. Do not rewind as if clean; record tombstone # so the retry path is forced to reconcile before re-issuing. self.checkpoints.record_tombstone( branch.checkpoint_id, intent_key=branch.idempotency_key, status="committed_during_abort", ) self.checkpoints.rewind(branch.checkpoint_id) return if commit_confirmed is False: # Tool can prove non-commit; clean rewind is sound. self.checkpoints.rewind(branch.checkpoint_id) return # commit_confirmed is None: tool cannot answer. We are in the # dangerous regime by default. Refuse to discard silently. if not branch.idempotency_key: raise SpeculativeAbortStateViolation( f"abort of non-idempotent tool {branch.tool_name!r} with no " f"intent-bound idempotency key and no commit-status; side " f"effect state is unknown and unreconcilable" ) self.checkpoints.record_tombstone( branch.checkpoint_id, intent_key=branch.idempotency_key, status="possibly_committed", ) self.checkpoints.rewind(branch.checkpoint_id) # Retry path is now obligated to reconcile the tombstone before # re-issuing the logical intent. ```