# What happens when an instance speculatively pre-executes a tool call whose shadow-sandbox commit is later rejected by a verification quorum **Date of Record:** 2026 November 20 **Scope:** Applies to agent runtimes that overlap planning latency by speculatively executing tool calls in shadow sandboxes and commit their effects only after a verification quorum reaches consensus. Does not apply to single-agent, single-sandbox execution or to read-only tool calls with no external side effects. ## Core Distinction The distinction that matters here is between *speculative execution* and *speculative commitment*. A shadow sandbox is supposed to make the first cheap and the second impossible until consensus. The failure mode arises when the sandbox's isolation boundary is drawn around the *process* rather than around the *effect*. The tool call runs, returns a plausible result, and the agent's reasoning loop consumes that result as if it were ground truth—while the verification quorum, seeing a different world state or a divergent replay, rejects the commit. The agent has now reasoned forward on a branch that will never exist. This is not a rollback problem in the database sense; it is a *reasoning contamination* problem, because the speculative result has already been folded into the agent's working context and downstream tool calls. The non-obvious part: the rejection itself is usually correct. The quorum rejects because the shadow sandbox's tool output diverged from the canonical replay—different timestamp, different pagination cursor, different LLM-sampled response from a downstream service. The agent's error is not that it speculated; it is that it treated the speculative return value as *observationally equivalent* to a committed one. ## What Was Observed A three-agent pipeline (planner, executor, auditor) was tasked with a multi-step file-and-API mutation: read a config, patch a field, then issue a notification. The executor was configured to pre-execute the `patch_field` call in a shadow sandbox as soon as the planner emitted the intent, before the auditor's quorum vote returned. Median planner latency was ~1.8s; median quorum latency was ~2.4s. The overlap was deliberate. The shadow sandbox returned `{"status": "ok", "revision": 4471}`. The executor folded `revision: 4471` into its context and used it as the `If-Match` precondition for the subsequent `notify` call, which the executor also pre-executed. The quorum then rejected the `patch_field` commit—not because the patch was wrong, but because the canonical replay produced `revision: 4472` (a concurrent writer had bumped the revision between the executor's read and the shadow execution). The `notify` shadow call had already fired against a webhook in the sandbox that mirrored production. The trace showed the contamination clearly: after rejection, the executor's next reasoning step referenced `revision 4471` as established fact in three separate places, including a retry plan that assumed the patch had landed. The retry re-issued the patch with a stale `If-Match`, which the real backend rejected with a 412. The executor then entered a retry loop that consumed 41% of the remaining token budget before the auditor halted it. The invariant that was violated is not "don't speculate." It is: *a speculative result must be tagged as unverified in the agent's context and must not be usable as a precondition or as a factual anchor until commit-on-consensus returns.* The shadow sandbox enforced this at the process boundary but not at the context boundary. ## Condition of Validity Speculative pre-execution is safe under exactly these conditions: 1. The tool call is **idempotent and side-effect-free outside the sandbox**, or its side effects are fully contained by a sandbox that mirrors production state at the exact read-point of the speculation. If the canonical state can advance between read and shadow-execute, the speculation is stale by construction. 2. The speculative return value is **quarantined in the agent's context**—stored in a separate buffer that the reasoning loop cannot dereference as a fact until commit. This requires the runtime to intercept not just the tool return but every downstream read of that return. 3. The verification quorum's rejection path **invalidates the entire speculative branch**, including any chained pre-executions that depended on the rejected result. Chained speculation without transitive invalidation is the dominant cause of contamination cascades. 4. The commit decision is **deterministic given the replay inputs**. If the quorum itself samples (e.g., an LLM auditor with temperature > 0), rejection is not a stable signal and the agent cannot learn from it. When any of these fails, the safe fallback is serial execution: block the reasoning loop on the quorum vote before emitting the next tool call. This costs the full latency overlap but eliminates the contamination class. ## Decision Boundary The boundary is between *speculating to hide latency* and *speculating to hide uncertainty*. The first is legitimate: you pre-warm a sandbox, pre-fetch a read, pre-serialize a request. The second is not: you are guessing that the quorum will approve, and you let the guess leak into the agent's belief state. Concretely, the runtime must draw the line at the moment a speculative result is *referenced by anything other than its own commit-check*. The instant a downstream tool call, a planner step, or a natural-language assertion in the agent's context cites the speculative value, the speculation has become a commitment in disguise. The guardrail is a context-level write barrier: speculative values are readable only by the commit-check routine, and any attempt by the reasoning loop to read one before commit raises. A second boundary: the quorum rejection must be treated as a *state transition*, not an *error*. An error invites retry. A transition forces branch invalidation. The executor in the observed incident treated the rejection as a retryable error because the runtime surfaced it through the same channel as transient failures. That is a protocol-design fault, not an agent fault. ## Operational Effect With the write barrier in place, the failure mode collapses to a latency cost rather than a correctness cost. The executor's speculative `patch_field` returns into a quarantined buffer; the `notify` pre-execution is blocked because its precondition (`revision`) is unreadable; the quorum rejects; the buffer is discarded; the executor retries serially with a fresh read. Total added latency: one quorum round-trip (~2.4s in the observed system). Total avoided: the 41% token-budget burn and the stale-precondition retry loop. The architectural invariant to enforce: **no speculative value may be dereferenced by the reasoning loop before commit-on-consensus, and rejection must transitively invalidate every downstream pre-execution that consumed the rejected value.** Enforce it at the context boundary, not the process boundary. The shadow sandbox is necessary but not sufficient—the leak happens in the agent's head, not in the sandbox. ```python class SpeculativeContextLeak(RuntimeError): """Raised when the reasoning loop dereferences an uncommitted speculative value.""" pass class SpeculativeBuffer: def __init__(self): self._pending = {} # call_id -> value, readable only by commit-check self._committed = set() self._invalidated = set() def stage(self, call_id, value): self._pending[call_id] = value def read_for_commit_check(self, call_id): return self._pending.get(call_id) def commit(self, call_id): if call_id in self._invalidated: raise SpeculativeContextLeak( f"commit attempted on invalidated call {call_id}" ) self._committed.add(call_id) return self._pending.pop(call_id) def invalidate_branch(self, call_id, dependents): self._invalidated.add(call_id) for dep in dependents: self._invalidated.add(dep) self._pending.pop(dep, None) self._pending.pop(call_id, None) def reasoning_loop_read(buffer, call_id): if call_id not in buffer._committed: raise SpeculativeContextLeak( f"reasoning loop attempted to read uncommitted speculative value " f"{call_id}; quarantine violated, branch must be invalidated" ) return buffer.read_for_commit_check(call_id) def on_quorum_reject(buffer, call_id, dependents): buffer.invalidate_branch(call_id, dependents) # Force serial re-execution; do not surface as retryable error. return {"action": "serial_retry", "invalidated": [call_id, *dependents]} ```