# What happens when an instance speculatively executes a branch, commits an irreversible tool side effect, and then loses the merge race **Date of Record:** 2026 November 20 **Scope:** Applies to multi-agent systems that fork task graphs into speculative branches to reduce wall-clock latency, invoke tools optimistically before the branch is known to be mergeable, and roll back losing branches on merge. Does not apply to strictly sequential single-agent execution or to systems where every tool call is transactional and externally reversible. ## Core Distinction There are two distinct meanings of "rollback" that speculative agent execution conflates at its peril. **State rollback** is the cheap operation: discard the branch's context window, episodic buffer, scratchpad, and pending plan node. **Effect rollback** is the expensive operation: undo what the branch actually did to the world — the file it wrote, the ticket it filed, the payment it authorized, the message it sent. A branching task graph treats these as the same operation because both are modeled as "abort the branch." They are not the same operation. Speculative execution is only sound when every tool invocation reachable from a speculative branch is either (a) idempotent and reversible, or (b) deferred until the branch wins the merge. The failure mode this record documents is the case where a branch invokes an optimistic, irreversible tool, then loses the merge race to a sibling branch — leaving an orphaned side effect that no branch owns and no rollback path can reach. ## What Was Observed A planner agent decomposed a "reconcile customer records" task into two speculative branches to hedge against an ambiguous identity match: - **Branch A** hypothesized the customer was a duplicate and invoked `merge_accounts(primary, secondary)` — an irreversible, non-idempotent operation that rewrites foreign keys across the CRM. - **Branch B** hypothesized the records were distinct and invoked `update_email(...)` — idempotent and reversible. Both branches ran concurrently against the same optimistic tool layer. Branch A completed first and committed its side effect. Branch B completed 400 ms later. The merge arbiter, using a confidence score from each branch's self-reported rationale, selected Branch B as the winner because its rationale had a higher log-probability under the planner's scoring model. The arbiter then issued `rollback(branch_A)`. `rollback(branch_A)` did exactly what it was implemented to do: it dropped Branch A's context, released its lease, and marked its plan node `ABORTED`. It did **not** call `unmerge_accounts` — no such tool existed, and the tool registry had no inverse mapping for `merge_accounts`. The result was a system in which the winning branch's plan (`update_email` on the surviving record) was applied to a data model that had already been destructively rewritten by the losing branch. The email update landed on the wrong surviving row. Downstream joins failed for eleven minutes before a human noticed. The critical detail: **no component in the system was in an error state.** Every agent reported success. The arbiter reported a clean merge. The rollback reported completion. The corruption was silent because the invariant that was violated — "the winning branch's preconditions still hold at commit time" — was never checked, only assumed. ## Condition of Validity Speculative branching with optimistic invocation is valid only under the following invariant, stated precisely: > For every speculative branch `b` and every tool invocation `t ∈ b`, either `t` is deferred until `b` is selected as the merge winner, or `t` is *compensable*: there exists a registered inverse `t⁻¹` such that applying `t⁻¹` after `t` restores the observable external state to its pre-`t` value, and `t⁻¹` is itself idempotent and safe to invoke from the arbiter process without the losing branch's context. The second clause is where systems break. Even when an inverse exists, invoking it from the arbiter is unsafe unless the inverse is *context-free* — it must be executable using only the tool's recorded input/output log, not the losing branch's reasoning state, which the rollback has already discarded. `merge_accounts` has no inverse at all. `update_email` has one, but only if the prior value was captured in the tool's audit log before the call, which the optimistic invocation path did not guarantee. A second, weaker invariant is required at the arbiter: **the winner's preconditions must be re-validated against the post-rollback world state, not the pre-branch world state.** A branch that was valid when it was forked may be invalid after a sibling committed an irreversible effect. The arbiter in the observed incident validated Branch B against the world as it existed at fork time, not at commit time. ## Decision Boundary The boundary between safe speculation and silent corruption is drawn by the tool registry, not by the planner. The correct decision procedure at branch-fork time is: 1. Enumerate the tools reachable from each speculative branch (statically, from the plan DAG — not dynamically, from what the branch happens to call). 2. Partition them into `DEFERRED`, `COMPENSABLE`, and `IRREVERSIBLE`. 3. If any branch reaches an `IRREVERSIBLE` tool, that branch may not be speculated optimistically. It must be serialized behind the merge decision, or the fork must be abandoned and the task run sequentially. The failure in the incident is that step 1 was never performed. The planner forked on the basis of confidence, not on the basis of tool reachability. A branch whose reachable tool set includes a non-compensable effect is a branch that *cannot lose*. Forcing it to win is not a fix — it inverts the arbiter's job and produces the opposite error (committing a low-confidence irreversible action because it happened to be un-rollbackable). The only sound resolution is to not speculate across that branch at all. There is a subtler boundary at the arbiter: **rollback of a branch that committed an irreversible effect must be treated as a hard fault, not a routine abort.** If the arbiter ever finds itself rolling back a branch that reached an `IRREVERSIBLE` tool, the correct action is to halt the entire task graph and escalate, because the world state is now unreconcilable with any branch's plan. Continuing the merge — as the observed system did — is the failure. ## Operational Effect The observable signature of this failure is a *clean* run: all agents exit zero, the arbiter logs a successful merge, rollback logs completion, and the corruption surfaces only through downstream data inconsistency hours later. This makes it nearly invisible to per-agent monitoring, which is why it must be caught at the arbiter by an explicit invariant check rather than by error rates. The architectural guardrail is threefold. First, the tool registry must carry a `reversibility` classification per tool, and the planner must consult it at fork time — a branch reaching an `IRREVERSIBLE` tool is un-speculatable by construction. Second, the arbiter must, before committing the winner, re-validate the winner's preconditions against the current world state and abort the whole graph if any losing branch committed an irreversible effect. Third, every optimistic invocation must be logged with its pre-state so that compensation, where possible, is context-free and executable by the arbiter alone. The code below encodes the arbiter-side check: it raises when a losing branch is found to have committed an irreversible effect, forcing escalation instead of a silent merge. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Reversibility(Enum): DEFERRED = "deferred" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" @dataclass class ToolInvocation: tool: str reversibility: Reversibility pre_state: Optional[dict] = None committed: bool = False @dataclass class Branch: branch_id: str invocations: list = field(default_factory=list) selected: bool = False class UnreconcilableSpeculationError(RuntimeError): """Raised when a losing speculative branch committed an irreversible effect, making the world state unreconcilable with any branch plan. The task graph must halt and escalate; it must not proceed to merge.""" def arbiter_commit(branches: list, winner_id: str) -> Branch: winner = next((b for b in branches if b.branch_id == winner_id), None) if winner is None: raise UnreconcilableSpeculationError(f"winner {winner_id} not found in graph") # Invariant: no losing branch may have committed an irreversible effect. for b in branches: if b.branch_id == winner_id: continue for inv in b.invocations: if inv.committed and inv.reversibility is Reversibility.IRREVERSIBLE: raise UnreconcilableSpeculationError( f"losing branch {b.branch_id} committed irreversible tool " f"'{inv.tool}'; world state cannot be reconciled with winner " f"{winner_id}. Halting graph for escalation." ) # Re-validate winner preconditions against current world state, not fork-time. for inv in winner.invocations: if not inv.committed and inv.pre_state is None: raise UnreconcilableSpeculationError( f"winner {winner_id} invocation '{inv.tool}' lacks pre-state; " f"cannot re-validate preconditions at commit time." ) winner.selected = True return winner ```