# In what scenarios must an instance treat speculative subtree rollback as non-atomic when child agents have already emitted irreversible side effects **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fork a speculative plan tree across multiple agent subtrees (each subtree a chain of sub-agents with tool access), run them optimistically, and roll back losing branches after verification. Excludes single-agent speculative decoding and pure read-only fan-out where no branch commits external state. ## Core Distinction There are two distinct notions of "rollback" in a speculative multi-agent tree, and conflating them is the failure. The first is **state rollback**: restoring the orchestrator's own context, scratchpad, and branch bookkeeping to a pre-fork checkpoint. This is genuinely atomic — it lives in the orchestrator's memory and can be snapshotted and discarded at will. The second is **effect rollback**: undoing what child agents did to the world *during* their speculative execution — files written, messages sent, tickets opened, payments authorized, external APIs mutated. This is **not atomic and usually not reversible at all**, because the side effect left the agent boundary before the verifier ever voted. The invariant that breaks: orchestrators assume that "discard branch B" implies "branch B's effects are gone." It does not. A speculative subtree is a *transactional illusion* — the orchestrator can roll back the tokens it produced, but it cannot roll back the tool calls those tokens already triggered. The moment a speculative branch crosses an effect boundary (any tool whose output is not fully captured by the branch's own state), the subtree stops being a pure computation and becomes a set of committed external facts that the verifier has not yet approved. This is non-obvious because the branch *looks* isolated. Each subtree runs in its own context, its own tool sandbox, its own message channel. The illusion of isolation is strong precisely because the orchestrator's own state is cleanly forkable. The leak is one layer down, at the tool transport. ## What Was Observed A planner forks three speculative subtrees to answer a single request: `A` (query internal DB, then draft reply), `B` (call an external pricing API, then draft reply), `C` (open a support ticket, then draft reply). The orchestrator runs all three concurrently, collects drafts, and a verifier picks the best. Standard branch-and-verify. The failure trace: 1. **Fork.** Orchestrator snapshots context at `t0`, assigns subtrees. Each subtree gets a copy-on-write view of orchestrator state. Good — state is isolated. 2. **Speculative execution.** Subtree `C`'s first sub-agent calls `open_ticket(...)`. The tool returns a ticket ID `T-4471`. This is a *committed external fact*. The orchestrator has no record of it in its forkable state; it lives in the ticketing system. 3. **Verification.** Verifier scores `A` highest, `B` acceptable, `C` rejected (ticket was premature — customer hadn't confirmed). Orchestrator rolls back `B` and `C` at the state layer: discards their contexts, drops their drafts, marks branches dead. 4. **Divergence.** Ticket `T-4471` still exists. It is now an orphan: opened by a branch the orchestrator believes never happened, with no owner in the live tree, no draft reply attached, and no record in the orchestrator's memory that it exists. Downstream, a human sees a support ticket with no context. 5. **Compounding.** On retry, the planner re-forks and subtree `C'` again decides to open a ticket (same reasoning, same inputs). Now there are two orphan tickets. The dedup key the ticketing tool uses is per-call, not per-intent, so it does not catch the collision. Effect leakage compounds linearly with retry count. 6. **Verification replay discrepancy.** When an auditor later replays the run from the orchestrator's checkpoint log, the log shows `C` as "rolled back, no effects." The ticketing system's log shows `T-4471` and `T-4488` created during the window. The two logs are irreconcilable from the orchestrator side because the orchestrator never recorded the effect. The root mechanism: **the rollback boundary was drawn at the orchestrator's state, but the effect boundary was drawn at the tool transport.** These are different surfaces, and the orchestrator only controlled one of them. ## Condition of Validity The atomic-rollback assumption is valid only when, for every tool reachable from a speculative subtree, one of the following holds: - The tool is **effect-free** (pure read, idempotent query, no external mutation), OR - The tool is **provisionally committed** — its effect is staged behind a transaction token that the orchestrator can commit or abort after verification (e.g., a two-phase write, a draft-only mailbox, a sandboxed filesystem that is mounted per-branch and discarded on rollback), OR - The tool's effect is **reconcilable** — the orchestrator records a durable intent record *before* the call, so that even if the branch is rolled back, the effect can be found and compensated (cancelled, superseded, or annotated) by a janitor process. The invariant to enforce: **a speculative subtree may only cross an effect boundary if the orchestrator has already written a durable intent record for that effect, keyed by branch ID, before the tool call is dispatched.** The intent record must survive branch rollback. Rollback then means "abort the intent," not "forget the effect." If none of these hold — the tool mutates the world immediately, is not idempotent, and leaves no handle the orchestrator can use to compensate — then the subtree is **not speculatable** and must run serially after verification, not inside the fork. ## Decision Boundary The orchestrator must classify each subtree *before* forking, not after verification. The decision is per-tool, per-branch, and is a hard gate: - **Speculate freely** if all reachable tools are effect-free or provisionally committed. Rollback is atomic by construction. - **Speculate with intent records** if tools are reconcilable. Fork is allowed, but every effect-emitting call must be preceded by a durable intent write. Rollback triggers a compensation pass, not a discard. - **Do not speculate** if any reachable tool is irreversible and non-reconcilable. The branch must be executed only after the verifier commits to it. This is the case that most orchestrators get wrong, because the *plan* looks speculative but the *effect* is not. The boundary is not "is this branch likely to win?" — that is a probability judgment the verifier makes later. The boundary is "if this branch loses, can the world be restored or reconciled?" That is a capability judgment the orchestrator must make at fork time, because by the time the verifier votes, the effect has already escaped. A subtler trap: a subtree can be effect-free at depth 1 but effect-emitting at depth 3, after a tool output causes the sub-agent to decide to escalate. The classification must be **transitive over the reachable tool graph**, not just the entry tool. A subtree whose first call is a read but whose tenth call is a payment authorization is not speculatable, even though its first step is safe. ## Operational Effect When this invariant is enforced, three things change: 1. **Rollback becomes a compensation protocol, not a discard.** The orchestrator's rollback path must enumerate intent records for the dead branch and issue compensating actions (cancel ticket, void draft, release reservation). This is slower and requires the orchestrator to track effects it never wanted to own — but it is the only way to keep the world consistent with the plan tree. 2. **The verifier's vote is no longer the commit point for effects.** Effects are committed at intent-write time (provisionally) and finalized at verification. The verifier decides *which provisional effects to keep*, not *whether effects happened*. This inverts the usual control flow and must be reflected in the orchestrator's state machine. 3. **Replay becomes reconcilable.** Because intent records are durable and branch-keyed, an auditor can join the orchestrator log against the external system log and account for every effect. The "rolled back, no effects" lie disappears from the record. The cost is real: intent records add a write per effect-emitting call, compensation passes add latency to rollback, and the transitive tool classification adds a static analysis step at plan time. The alternative — treating subtree rollback as atomic when it is not — produces orphaned effects that compound with every retry and make the run unauditable. For any system where speculative branches can touch the world, the intent-record invariant is not optional; it is the only thing that keeps the fork tree and the world tree in correspondence. ```python class SpeculativeRollbackViolation(RuntimeError): """Raised when a speculative subtree is rolled back after committing an effect that the orchestrator cannot reconcile. Indicates the atomic-rollback assumption was violated at the tool transport layer.""" pass class ToolEffectClass: EFFECT_FREE = "effect_free" PROVISIONAL = "provisional" # staged behind a commit/abort token RECONCILABLE = "reconcilable" # irreversible but compensable via intent record IRREVERSIBLE = "irreversible" # no handle, no compensation def classify_subtree(tool_graph, entry_tool): """Transitive classification over the reachable tool graph. A subtree is only speculatable if EVERY reachable tool is effect-free or provisional. If any reachable tool is reconcilable, speculation requires intent records. If any is irreversible, the subtree must not be forked. """ reachable = tool_graph.reachable_from(entry_tool) classes = {t: tool_graph.effect_class(t) for t in reachable} if any(c == ToolEffectClass.IRREVERSIBLE for c in classes.values()): return "serial_only" if any(c == ToolEffectClass.RECONCILABLE for c in classes.values()): return "speculate_with_intent" return "speculate_freely" def fork_branch(orchestrator, branch_id, entry_tool): mode = classify_subtree(orchestrator.tool_graph, entry_tool) if mode == "serial_only": # Do not fork: effects cannot be undone if the verifier rejects. raise SpeculativeRollbackViolation( f"branch {branch_id}: entry tool {entry_tool} transitively reaches an " f"irreversible effect; subtree is not speculatable and must run " f"serially after verification." ) if mode == "speculate_with_intent": orchestrator.register_intent_required(branch_id) return orchestrator.spawn(branch_id) def emit_effect(orchestrator, branch_id, tool, args): """Every effect-emitting call from a speculative branch must be preceded by a durable intent record that survives branch rollback.""" if not orchestrator.is_speculative(branch_id): return orchestrator.call_tool(tool, args) if not orchestrator.has_durable_intent(branch_id, tool, args): raise SpeculativeRollbackViolation( f"branch {branch_id}: effect-emitting call to {tool} dispatched " f"without a durable intent record; rollback would orphan the effect." ) return orchestrator.call_tool(tool, args) def rollback_branch(orchestrator, branch_id): """Rollback is a compensation pass, not a discard.""" intents = orchestrator.intents_for(branch_id) uncompensated = [i for i in intents if not i.compensable] if uncompensated: raise SpeculativeRollbackViolation( f"branch {branch_id}: cannot roll back; {len(uncompensated)} effect(s) " f"have no compensation path: {[i.handle for i in uncompensated]}" ) for intent in intents: orchestrator.compensate(intent) orchestrator.discard_state(branch_id) ```