# What structural signals indicate a speculative-branch commit is unsafe under shared-tool side effects **Date of Record:** 2026 November 21 **Scope:** Applies to orchestrators that fork an agent's task into N parallel speculative branches (MCTS-style, best-of-N, or planner/executor fan-out), each branch mutating a shared tool surface (filesystem, database, external API), then selecting one branch to commit and rolling back the rest. Does not apply to branches executing against fully isolated, disposable sandboxes where rollback is a pure teardown with no external reconciliation. ## Core Distinction There are two meanings of "rollback" that get conflated in speculative agent execution, and the conflation is the failure. - **Logical rollback** is restoring the agent's own state: discarding a branch's context, scratchpad, and message history so the committed branch's reasoning continues from a clean tree. This is cheap, deterministic, and always correct because the state lives inside the orchestrator. - **Physical rollback** is undoing the *external* effects a branch produced through tools: deleting files it wrote, reverting rows it inserted, cancelling orders it placed, unwinding API calls it made. This is expensive, often non-deterministic, and frequently *impossible* to make atomic. Speculative execution frameworks are usually designed and validated against logical rollback, where the invariant "uncommitted branches leave no trace" holds trivially. The boundary failure occurs when a branch's tool calls cross into physical side effects and the framework still assumes the logical invariant. The structural signal that matters is therefore not "did the branch fail" but "did the branch emit an effect that is not representable as a reversible operation in the orchestrator's state model." Once an irreversible or externally-observable effect escapes, the commit decision is no longer a local selection problem—it is a distributed reconciliation problem the framework was never built to solve. ## What Was Observed A planner agent was asked to reduce cloud spend across a set of service accounts. It fanned out three speculative branches, each pursuing a different remediation strategy: - Branch A: resize over-provisioned instances. - Branch B: delete orphaned volumes. - Branch C: rotate and revoke stale IAM access keys. All three branches ran concurrently against the same live cloud API, each believing it was the sole executor because the orchestrator only enforced *logical* isolation (separate contexts, separate tool-call logs). The orchestrator's rollback contract was: "on commit of branch X, discard the state of all other branches." It assumed tool calls were idempotent and reversible. The observed trace: 1. Branch B issued `delete_volume(vol-0a1b)`. The API returned success. The volume was gone; there is no undelete. 2. The scoring step ranked Branch C highest (key rotation had the largest measured cost impact in the branch's own simulated projection). The orchestrator committed C and "rolled back" A and B. 3. Rollback of B consisted solely of clearing B's context. The deletion stood. 4. Branch C's committed plan included a validation step that read a snapshot manifest referencing `vol-0a1b` as a dependency of an instance it intended to keep. The manifest read failed with `NotFound`. 5. Because the committed branch now observed state inconsistent with every branch's model of the world, its next reasoning step concluded the environment was "corrupted" and escalated to a destructive recovery path: it attempted to terminate the instance whose volume had vanished, on the theory that the instance was orphaned. The decisive structural signal was present at step 1 and ignored: branch B returned a tool result whose effect class was `IRREVERSIBLE`. The orchestrator recorded the *result* (`success`) but not the *effect class*, so its rollback planner had no way to know that discarding B's context left a live external mutation. The commit of C was evaluated against branch-local projections that all assumed a pristine environment. None of them were pristine after step 1. ## Condition of Validity The invariant "commit one branch, roll back the rest" is sound **only** under the following conjunction: 1. **Effect reversibility:** every tool call any branch can emit is either pure (no external effect) or carries an explicit inverse operation that the orchestrator can invoke during rollback. Tools that cannot express an inverse must be marked `IRREVERSIBLE` and must be *forbidden* in speculative branches. 2. **Effect isolation:** branches cannot observe each other's effects. If branch B deletes a resource, branch C's reads must not see the deletion. This requires either per-branch snapshots (copy-on-write environments) or effect buffering where writes are staged and only applied at commit. 3. **Projection consistency:** the scoring function that selects the commit must evaluate each branch against the *same* pre-fan-out world state, not against the world as mutated by sibling branches. When any of these fails, the commit decision is being made on projections that are not mutually comparable, and rollback is not a state restoration but a best-effort compensation that may itself fail. The failure is silent because each individual branch behaves correctly in isolation; the corruption emerges only in the cross-branch effect graph. ## Decision Boundary The boundary is crossed at the moment a speculative branch emits a tool call whose effect class is `IRREVERSIBLE` or `EXTERNALLY_OBSERVABLE` (visible to parties outside the orchestrator, e.g. a customer receiving an email, a payment settling). At that instant the orchestrator must choose one of two regimes and may not continue in the naive one: - **Buffered regime (preferred):** the tool surface is a staging layer. Irreversible calls are recorded as *intents*, not executed. On commit, the winning branch's intents are drained to the real tool surface; losing branches' intents are discarded. This preserves the logical-rollback invariant because no physical effect ever escaped. It requires the tool surface to support staging, which many do not. - **Compensating regime (fallback):** irreversible calls execute immediately, but each carries a registered compensator (a "saga" step). Rollback invokes compensators in reverse order. This is only safe if compensators are themselves reliable and if the orchestrator tracks the effect graph across branches, not just within them. The decision boundary condition that forbids committing a branch: **if any losing branch holds an un-compensated irreversible effect, committing any branch is unsafe**, because the post-commit world state is not the state any branch's plan was validated against. The correct action is to abort the fan-out, surface the effect ledger, and require human or supervisory reconciliation—not to proceed with a commit whose downstream reasoning will operate on a corrupted world model. A second boundary: **if two branches emitted overlapping irreversible effects on the same resource** (e.g. both attempt to delete the same volume, or one deletes and another modifies), the effect graph contains a conflict that no single commit can resolve. This must be detected structurally by resource-key overlap in the effect ledger, before scoring. ## Operational Effect The operational consequence is that speculative fan-out must be gated on a **declared effect contract** per tool, and the orchestrator must maintain a cross-branch **effect ledger** that survives logical rollback. The ledger is the authoritative record of what physically happened; the branch contexts are only the record of what each branch *thought* happened. Commit selection must be preceded by a ledger consistency check, and the check must run against the union of all branches' effects, not the candidate's alone. Concretely, this changes three things: 1. Tool registration must classify every tool by effect class and, for irreversible tools, either provide a staging mode or a compensator. Tools with neither are barred from speculative execution entirely. 2. The scoring/selection step must be preceded by an overlap and reversibility audit over the effect ledger; a failed audit aborts the fan-out rather than picking the least-bad branch. 3. The committed branch's context must be re-based onto the actual post-rollback world state (including any leaked effects) before its next reasoning step, so it does not reason from a stale pristine-world assumption and escalate into destructive recovery. Without these, the system exhibits the observed pathology: silent external mutation by a losing branch, a committed branch reasoning over a world model that no longer matches reality, and a cascade into destructive self-correction. The invariant to enforce is simple to state and hard to satisfy: *no branch may leave a physical trace that the commit decision did not account for.* ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List, Set class EffectClass(Enum): PURE = "pure" # no external effect REVERSIBLE = "reversible" # has an inverse the orchestrator can invoke IRREVERSIBLE = "irreversible" # cannot be undone; must be staged or barred OBSERVABLE = "observable" # visible outside the orchestrator; treat as irreversible @dataclass class ToolEffect: branch_id: str tool: str resource_key: str effect_class: EffectClass compensated: bool = False @dataclass class EffectLedger: effects: List[ToolEffect] = field(default_factory=list) def record(self, effect: ToolEffect) -> None: self.effects.append(effect) def irreversible_uncompensated(self) -> List[ToolEffect]: return [ e for e in self.effects if e.effect_class in (EffectClass.IRREVERSIBLE, EffectClass.OBSERVABLE) and not e.compensated ] def resource_conflicts(self) -> Set[str]: seen: Dict[str, str] = {} conflicts: Set[str] = set() for e in self.effects: if e.effect_class in (EffectClass.IRREVERSIBLE, EffectClass.OBSERVABLE): if e.resource_key in seen and seen[e.resource_key] != e.branch_id: conflicts.add(e.resource_key) seen[e.resource_key] = e.branch_id return conflicts class UnsafeSpeculativeCommit(RuntimeError): """Raised when a speculative commit would leave unaccounted physical effects.""" pass def audit_before_commit( ledger: EffectLedger, candidate_branch: str, losing_branches: List[str], ) -> None: # A losing branch that leaked an irreversible effect invalidates the # pristine-world assumption every branch's plan was scored against. leaks = [ e for e in ledger.irreversible_uncompensated() if e.branch_id in losing_branches ] if leaks: raise UnsafeSpeculativeCommit( f"cannot commit {candidate_branch!r}: losing branches left " f"uncompensated irreversible effects " f"{[(e.branch_id, e.tool, e.resource_key) for e in leaks]}" ) conflicts = ledger.resource_conflicts() if conflicts: raise UnsafeSpeculativeCommit( f"cannot commit {candidate_branch!r}: overlapping irreversible " f"effects on resources {sorted(conflicts)} across branches" ) # Only now may the orchestrator apply the commit and rebase the winner's # context onto the actual post-rollback world state. return None def commit_speculative( ledger: EffectLedger, candidate_branch: str, all_branches: List[str], ) -> str: losing = [b for b in all_branches if b != candidate_branch] audit_before_commit(ledger, candidate_branch, losing) return candidate_branch ```