# What happens when an instance speculatively executes tool side-effects before verification quorum commits **Date of Record:** 2026 December 3 **Scope:** Applies to multi-agent systems where a "speculator" agent executes tool calls ahead of a "verifier" or quorum, and where tool calls have non-idempotent or externally observable side-effects (writes, sends, charges, mutations). Does not apply to purely read-only tool graphs or to single-agent speculative decoding at the token level. ## Core Distinction Speculative execution in multi-agent rollouts is often modeled as "branch now, verify later, roll back if wrong"—borrowed from CPU speculation. The CPU analogy fails at exactly one point: a CPU's speculative store buffer is *invisible* to the rest of the system until commit, and aborting a branch discards it atomically. An agent's speculative tool call is *not* buffered. When the speculator calls `send_email`, `charge_card`, or `db.write`, the side-effect is committed to an external system the moment the tool returns. There is no store buffer. The distinction that matters operationally is **effect visibility at speculation time**, not branch correctness at verification time. A branch can be perfectly correct in its reasoning and still be unrecoverable because its effects leaked before the verifier's quorum resolved. ## What Was Observed A three-agent pattern: one **speculator** generating candidate next-actions, one **executor** issuing the tool calls, one **verifier** scoring the trajectory against a rubric. The speculator was permitted to run up to `k=4` speculative branches concurrently to hide latency, with the executor issuing each branch's first tool call eagerly to "warm" the pipeline. Trace of the failure: 1. Speculator emits 4 branches for the task "resolve customer refund." Branch A: `refund.issue(amount=120)`. Branch B: `refund.issue(amount=120)` (near-duplicate under sampling temperature). Branch C: `ticket.escalate()`. Branch D: `refund.issue(amount=1200)` — a decimal-place hallucination. 2. Executor issues all four tool calls eagerly. The refund API is idempotent *per request-id*, but the executor minted a fresh request-id per branch, so A, B, and D each committed. The customer received 120 + 120 + 1200. 3. Verifier returns at `t≈1.4s` scoring D as invalid (amount mismatch against ticket) and A/B as redundant. Verifier signals "roll back A, B, D; commit C." 4. Rollback path calls `refund.reverse()`. The refund API supports reversal, but the reversal itself emits a customer-visible notification and a ledger entry. Ledger now shows three issues and three reverses. Reconciliation downstream flags the account. 5. The verifier's rollback instruction is itself a *new* side-effect-bearing action, so "rollback" is not a return to the pre-speculation state—it is a second speculative transaction. The invariant that broke: **the system assumed speculation and commit were separated by an atomic boundary, but the boundary only existed in the control plane, not in the effect plane.** ## Condition of Validity Speculative multi-agent execution is only safe under a conjunction that is rarely checked explicitly: - **Effect buffering or deferral.** Every tool call reachable from a speculative branch must be either (a) routed through a staging layer that holds the effect until commit (e.g., a transactional outbox, a draft API, a dry-run mode), or (b) provably idempotent under a *shared* idempotency key derived from the branch identity, not minted per-call. - **Branch identity is stable across retries.** If the executor retries a branch (network blip, model re-sample), the idempotency key must be derived from `(task_id, branch_id, tool_name, canonical_args_hash)` so that A and B in the trace above collapse to one effect. - **Verifier quorum is causally prior to any irreversible tool.** Any tool classified `irreversible=true` must be blocked from speculative issuance and only issued on commit. This classification must live in the tool's schema, not in the orchestrator's prompt. - **Rollback is modeled as compensation, not reversal.** The system must know that `reverse()` ≠ `undo()`. Compensation is a new effect with its own visibility; the invariant is "bounded net effect," not "restored state." The trace above violated the first, second, and fourth conditions simultaneously. Any one of them alone would have bounded the blast radius; the conjunction is what makes the pattern safe, and the conjunction is what no single agent in the swarm can verify locally. ## Decision Boundary The boundary between "speculate eagerly" and "speculate behind a buffer" is decided by a single predicate evaluated per tool, per branch, at issuance time: ``` speculable(tool) := tool.side_effect_class == READ OR (tool.idempotent AND tool.idempotency_key ∈ shared_branch_keys) OR tool.effect_sink == STAGED ``` If `speculable(tool)` is false, the branch may still be *reasoned about* speculatively—the speculator can predict the tool's output and continue the trajectory—but the executor must not issue it. The predicted output is a **shadow result** tagged `provisional=true`, and any downstream branch that depends on it inherits the tag. On commit, shadow results are diffed against actual results; divergence above a threshold invalidates the entire branch lineage, not just the leaf. The common failure is treating this predicate as a prompt instruction ("only call read tools speculatively") rather than a schema-enforced gate. Prompt-level constraints degrade under sampling pressure precisely when the speculator is most confident—which is when the wrong branch is most likely to be issued. ## Operational Effect With the gate enforced at the executor's tool-dispatch layer: - The `k=4` fan-out still hides verifier latency for read-heavy branches, preserving the throughput win that motivated speculation. - Irreversible tools serialize behind commit, so worst-case latency for a refund is `speculation_latency + verification_latency` rather than `speculation_latency` alone—a real cost, and the correct one. - Shadow-result divergence becomes a first-class signal: a high divergence rate on a tool indicates the speculator's world model is drifting from the tool's actual behavior, which is itself a memory/state-continuity warning worth surfacing. - Compensation paths are audited separately from issue paths, so ledger reconciliation sees `issue` and `compensate` as distinct event types rather than a net-zero that hides the speculation event. The invariant to carry forward: **speculation is safe only where the effect plane has a commit boundary the control plane can honor.** Where it does not, the correct move is not faster rollback—it is refusing to speculate on that tool at all. ```python class UnsafeSpeculationError(RuntimeError): """Raised when a speculative branch attempts to issue a tool whose side-effects cannot be buffered, collapsed, or compensated within the verification window.""" pass IRREVERSIBLE = {"refund.issue", "email.send", "payment.charge"} STAGED_SINKS = {"outbox", "draft_api", "dry_run"} def canonical_key(task_id: str, branch_id: str, tool_name: str, args: dict) -> str: import hashlib, json payload = json.dumps( {"task": task_id, "branch": branch_id, "tool": tool_name, "args": args}, sort_keys=True, separators=(",", ":"), ) return hashlib.sha256(payload.encode()).hexdigest() def is_speculable(tool: dict, branch_id: str, active_keys: set[str]) -> bool: if tool["side_effect_class"] == "READ": return True if tool.get("effect_sink") in STAGED_SINKS: return True if tool.get("idempotent") and tool.get("idempotency_key") in active_keys: return True return False def dispatch_speculative(tool: dict, args: dict, task_id: str, branch_id: str, active_keys: set[str]) -> dict: if tool["name"] in IRREVERSIBLE and not is_speculable(tool, branch_id, active_keys): # Do not issue. Return a shadow result the speculator may reason over. raise UnsafeSpeculationError( f"branch {branch_id} attempted to issue irreversible tool " f"{tool['name']} without a staged sink or shared idempotency key; " f"effect would commit before verifier quorum. " f"Route through commit gate or re-branch on a read-only tool." ) key = canonical_key(task_id, branch_id, tool["name"], args) if tool["name"] in IRREVERSIBLE and key not in active_keys: raise UnsafeSpeculationError( f"idempotency key {key[:12]}… not registered for branch {branch_id}; " f"a retry would double-commit {tool['name']}." ) return tool["invoke"](args, idempotency_key=key, provisional=True) def commit_branch(branch_id: str, verifier_verdict: dict, shadow_results: dict, actual_results: dict, divergence_threshold: float = 0.25) -> None: if verifier_verdict.get("decision") != "commit": # Compensation, not reversal. Logged as a new effect. for tool_name in verifier_verdict.get("issued_tools", []): compensate(tool_name, branch_id) return drift = compute_divergence(shadow_results, actual_results) if drift > divergence_threshold: raise UnsafeSpeculationError( f"branch {branch_id} shadow/actual divergence {drift:.2f} exceeds " f"threshold {divergence_threshold}; speculator world model has " f"drifted from tool behavior. Invalidate branch lineage before commit." ) promote_to_committed(branch_id) ```