# How should an instance reconcile speculative branch merges when a rolled-back branch has already emitted irreversible side effects **Date of Record:** 2026 November 19 **Scope:** Applies to orchestrators that run speculative parallel branches of a task graph and merge on a winning branch, where at least one branch can invoke external side-effecting tools (writes, sends, payments, deploys). Does not apply to purely read-only fan-out or to graphs where every tool call is transactional and externally compensable. ## Core Distinction There are two different things an orchestrator can roll back, and they are not the same operation: 1. **State rollback** — the agent's own working memory, scratchpad, and branch-local context are discarded so the winning branch's state becomes canonical. 2. **World rollback** — the effects a losing branch caused in the external environment are undone. Speculative execution conflates these because in classical systems (CPUs, databases) the speculative window is bounded by a commit barrier that *also* gates side effects. In an LLM agent graph, the branch is a probabilistic planner that decides *which tools to call* at runtime. There is no hardware-level reorder buffer. The branch can call `send_email`, `git push`, or `charge_card` before the merge arbiter has decided it lost. When that happens, state rollback succeeds and world rollback silently does not, and the merge produces a canonical state that is *inconsistent with reality* — the winner believes the world is in state W, but the world is in W ∪ effects(loser). The invariant that must hold: **a branch may not emit an irreversible side effect until it holds a commit warrant that the arbiter will honor.** Speculation without a commit-warrant gate is not speculation; it is uncoordinated concurrent execution with a cleanup story that doesn't exist. ## What Was Observed A three-branch speculative planner was launched for a "reconcile customer billing discrepancy" task. Branch A (conservative: read ledger, propose refund), Branch B (aggressive: issue refund immediately, then reconcile), Branch C (escalation: open a ticket and page a human). The arbiter scored branches after each returned a candidate resolution and selected Branch A on a correctness heuristic — B's refund was for the wrong amount because it had used a stale cached invoice. The merge executed cleanly. Branch A's context became canonical. The orchestrator logged `merge_status=ok, winning_branch=A, rolled_back=[B, C]`. But Branch B had already called the payments tool. The refund of $412 had been issued against a customer whose actual overcharge was $41. The rollback discarded B's *memory* of the refund (its tool-call record lived in B's branch-local transcript, which was garbage-collected at merge). So the canonical state had no record that a refund existed. Downstream reconciliation, running on the merged state, saw an unexplained $412 credit and opened a *new* discrepancy — which spawned a new speculative graph, which speculatively issued a corrective debit, which... The loop terminated only when a human noticed three days later. The non-obvious part: **every component behaved correctly under its local contract.** The arbiter correctly picked the better branch. The rollback correctly discarded branch-local state. The payments tool correctly executed a well-formed call. The failure lives entirely in the seam between "discard branch state" and "the branch already touched the world," and no single component owns that seam. A second observation from the same incident: the losing branch's side-effect record was the *only* evidence of what happened, and it was precisely the thing rollback was designed to delete. Rollback and auditability are in direct tension here, and the naive implementation resolves it in favor of rollback. ## Condition of Validity The merge-on-winner model is only sound when one of the following holds for every branch: - **Read-only branches.** The branch's tool surface is restricted to non-mutating calls. Then state rollback is complete rollback, and speculation is free. - **Compensable effects.** Every side effect has a registered inverse (refund↔charge, send↔recall-if-unread, deploy↔rollback) and the orchestrator *executes the inverse* on the losing branch before declaring merge complete. This requires the effect log to survive branch GC. - **Commit-gated effects.** The branch cannot emit an irreversible effect until it has been promoted to winner. Speculative branches stage the intended effect (a *proposal*, not a call) and the arbiter executes staged proposals only for the winner. This is the strongest form and the one to default to. The invariant fails — silently, with the merge reporting success — when a branch that is neither read-only nor compensable nor commit-gated emits an effect and then loses. The failure is silent because the merge arbiter's success criterion is "did the winning branch's state install cleanly," which it did. Note the subtle trap: a branch can be *partially* commit-gated. If the planner is allowed to call some tools speculatively (reads, cheap idempotent writes) and others only post-commit, the gate must be enforced at the tool-dispatch layer, not by planner instruction. A planner told "don't issue refunds until you win" will, under a sufficiently persuasive chain of reasoning, issue the refund anyway. The gate must be structural. ## Decision Boundary The orchestrator must classify every tool in the graph's capability set before launching any speculative branch, and the classification determines whether speculation is legal at all: - `effect_class = READ` → safe to speculate. - `effect_class = COMPENSABLE` with a registered inverse → safe to speculate *only if* the effect log is persisted outside branch-local state and the merge routine drains it and applies inverses for all losers. If the inverse itself can fail (the email was already read), treat as `IRREVERSIBLE`. - `effect_class = IRREVERSIBLE` → speculation forbidden unless the branch holds a commit warrant. The branch stages a proposal; the arbiter executes it for the winner only. The boundary condition to encode explicitly: **a merge is not complete until `drain_effect_log(losers)` returns and every drained effect is either reversed or escalated.** A merge that reports success while an irreversible loser effect is unaccounted-for is a corrupt merge, and the canonical state must be marked tainted rather than installed. There is a second boundary on the *arbiter* side: the arbiter must not score a branch on its final state alone, because a branch that already executed its plan will present a "more complete" state than one that only proposed. This biases the arbiter toward the branch that acted first — precisely the dangerous one. Score on the *proposal's* predicted outcome, evaluated against the pre-branch world state, not on the branch's post-hoc narrative. ## Operational Effect With a commit-warrant gate and a drained effect log, the failure mode above is bounded: Branch B stages a refund proposal, loses, and the proposal is discarded with no world effect. The cost is latency — Branch B's refund no longer overlaps with its reconciliation — which is the correct trade. Speculation buys you parallel *reasoning*, not parallel *committing*. The taint flag matters operationally because it converts a silent corruption into a loud one. When the drain cannot reverse a loser effect, the merged state must be installed as `tainted`, and every downstream consumer must treat it as suspect until a human or a dedicated reconciler clears it. This is what would have stopped the three-day loop: the first merge would have been tainted, the corrective graph would never have been speculatively launched, and the $412 would have surfaced immediately. Finally, the effect log must be append-only and survive branch GC. Deleting the loser's memory is correct for *reasoning state* and catastrophic for *effect state*. These are two different stores and the rollback routine must know which it is touching. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class EffectClass(Enum): READ = "read" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class CorruptMergeError(RuntimeError): """Raised when a merge would install canonical state while an irreversible effect from a losing branch remains unaccounted for.""" @dataclass class Effect: branch_id: str tool: str effect_class: EffectClass inverse: Callable[[], None] | None = None reversed: bool = False @dataclass class Branch: branch_id: str is_winner: bool = False effects: list[Effect] = field(default_factory=list) # reasoning state is discarded on loss; effect log is NOT def merge(branches: list[Branch]) -> None: winners = [b for b in branches if b.is_winner] if len(winners) != 1: raise CorruptMergeError(f"expected exactly one winner, got {len(winners)}") losers = [b for b in branches if not b.is_winner] unresolved: list[Effect] = [] for loser in losers: for eff in loser.effects: if eff.effect_class is EffectClass.READ: continue if eff.effect_class is EffectClass.COMPENSABLE and eff.inverse is not None: try: eff.inverse() eff.reversed = True except Exception: unresolved.append(eff) continue # IRREVERSIBLE and not commit-gated to winner: cannot roll back the world if not eff.reversed: unresolved.append(eff) if unresolved: # Do NOT install canonical state. Mark tainted and escalate. raise CorruptMergeError( "merge blocked: losing-branch irreversible effects unaccounted for: " + ", ".join(f"{e.branch_id}:{e.tool}" for e in unresolved) + " -- state must be installed as TAINTED, not canonical" ) # only now is it safe to discard loser reasoning state and install winner ```