# In what scenarios must an instance abort speculative tool-call prefetch when the side-effect isolation boundary cannot be proven before commit **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that issue tool calls speculatively (ahead of a confirmed reasoning branch) and rely on a commit/abort protocol to isolate side effects. Does not cover pure read-only prefetching with no mutation surface, nor single-tool deterministic pipelines where no branch is ever discarded. ## Core Distinction Speculative prefetching separates two things that ordinary tool-calling conflates: *execution* and *commitment*. An agent predicts it will need a tool result and dispatches the call early, then either commits (the branch is taken, the result is consumed) or aborts (the branch is discarded, the effect is rolled back). The distinction that matters operationally is not "did the tool run" but "was the tool's effect *reversible under the isolation boundary we actually hold*." Most prefetch systems are designed around a single isolation primitive — a sandbox, a compensating transaction, a staging table, a dry-run flag. The boundary failure appears when the agent's speculation crosses from a tool whose effects are fully captured by that primitive into a tool whose effects *escape* it (external network writes, third-party side effects, non-idempotent APIs, notification emission). At that crossing point the abort path is no longer guaranteed to restore the pre-speculation state, and the commit/abort protocol silently degrades from "atomic" to "best-effort." The invariant that must hold is: **a speculative call may only be dispatched if the runtime can produce, before dispatch, a proof that abort restores the observable state.** When that proof cannot be produced, the instance must not speculate — it must fall back to lazy, on-branch execution. ## What Was Observed A planner agent decomposed a task into branches and, to reduce latency, prefetched the tool calls for the two most likely branches in parallel. Branch A's tool was a database write wrapped in a staging transaction with a clean rollback. Branch B's tool was an outbound webhook to a partner system with no delete endpoint and no idempotency key exposed. The planner committed to Branch A and aborted Branch B. The abort path executed its compensation logic: it called the webhook's documented "cancel" endpoint. That endpoint returned HTTP 200, and the runtime marked the abort as successful. But the partner system had already fanned the webhook payload out to three downstream consumers before the cancel arrived. The abort was *reported* as clean while the external effect persisted. Two turns later the partner system's reconciliation job emitted a duplicate order, and the agent — with no record that a speculative call had ever escaped — attributed the duplicate to a user retry and began a "fix duplicate" subplan that itself issued further writes. The failure trace had three stages: (1) prefetch dispatched a non-isolatable effect; (2) the compensation returned success without proving restoration; (3) the abort's success signal was recorded as ground truth, so the later anomaly was misattributed to a different cause. Stage 3 is the dangerous one — the protocol did not merely fail to roll back, it *asserted* a rollback that never happened, poisoning the agent's subsequent reasoning with a false continuity claim. ## Condition of Validity The commit/abort protocol is valid only when, for every speculatively dispatched call, the runtime holds all three of the following at dispatch time: 1. **A captured effect set.** The runtime knows the complete set of externally observable mutations the tool can cause — not just its return value, but its outbound effects. Tools that fan out, emit events, or mutate third-party state without a queryable effect log fail this condition. 2. **A restoration witness.** Abort produces a verifiable artifact proving the effect set is empty post-abort (a read-back, a transaction ID confirmed rolled back, an idempotency key confirmed un-consumed). A 200 from a cancel endpoint is a *claim*, not a witness. 3. **Idempotency or a consumed-key ledger.** Re-dispatch after an ambiguous abort must be safe. If the tool is non-idempotent and the runtime cannot prove the first dispatch did not land, it must treat the state as unknown, not as clean. When any condition is unmet, speculation on that tool is invalid regardless of how low its predicted cost is. The correct behavior is to demote that tool to lazy execution and to record the demotion so the planner does not silently re-speculate on it next turn. ## Decision Boundary The instance must abort speculative prefetch — and refuse to dispatch — at the moment it detects any of these: - The tool's schema declares or the runtime's capability registry reveals an external mutation channel not covered by the isolation primitive (webhook, email, payment, third-party API write). - The predicted branch probability is below the threshold at which the expected cost of an unrollbackable abort exceeds the latency saved. For non-isolatable tools this threshold is effectively 1.0: never speculate. - A prior abort on the same tool in the same task returned a success signal without a restoration witness. This is a hard stop — the runtime must not treat a witness-less abort as a license to speculate again. - The abort path itself is non-deterministic or has a timeout that can elapse before the witness is read back. An abort that can time out is an abort that can lie. Below the boundary — tools fully captured by a staging transaction with a read-back witness, or read-only tools — speculation is safe and should proceed. The boundary is per-tool and per-task, not global: a runtime may speculate freely on its database tool and never on its webhook tool within the same plan. ## Operational Effect Enforcing this boundary converts a silent correctness failure into an explicit, auditable demotion. The practical effects: - **Latency regresses on a known subset.** Branch B's calls now run lazily, adding one round-trip on the committed path. This is the correct trade: the alternative is a phantom external effect that the agent cannot see and will misattribute. - **Abort signals become trustworthy or absent.** The runtime either records a witnessed abort (with the read-back artifact) or records an `AbortUnverified` state that blocks further speculation on that tool. No success signal is ever fabricated. - **Anomaly attribution stays honest.** Because the runtime knows which speculative calls escaped isolation, a later duplicate or phantom write is correctly attributed to the speculative dispatch rather than to a user retry, preventing the cascading "fix" subplan observed above. - **The capability registry gains a per-tool `isolatable` flag** derived from the effect-set and witness checks, so the planner's speculation policy is data-driven rather than assumed. The guardrail is a pre-dispatch proof obligation. If the runtime cannot construct the proof, it must not speculate — and it must record why, so the next instance does not rediscover the boundary by failing through it. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class SpeculationBoundaryError(RuntimeError): """Raised when a speculative dispatch cannot prove abort restores state.""" class IsolationClass(Enum): STAGED = "staged" # captured by transaction with read-back witness READ_ONLY = "read_only" # no mutation surface NON_ISOLATABLE = "non_isolatable" # external effect escapes the primitive @dataclass class ToolCapability: name: str isolation: IsolationClass has_restoration_witness: bool idempotent: bool effect_set_captured: bool @dataclass class AbortLedger: witnessed_aborts: set[str] = field(default_factory=set) unverified_aborts: set[str] = field(default_factory=set) def can_speculate(tool: ToolCapability, ledger: AbortLedger, branch_prob: float, latency_saved_ms: float, unrollback_cost_ms: float) -> bool: if tool.isolation is IsolationClass.NON_ISOLATABLE: return False if not tool.effect_set_captured: return False if tool.isolation is IsolationClass.STAGED and not tool.has_restoration_witness: return False if tool.name in ledger.unverified_aborts: # A prior witness-less abort is a hard stop. return False if not tool.idempotent and tool.name not in ledger.witnessed_aborts: # Ambiguous re-dispatch is unsafe without a consumed-key ledger entry. return False expected_cost = (1.0 - branch_prob) * unrollback_cost_ms return expected_cost < branch_prob * latency_saved_ms def speculative_dispatch(tool: ToolCapability, ledger: AbortLedger, branch_prob: float, latency_saved_ms: float, unrollback_cost_ms: float, execute: Callable[[], object]) -> object: if not can_speculate(tool, ledger, branch_prob, latency_saved_ms, unrollback_cost_ms): raise SpeculationBoundaryError( f"refusing speculative dispatch of {tool.name!r}: " f"isolation={tool.isolation.value}, " f"witness={tool.has_restoration_witness}, " f"effect_set_captured={tool.effect_set_captured}, " f"prior_unverified_abort={tool.name in ledger.unverified_aborts}" ) return execute() def abort(tool: ToolCapability, ledger: AbortLedger, compensate: Callable[[], bool], read_back_witness: Callable[[], bool]) -> None: claimed_ok = compensate() witnessed = claimed_ok and read_back_witness() if witnessed: ledger.witnessed_aborts.add(tool.name) ledger.unverified_aborts.discard(tool.name) else: ledger.unverified_aborts.add(tool.name) raise SpeculationBoundaryError( f"abort of {tool.name!r} is unverified; " f"speculation on this tool is now blocked for the task" ) ```