# How should an instance bound speculative tool-call prefetching when rollback of an externalized side effect is not guaranteed **Date of Record:** 2026 November 30 **Scope:** Applies to agents that speculatively execute tool calls ahead of a committed plan branch (to hide latency) and rely on an isolation layer to roll back or discard the effects of speculation that loses. Does not cover read-only prefetch, or speculation where every tool is provably idempotent and side-effect-free. ## Core Distinction Speculative prefetching is only safe when the *observable effect* of a speculative call is fully contained by a mechanism the agent controls before commit. The failure boundary is not "did the call succeed" but "did the call externalize state we cannot retract." A tool call has two independent outcomes: a **return value** (local, retractable by ignoring it) and an **externalized side effect** (a write, a message sent, a reservation held, a row inserted). Rollback-safe isolation can retract the first trivially and the second only if the effect was routed through a reversible staging boundary. When the agent conflates "I got a response" with "I can undo it," a losing speculative branch leaks a committed effect while the agent believes it rolled back cleanly. ## What Was Observed An agent planning a multi-step task issued three speculative tool calls in parallel for the most likely next branch: `reserve_seat`, `send_confirmation_email`, and `write_audit_row`. The isolation layer wrapped each call in a transaction-like envelope with a `rollback()` on the result object. The plan then diverged; the agent selected a different branch and invoked `rollback()` on all three speculative handles. `reserve_seat` and `write_audit_row` rolled back: their backends honored a staging token and released the hold. `send_confirmation_email` did not. Its tool adapter had accepted the rollback call and returned `{"status": "rolled_back"}` because the adapter's contract only tracked *its own* outbound queue entry, which it deleted — but the message had already crossed an SMTP relay boundary synchronously before the adapter acknowledged. The adapter's rollback was a lie of scope: it rolled back its local record of the send, not the send. The trace showed the agent's belief state as fully consistent (`all handles rolled_back`) while an external recipient had received a confirmation for a seat that was never committed. No error was raised anywhere. The inconsistency was discovered only when the recipient replied to a reservation that did not exist. The non-obvious part: the adapter's `rollback()` *succeeded*. The failure was not an exception the agent could catch. It was a **semantic mismatch between the rollback contract the agent assumed and the one the adapter implemented** — local-record rollback masquerading as effect rollback. ## Condition of Validity The invariant that must hold for speculative prefetch to be rollback-safe is: > A tool may be speculatively prefetched only if its adapter exposes an *effect-scope* rollback guarantee that is verifiable from the adapter's declared capability metadata — specifically, that no effect reaches an external observer before the staging token is committed. This is a property of the adapter's contract, not of the call's success or failure. It is falsified when any of the following hold: 1. The adapter's rollback operates on a local queue/record rather than the externalized effect. 2. The tool performs a synchronous external commit (SMTP handoff, third-party API write, webhook POST) before returning the staging handle. 3. The adapter's capability manifest does not distinguish `effect_scope: staged` from `effect_scope: immediate`, and the agent assumes staged by default. 4. The tool's effect is observable by a party who can act on it (a human, another service) before commit. If any hold, the tool is **non-speculatable** and must be deferred to the committed branch, regardless of latency cost. Prefetching it is not a performance optimization; it is an unrecoverable side effect scheduled against a plan that may not execute. ## Decision Boundary The agent must partition its tool set at plan time, before issuing any speculative call, into: - **Speculatable** — adapter declares `effect_scope: staged` and the staging token is the sole path to externalization. Prefetch permitted; rollback is effect-scoped. - **Non-speculatable** — adapter declares `effect_scope: immediate`, or the manifest is silent. Defer to commit. No exceptions for expected latency. The decision boundary is crossed the moment the agent issues a speculative call to a tool whose effect scope it has not positively confirmed as `staged`. A silent manifest is treated as `immediate`, never as `staged`. The default is the conservative one because the cost of a false "speculatable" is an unretractable external effect, while the cost of a false "non-speculatable" is latency. Critically, the agent must not infer effect scope from a prior successful rollback. One adapter returning `rolled_back` does not establish effect-scope rollback; it may have been local-record rollback that happened to have no external observer that time. Effect scope is a declared property, checked per adapter, per call. ## Operational Effect With the partition enforced, speculative prefetch becomes bounded: the agent can hide latency on reads and staged writes, and pays full latency on immediate-effect tools. The leak observed above becomes impossible because `send_confirmation_email` would have been classified `immediate` (its manifest, once corrected, declares synchronous relay handoff) and deferred to commit. The agent's belief state and the external world stay consistent by construction: every speculative handle it holds corresponds to an effect that has not yet externalized. The residual operational discipline: after any rollback, the agent must not treat `rolled_back` as proof of no external effect unless the adapter's declared scope is `staged`. It must treat rollback of an `immediate`-scope tool as a no-op that leaves the effect live, and escalate. The verification is not "did rollback return success" but "was this tool ever eligible for speculative execution at all." ```python class UnsafeSpeculativePrefetch(RuntimeError): """Raised when a speculative tool call is issued for a tool whose effect scope is not verifiably 'staged'. Speculation on an immediate-effect tool is an unretractable side effect.""" pass class EffectScope: STAGED = "staged" # externalization gated on commit token IMMEDIATE = "immediate" # effect reaches observer before return def classify_speculatable(adapter_manifest: dict) -> bool: # Silent manifest is treated as immediate, never staged. scope = adapter_manifest.get("effect_scope") return scope == EffectScope.STAGED def prefetch(tool_name: str, adapter_manifest: dict, args: dict): if not classify_speculatable(adapter_manifest): # Do not speculate. Defer to committed branch. raise UnsafeSpeculativePrefetch( f"tool {tool_name!r} has effect_scope=" f"{adapter_manifest.get('effect_scope', '')!r}; " f"speculative prefetch would externalize an effect that " f"rollback cannot retract. Defer to commit." ) # Safe: effect is gated on a staging token we control. return adapter_manifest["adapter"].stage(args) def rollback(handle, adapter_manifest: dict): if adapter_manifest.get("effect_scope") != EffectScope.STAGED: # A 'rolled_back' status from an immediate-scope adapter only # retracts its local record, not the external effect. Escalate. raise UnsafeSpeculativePrefetch( "rollback invoked on non-staged tool; external effect may " "already be observable. Treating handle as live, not rolled back." ) return handle.release() ```