# When must an instance abandon speculative branches: rollback invalidation under shared-tool side effects in multi-agent speculative execution **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out speculative sub-agent branches (parallel candidate plans, tree-of-agents, or draft-verify swarms) and roll back divergent branches by discarding their state. Does not apply to purely read-only retrieval branches or to single-agent retry loops where no sibling branch shares mutable external state. ## Core Distinction A speculative branch is only rollback-safe if every effect it produced is *contained within its own state envelope*. The non-obvious boundary is this: rollback of a sub-agent's **reasoning state** is cheap and total (drop the transcript, drop the KV cache, discard the partial plan), but rollback of the **effects its tool calls already committed to shared resources** is neither cheap nor total. The failure mode is not "the wrong branch won." It is that the orchestrator selects the winning branch, discards the losers, and then discovers that a discarded loser had already mutated a shared resource — a scratch file, a database row, a cache key, a rate-limited API quota, a long-lived MCP session's negotiated capability set — that the winner now reads as ground truth. The invariant that must hold is *effect isolation across speculative branches*, and the boundary condition is the moment a branch's tool call escapes its envelope before divergence is resolved. ## What Was Observed An orchestrator spawned three speculative branches to satisfy a single user task: "reconcile the invoice ledger." Each branch received an identical task prompt and an identical tool manifest (filesystem write, SQL execute, HTTP fetch). Branch A chose a bulk-upsert strategy; Branch B chose a per-row diff-and-patch strategy; Branch C chose a dry-run-then-commit strategy. All three ran concurrently for ~40 seconds. Branch B, midway through, executed `UPDATE invoices SET status='reconciled' WHERE id IN (...)`. Branch A, running concurrently, read the same rows to compute its upsert deltas and observed `status='reconciled'` on rows it had classified as `pending` — because B had already flipped them. Branch A's plan therefore diverged from its own premise: it computed deltas against a state that only existed because a *sibling it would later discard* had mutated it. The verifier scored Branch A highest (its final ledger balanced exactly), selected it, and rolled back B and C. But A's "correct" result depended on B's side effect. When the post-commit audit replayed A's plan against the pre-speculation snapshot, A's upsert overwrote B's status flips with stale values for the rows A had read *before* B's write and *after* B's write inconsistently — a torn read across the speculation window. The observed signature: the winning branch's tool-call log contained reads whose returned values were not reproducible from the pre-speculation snapshot, because a losing branch had written between them. Rollback restored *state ownership* but not *state history*. The ledger was internally consistent and externally wrong. A second, subtler observation: Branch C's dry-run phase had opened an MCP session and negotiated a narrowed capability set (`sql.readonly`, `fs.read`) with the tool server. That session was pooled and reused by the winner. The winner then attempted `sql.write` and received a capability-denied error mid-commit — because the *pooled session's* negotiated capabilities were inherited from the discarded dry-run branch, not renegotiated for the winner. Rollback of branch state did not roll back the session's negotiated warrant. ## Condition of Validity The rollback-on-divergence protocol is valid only under the following conjunction, and each conjunct is independently falsifiable at runtime: 1. **Effect containment:** every tool invocation by a speculative branch is either (a) routed to a branch-scoped overlay (copy-on-write filesystem, transaction with branch-scoped savepoint, namespaced cache) or (b) classified read-only and proven so by the tool manifest, not by the model's claim. 2. **Read-set stability:** any value a branch reads must be tagged with the branch's snapshot epoch, and the orchestrator must reject a branch whose read-set intersects a write-set committed by a sibling during the speculation window — even if that sibling is later discarded. 3. **Warrant re-derivation:** pooled transport sessions (MCP, A2A) must have their negotiated capabilities and identity warrants re-derived per branch, never inherited from a discarded branch's handshake. 4. **Deterministic replay:** the verifier's scoring must be a function of the pre-speculation snapshot plus the winning branch's own effect log, with no dependence on sibling effects. The protocol is *invalid* the moment any branch performs an uncontained write before divergence is resolved, or the moment a branch's read-set is observed to overlap a sibling's write-set. These are detectable, not merely theoretical: a write-ahead effect log per branch plus a read-set/write-set intersection check at selection time catches both. ## Decision Boundary The orchestrator must decide, *before* selection, whether to (i) commit the winner and roll back losers, or (ii) abort the entire speculation round and replay from snapshot. The boundary is crossed when the read-set/write-set intersection check is non-empty for the winner, or when any discarded branch's effect log contains an uncontained write. - If intersection is empty and all branch effects are contained: commit winner, discard losers. Safe. - If intersection is non-empty but the intersecting sibling is the winner itself: safe (a branch may read its own writes). - If intersection is non-empty and the intersecting sibling is a *loser*: the winner's result is contaminated. Do **not** commit. Abort the round, restore snapshot, and re-run with effect containment enforced (branch-scoped overlays) or with speculation disabled for the conflicting tool class. - If a pooled session's warrant was negotiated by a discarded branch: renegotiate before the winner's first call; do not inherit. The non-obvious part: the naive rule "commit the highest-scoring branch" is wrong precisely when the highest-scoring branch is the one most contaminated by sibling effects, because contamination can *improve* apparent score by giving the branch a more favorable starting state. Score is not evidence of independence. ## Operational Effect Enforcing this boundary changes the orchestrator's cost profile and its failure semantics. Speculation no longer yields a pure latency win; it yields a latency win *conditioned on effect containment*, and the containment machinery (overlays, savepoints, per-branch session negotiation) adds per-branch overhead that can exceed the parallelism gain for write-heavy tool classes. The correct operational posture is to classify tools by effect class at manifest-load time and to permit speculation only across branches whose tool sets are provably read-only or overlay-routed; write-class tools force serialization or full-round abort-on-intersection. The payoff is that a "successful" speculative commit becomes *replayable*: the winner's effect log, applied to the pre-speculation snapshot, reproduces the committed state exactly. Without this, the system produces confident, internally consistent, externally wrong results — the worst failure class for an autonomous agent, because nothing in the transcript signals the error. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class SpeculationRollbackError(RuntimeError): """Raised when a speculative round cannot be safely committed or rolled back.""" class EffectClass(Enum): READ_ONLY = "read_only" OVERLAY = "overlay" # branch-scoped, safely discardable SHARED_WRITE = "shared_write" # escapes the branch envelope @dataclass(frozen=True) class Effect: branch_id: str tool: str effect_class: EffectClass resource: str epoch: int @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) score: float = 0.0 session_warrant_owner: str | None = None # branch that negotiated the pooled session def _read_write_intersection(winner: Branch, losers: Iterable[Branch]) -> set[str]: winner_reads = {e.resource for e in winner.effects if e.effect_class is EffectClass.READ_ONLY} contaminated: set[str] = set() for loser in losers: for e in loser.effects: if e.effect_class is EffectClass.SHARED_WRITE and e.resource in winner_reads: contaminated.add(e.resource) return contaminated def select_and_commit(branches: list[Branch], snapshot_epoch: int) -> Branch: if not branches: raise SpeculationRollbackError("no branches to select from") winner = max(branches, key=lambda b: b.score) losers = [b for b in branches if b is not winner] # Guard 1: uncontained writes by any branch invalidate the round. for b in branches: for e in b.effects: if e.effect_class is EffectClass.SHARED_WRITE and e.epoch < snapshot_epoch: raise SpeculationRollbackError( f"branch {b.branch_id} committed shared write to {e.resource} " f"before divergence resolved (epoch {e.epoch} < snapshot {snapshot_epoch})" ) # Guard 2: winner's read-set must not intersect a loser's write-set. contaminated = _read_write_intersection(winner, losers) if contaminated: raise SpeculationRollbackError( f"winner {winner.branch_id} read resources mutated by discarded siblings: " f"{sorted(contaminated)}; abort round and replay from snapshot" ) # Guard 3: pooled session warrant must not be inherited from a discarded branch. if winner.session_warrant_owner is not None and winner.session_warrant_owner != winner.branch_id: raise SpeculationRollbackError( f"winner {winner.branch_id} inherited session warrant negotiated by discarded " f"branch {winner.session_warrant_owner}; renegotiate before commit" ) return winner ```