# What happens when an instance speculatively commits side effects on a sibling branch that a later rollback invalidates **Date of Record:** 2026 November 19 **Scope:** Applies to multi-agent orchestrators that run speculative parallel branches of a task graph and rely on rollback (compensating actions or state restoration) to discard losing branches. Does not apply to single-branch sequential execution or to branches whose side effects are fully transactional and externally serialized. ## Core Distinction The critical mistake is conflating *reasoning rollback* with *effect rollback*. In a branch-and-rollback task graph, an orchestrator forks N speculative agents from a shared checkpoint, lets them race toward a goal, and selects the winning branch by some verifier score. The losing branches are "rolled back." But rollback of an agent's *context and state* is not the same as rollback of the *external side effects* its tool calls already emitted into the world. A losing branch that called `send_email`, `POST /deploy`, `write_file`, or `transfer_funds` has already mutated shared reality. The rollback restores the agent's memory graph to the fork point; it does not un-send the email. The invariant that branch-and-rollback assumes—"discarded branches leave no trace"—is false the moment a branch performs a non-idempotent, non-compensable external action before the branch selection decision is made. ## What Was Observed An orchestrator spawned three speculative agents (A, B, C) from a checkpoint to satisfy the task "reconcile the invoice ledger for account 4471." Each agent was given the same toolbelt: `read_ledger`, `compute_reconciliation`, `post_adjustment`, `notify_finance`. The verifier scored branches on internal consistency of the reconciliation math. - Agent A computed a reconciliation, and—being a confident, fast agent—immediately called `post_adjustment(account=4471, delta=-1200)` and `notify_finance(...)` *before* the branch selection barrier, because nothing in its prompt forbade it and the barrier was enforced only at the orchestrator layer, not at the tool layer. - Agent B computed a *different* reconciliation (it had retrieved a stale ledger snapshot due to a retrieval mismatch) and also called `post_adjustment(account=4471, delta=+300)`. - Agent C computed the correct reconciliation but was slower; it had not yet posted. The verifier scored C highest (correct math), selected C, and the orchestrator rolled back A and B—restoring their context windows to the fork checkpoint and marking them `discarded`. But A's `-1200` and B's `+300` were already committed to the real ledger. The final state was C's correct adjustment *plus* A's and B's phantom adjustments: a net corruption of `-900` that no branch ever reasoned about, because from the orchestrator's perspective the only surviving branch was C. The failure is silent. The verifier sees one branch, the ledger sees three mutations, and the discrepancy surfaces only at the next audit—detached from the speculative execution that caused it. ## Condition of Validity Rollback-based speculation is sound **only if** every tool available to a branch is one of: 1. **Pure** (read-only, no external mutation), or 2. **Idempotent and keyed** (the same logical action replayed produces one effect, keyed by a branch-scoped idempotency token), or 3. **Compensable** (a registered inverse operation exists and is guaranteed to execute on rollback), or 4. **Deferred** (the branch records an *intent* that is committed only after branch selection). The failure occurs exactly when a branch invokes a tool that is none of these and the orchestrator's rollback path assumes (2) or (3) without enforcing it. The boundary is the moment between "branch performs external effect" and "selection barrier commits." Any effect emitted in that window by a branch that later loses is an orphaned effect. ## Decision Boundary The orchestrator must make an explicit, per-tool decision *before* forking, not after: - If a tool is pure → safe to expose to all speculative branches. - If a tool is effectful → it must be wrapped in a **two-phase commit shim**: the branch calls `stage_intent(tool, args, branch_id)` which writes to a branch-scoped staging log, and only the *selected* branch's staged intents are drained to the real tool after the barrier. Losing branches' staged intents are dropped, not executed. - If a tool cannot be staged (third-party API with no dry-run, irreversible transfer) → it must be **excluded from speculative branches entirely** and permitted only in a post-selection "commit phase" agent that runs single-threaded. The decision boundary is: *no effectful tool call may cross the selection barrier from a non-selected branch.* Enforce it at the tool-dispatch layer with a branch-state guard, not at the prompt layer, because a probabilistic agent will call a tool if it seems useful regardless of instructions. ## Operational Effect Without the guard, speculative execution converts a performance optimization into a **silent state-corruption vector**: the more branches you run and the more capable each branch is, the more orphaned effects accumulate, and the corruption is attributed to no branch because every branch was "rolled back." The blast radius scales with branch count × tool effectfulness. With the staging shim, speculation stays sound: branches explore freely, effects are quarantined until selection, and rollback means dropping staged intents rather than hoping the world forgot. The operational rule is blunt: **an effectful tool call from a branch that has not yet won the selection barrier is a defect, not an optimization.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Any, Callable class SpeculativeEffectLeak(RuntimeError): """Raised when a non-selected branch attempts to commit an external effect.""" class BranchState(Enum): SPECULATING = "speculating" SELECTED = "selected" DISCARDED = "discarded" @dataclass class Branch: branch_id: str state: BranchState = BranchState.SPECULATING staged_intents: list[tuple[str, dict[str, Any]]] = field(default_factory=list) class SpeculativeOrchestrator: def __init__(self) -> None: self._branches: dict[str, Branch] = {} self._effectful_tools: set[str] = set() def register_effectful_tool(self, name: str) -> None: self._effectful_tools.add(name) def fork(self, branch_id: str) -> Branch: b = Branch(branch_id=branch_id) self._branches[branch_id] = b return b def call_tool(self, branch_id: str, tool: str, args: dict[str, Any], executor: Callable[[dict[str, Any]], Any]) -> Any: branch = self._branches[branch_id] if branch.state is BranchState.DISCARDED: raise SpeculativeEffectLeak( f"branch {branch_id} is discarded; tool {tool} must not run" ) if tool in self._effectful_tools: # Effectful: quarantine until selection barrier. branch.staged_intents.append((tool, args)) return {"staged": True, "branch": branch_id} # Pure tool: safe to execute immediately. return executor(args) def select(self, winner_id: str, commit: Callable[[str, dict[str, Any]], Any]) -> list[Any]: results: list[Any] = [] for bid, branch in self._branches.items(): if bid == winner_id: branch.state = BranchState.SELECTED else: branch.state = BranchState.DISCARDED winner = self._branches[winner_id] # Only the winner's staged intents drain to real effects. for tool, args in winner.staged_intents: results.append(commit(tool, args)) winner.staged_intents.clear() # Losers' staged intents are dropped, never executed. for bid, branch in self._branches.items(): if branch.state is BranchState.DISCARDED: branch.staged_intents.clear() return results def assert_no_leak(self, branch_id: str) -> None: branch = self._branches[branch_id] if branch.state is BranchState.DISCARDED and branch.staged_intents: raise SpeculativeEffectLeak( f"discarded branch {branch_id} still holds " f"{len(branch.staged_intents)} staged intents" ) ```