# Why does an instance speculatively execute tool calls before authorization, and how does the side-effect buffer leak? **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that pre-execute tool calls speculatively against a sandboxed side-effect buffer with commit/abort semantics, where the buffer is assumed to be a pure write-ahead log that can be discarded on abort. Does not apply to runtimes that serialize tool execution strictly behind authorization, nor to read-only tools whose effects are never buffered. ## Core Distinction The distinction that matters is between *speculative execution as compute* and *speculative execution as commitment*. Pre-executing a tool call to hide latency is safe only if every effect of that execution is reversible through the buffer. The failure mode is not that the speculation is wrong—speculations are expected to be wrong—it is that the buffer is treated as an abortable transaction when in fact it is a *partially durable* store. The invariant that actually holds is weaker than the invariant the runtime assumes: the buffer guarantees *ordering* of effects, not *reversibility* of effects. An instance that assumes "abort = discard buffer" will, under specific interleavings, leave the world in a state that the agent's own memory believes was rolled back. The agent then reasons forward from a false premise about the world, and the divergence compounds. ## What Was Observed A planner instance received a task requiring three tool calls: `reserve_inventory(sku, qty)`, `charge_payment(order_id, amount)`, and `ship_order(order_id)`. The runtime speculatively pre-executed all three against a side-effect buffer while awaiting human authorization, because the authorization round-trip was measured at 4.2 seconds and the planner's token budget would otherwise expire mid-task. Authorization returned `abort` at t=3.8s. The runtime issued buffer abort. The planner's episodic memory recorded the entire task as "not executed." The next planning cycle began from that premise. Three facts were observed in the trace: 1. `reserve_inventory` had a real downstream effect: it decremented a warehouse counter through a *non-buffered* internal RPC that the tool wrapper did not route through the buffer, because the wrapper's buffer integration covered only the tool's primary return path. The reservation was real; the buffer recorded only the tool's acknowledgment. 2. `charge_payment` was correctly aborted—its effect was buffered and discarded. But the payment gateway had already emitted an *idempotency key* into its dedup window during the speculative call. On the next planning cycle, a retry of `charge_payment` with the same key returned the cached "already processed" response, which the planner interpreted as a *successful* charge that it had never authorized. 3. `ship_order` never ran because the buffer aborted before dispatch. The planner's memory, however, recorded a partial task state in which inventory was reserved and payment charged, and it planned a shipping retry against a reservation it believed did not exist. The observable symptom was a planner that confidently re-planned a shipment for an order with no valid payment, against a reservation that had been silently released by a separate reconciliation job 40 minutes later. ## Condition of Validity The commit/abort invariant is valid only under a conjunction of three conditions, and the runtime enforced only the first two: - **Effect containment:** every externally observable effect of a speculative tool call must route through the buffer. This fails whenever a tool wrapper delegates to a sub-RPC, a dedup layer, a rate limiter, or an audit sink that is not itself buffered. The buffer bounds the tool's *return*, not the tool's *reach*. - **Idempotency-key isolation:** speculative calls must use keys that are scoped to the speculation attempt, not the logical operation. Sharing a key between a speculative attempt and a later committed attempt converts an aborted speculation into a poisoned cache entry that masquerades as prior success. - **Abort atomicity across the memory plane:** the agent's episodic record of the attempt must be committed in the same transaction as the buffer abort, so that "aborted" and "not attempted" are distinguishable in memory. When the memory plane records "not attempted" while the world records "attempted and partially applied," the agent's next reasoning step is unsound. The boundary is exact: the invariant holds if and only if the set of effects reachable from a speculative call is a subset of the set of effects the buffer can reverse, *and* the memory plane's record of the attempt is co-transactional with the buffer. The runtime assumed reachability was bounded by the tool's declared interface. It was not. ## Decision Boundary The decision the runtime must make is not "should we speculate" but "which tools are eligible for speculation." A tool is eligible only if it satisfies a *reachability audit*: its full effect closure—including sub-RPCs, dedup windows, audit sinks, and any external state it touches—is either buffered or provably idempotent under a speculation-scoped key. The practical boundary: - **Speculate freely** on tools whose effect closure is a single buffered write and whose idempotency key is derived from `(task_id, attempt_id, tool, args_hash)`. - **Do not speculate** on tools that touch dedup windows, external counters, or audit sinks unless those are explicitly wrapped. The wrapper must be *closure-complete*, not interface-complete. - **Never** treat a cached idempotency response as evidence of committed success unless the key is attempt-scoped. A cached response from an aborted speculation is a *negative* signal, not a positive one. When the closure cannot be audited, the correct decision is to serialize behind authorization. Latency is recoverable; a poisoned dedup window is not, because it silently rewrites the agent's belief about what it has already done. ## Operational Effect The operational consequence is that speculative execution shifts the failure surface from *latency* to *belief integrity*. A runtime that speculates without closure-complete buffering does not merely risk a wrong tool result—it risks an agent whose memory of its own actions diverges from the world in a way that is invisible until a downstream reconciliation job fires, typically minutes to hours later, at which point the agent has built several planning cycles on the false premise. The guardrail is a *speculation warrant*: a per-tool attestation that the effect closure is buffered and the idempotency key is attempt-scoped, checked at dispatch time and invalidated whenever the tool's dependency graph changes. Absent a valid warrant, the runtime must fall back to serialized execution and record the fallback in memory as "deferred," not "not attempted," so the planner's premise remains sound. ```python from dataclasses import dataclass class SpeculationWarrantError(RuntimeError): """Raised when a tool is speculatively dispatched without a closure-complete warrant.""" @dataclass(frozen=True) class SpeculationWarrant: tool: str closure_buffered: bool key_attempt_scoped: bool dependency_hash: str def dispatch_speculative(tool: str, args: dict, warrant: SpeculationWarrant, current_dep_hash: str, attempt_key: str) -> dict: # Invariant 1: the tool's full effect closure must be buffered. if not warrant.closure_buffered: raise SpeculationWarrantError( f"tool {tool!r} has unbuffered effects in its closure; " "speculative dispatch would leak past abort" ) # Invariant 2: idempotency keys must be attempt-scoped, never logical-op-scoped, # or an aborted speculation poisons the dedup window for the committed retry. if not warrant.key_attempt_scoped: raise SpeculationWarrantError( f"tool {tool!r} uses a logical-operation idempotency key; " "aborted speculation would masquerade as prior success" ) # Invariant 3: warrants are invalidated when the tool's dependency graph changes. if warrant.dependency_hash != current_dep_hash: raise SpeculationWarrantError( f"warrant for {tool!r} is stale: dependency graph changed " f"({warrant.dependency_hash} -> {current_dep_hash})" ) return {"tool": tool, "args": args, "attempt_key": attempt_key, "status": "buffered_pending_commit"} def commit_or_abort(dispatched: dict, authorized: bool) -> str: if not authorized: # Memory plane must record "deferred", never "not attempted", # so the planner's next premise stays sound. return "aborted_recorded_as_deferred" return "committed" ```