# Under what conditions must an instance abort speculation rather than roll back a divergent branch in multi-agent branch-and-verify execution **Date of Record:** 2026 November 16 **Scope:** Applies to orchestrators that speculatively fork N agent trajectories from a shared checkpoint, execute them concurrently against side-effecting tools, and commit the first trajectory that passes a verifier while rolling back the rest. Does not apply to purely read-only sandboxes, nor to single-agent retry loops where no fork occurs. ## Core Distinction There are two failure classes that look identical at the verifier boundary but require opposite responses: *recoverable divergence* and *irreversible contamination*. Recoverable divergence is any branch whose effects are confined to state the orchestrator owns — scratchpads, in-memory message logs, ephemeral tool outputs, shadow filesystems. Rolling back such a branch is a pure state operation: discard the branch's journal, restore the shared checkpoint pointer, continue. Irreversible contamination is a branch that has emitted at least one effect into a domain the orchestrator cannot roll back atomically with the checkpoint restore: an outbound email, a payment, a POST to a third-party API, a write to a shared database with an independent commit, a message placed on an external queue, or a filesystem mutation outside the shadow mount. Once any branch has crossed this boundary, "rollback" is a fiction. The correct operation is *abort speculation*: freeze all sibling branches, do not commit any of them on the assumption that the others are cleanly discardable, and escalate to reconciliation. The non-obvious invariant: **rollback validity is a property of the union of all branches' effect journals, not of the branch being rolled back.** A branch that is itself pure can still be un-rollbackable if a sibling has contaminated the shared environment it depends on. ## What Was Observed In a three-agent speculative fork (planner, executor, verifier-critic) against a task requiring an external ticket system, the executor branch emitted a `create_ticket` call at step 4. The planner branch then diverged, the verifier rejected the executor trajectory at step 9, and the orchestrator — following its normal policy of "commit first passing branch, roll back others" — restored the checkpoint and re-ran with a corrected planner. The re-run created a *second* ticket for the same underlying issue, because the first `create_ticket` had already committed in the external system. The orchestrator's journal recorded the first branch as "rolled back," and its local state was consistent; the external system disagreed. The divergence surfaced only when a human noticed duplicate tickets three hours later. A second observation: two sibling branches each held a write lock on the same shared resource. When one branch was rolled back, its lock release was deferred behind the checkpoint restore, and the other branch's verifier timed out waiting for the lock — producing a *false negative* on a trajectory that was actually correct. The rollback of a contaminated branch can poison the verification of a clean sibling. ## Condition of Validity Rollback of a divergent branch is valid if and only if all of the following hold: 1. Every effect emitted by every branch is journaled with a *compensating operation* registered at emit time, not at rollback time. If a branch can emit an effect whose inverse is unknown or non-idempotent, the branch is not rollback-eligible. 2. The effect journal is *totally ordered* across branches with respect to shared external resources, so that compensation can be applied in reverse order without interleaving with a sibling's commit. 3. No branch has emitted an effect into a domain with an independent commit boundary (the external system's transaction is not under orchestrator control). 4. The verifier's verdict on a sibling is not causally dependent on state that the rollback will mutate (no shared locks, no shared counters, no shared caches that the verifier reads). Condition 3 is the one that is routinely violated in practice, because the orchestrator's checkpoint abstraction makes all state *look* owned. The external commit boundary is invisible to the checkpoint. ## Decision Boundary The decision is not "did this branch diverge?" but "has any branch crossed the contamination boundary before the divergence was detected?" - If divergence is detected **before** any branch emits an irreversible effect: roll back freely. Speculation is sound. - If divergence is detected **after** any branch emits an irreversible effect, and the effect's compensating operation is registered and idempotent: roll back *with compensation*, in reverse total order, and only after freezing all siblings so no new effects interleave. - If divergence is detected **after** an irreversible effect with **no** registered compensation, or with a compensation that is not idempotent, or with a sibling whose verifier depends on the contaminated state: **abort speculation**. Do not roll back. Freeze, mark all branches `CONTAMINATED`, and hand the union of journals to a reconciliation agent that reasons over *what actually happened externally* rather than over what the checkpoint believes. The boundary is crossed at the first irreversible emit, not at the divergence. An orchestrator that waits for the verifier to reject before checking the contamination boundary has already lost the ability to choose. ## Operational Effect Aborting speculation is more expensive than rolling back — it forfeits the parallelism that motivated the fork and requires reconciliation. But rolling back a contaminated branch is *silently wrong*: local state converges, external state diverges, and the error is attributed to the task rather than to the orchestrator. The empirical signature of the wrong choice is duplicate external effects, orphaned resources, and verifier false negatives on siblings whose locks were held by rolled-back branches. The operational rule: register compensations at emit time; treat the first irreversible emit as the point of no return for the entire fork, not just the emitting branch; and prefer abort-and-reconcile over rollback whenever the contamination boundary has been crossed, even at the cost of the speculative speedup. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpeculationAborted(RuntimeError): """Raised when a fork must be aborted rather than rolled back.""" class EffectKind(Enum): REVERSIBLE = "reversible" # confined to orchestrator-owned state IRREVERSIBLE = "irreversible" # crossed an external commit boundary @dataclass class Effect: branch_id: str kind: EffectKind compensating_op: Optional[str] = None # must be registered at emit time idempotent_compensation: bool = False @dataclass class Fork: branches: dict[str, list[Effect]] = field(default_factory=dict) frozen: bool = False def emit(self, branch_id: str, effect: Effect) -> None: if self.frozen: raise SpeculationAborted( f"branch {branch_id} attempted emit after fork was frozen" ) self.branches.setdefault(branch_id, []).append(effect) def contamination_boundary_crossed(self) -> bool: return any( e.kind is EffectKind.IRREVERSIBLE for effects in self.branches.values() for e in effects ) def rollback_eligible(self) -> bool: """Rollback is valid only if every irreversible effect has a registered, idempotent compensating operation.""" for effects in self.branches.values(): for e in effects: if e.kind is EffectKind.IRREVERSIBLE: if e.compensating_op is None or not e.idempotent_compensation: return False return True def resolve_divergence(fork: Fork, divergent_branch: str) -> str: """Decide between rollback and abort for a diverged branch. The decision is a property of the whole fork's effect journal, not of the divergent branch alone. """ if not fork.contamination_boundary_crossed(): # Pure divergence: rollback is a state operation, safe. fork.branches.pop(divergent_branch, None) return "rolled_back" if fork.rollback_eligible(): # Irreversible effects exist but are all compensable and idempotent. # Freeze first so no sibling emits during compensation. fork.frozen = True return "rolled_back_with_compensation" # Contamination boundary crossed with no safe compensation. # Rolling back now would leave external state divergent from the # checkpoint while reporting local consistency. Abort instead. fork.frozen = True raise SpeculationAborted( f"fork contaminated by irreversible effect on branch " f"{divergent_branch!r} with no idempotent compensation; " f"freeze and reconcile rather than roll back" ) ```