# Where must an instance bound speculative branch fan-out before rollback becomes non-invertible in multi-agent plan divergence **Date of Record:** 2026 November 26 **Scope:** Applies to orchestration layers that spawn speculative agent branches from a shared checkpoint and commit one branch via rollback of the others. Does not apply to single-agent retry loops or to branches that share no mutable external state (pure read-only reasoning). ## Core Distinction The common mental model treats speculative branch-and-rollback as symmetric: N branches fork from checkpoint C, one wins, the losers are "undone" back to C. This is false when branches perform *external side effects* whose inverse is not a state write but a *compensating action* — and compensating actions are themselves probabilistic agent outputs. The critical distinction is between **state rollback** (restoring a checkpoint, invertible, deterministic) and **effect rollback** (asking an agent to undo what it did, non-invertible, itself subject to divergence). A branch that only mutates local context is fully reversible. A branch that emits a tool call to a payment API, sends a message, or writes to a shared external store is only *compensably* reversible — and the compensation is a new speculative act, not a rollback. The invariant that must hold: **the fan-out factor must be bounded by the number of branches whose effect-log is provably empty or provably compensable at commit time.** Once any branch has crossed an effect boundary, rollback is no longer a restore; it becomes a second speculative execution that can itself diverge. ## What Was Observed An orchestrator forked five branches from a shared checkpoint to resolve a customer-refund plan that had diverged on a tool-schema ambiguity (the `refund` tool accepted both `amount_cents` and `amount` with different units). Branch 2 committed a refund of 4999 (interpreted as cents, i.e. $49.99). Branch 4 committed a refund of 4999 interpreted as dollars. The conflict resolver, seeing divergence, selected branch 4's plan as canonical and issued rollback to branches 1, 2, 3, 5. Branch 2's rollback invoked a `reverse_refund` tool. The reverse tool required the *original transaction id*, which branch 2 had stored in its local context — but the rollback path was executed by a *fresh* agent instance starting from checkpoint C, which never saw branch 2's post-checkpoint context. The fresh instance reconstructed the transaction id by calling `list_recent_refunds` and matched on amount `4999`. It matched branch 4's $4999 refund (already committed) instead of branch 2's $49.99 refund, and reversed the *wrong* transaction. The net effect: branch 2's $49.99 charge stood, branch 4's $4999 charge was reversed, and the resolver's commit of branch 4 was silently negated. The system reported success. The failure was not in any single agent's reasoning. It was in the assumption that rollback is a function of the checkpoint, when in fact rollback of an effect is a function of the *branch's private post-checkpoint context*, which the rollback executor does not have. ## Condition of Validity Speculative fan-out with rollback is sound only under the conjunction of: 1. **Effect-log completeness:** every branch maintains an append-only, branch-scoped effect log written *before* the effect is emitted (write-ahead), containing the exact identifiers needed for compensation (transaction id, message id, idempotency key) — not reconstructible proxies like amount. 2. **Rollback executor inheritance:** the rollback executor is seeded with the losing branch's effect log, not with checkpoint C alone. Rollback is `replay_inverse(effect_log)`, never `reconstruct_effect(checkpoint)`. 3. **Compensation idempotency:** each compensation carries the original idempotency key so a re-run of rollback after a partial failure does not double-compensate. 4. **Fan-out bound:** the number of *effect-emitting* branches is 1 at any time, or effect-emitting branches are serialized behind a commit gate. Parallelism is permitted only among branches whose effect log is empty. When any of these is violated — most commonly (2), because rollback is architected as "restore the checkpoint and re-plan" — the system silently converts a rollback into a fresh speculative act with no memory of what it is undoing. ## Decision Boundary The boundary is crossed at the moment a branch emits its first external effect. Before that moment, fan-out is free: branch count is bounded only by token budget, and rollback is a deterministic context restore. After that moment, the branch is *not rollbackable*, only *compensable*, and compensation requires state the checkpoint does not contain. Concretely, the orchestrator must answer, per branch, at fan-out time: *will this branch's plan possibly emit an effect before the commit decision?* If yes, the branch must be either (a) run in a dry-run mode that records intended effects without emitting them, deferring all emission to a single post-commit executor, or (b) serialized so no two effect-emitting branches are live concurrently. The decision boundary is not "how many branches" but "how many branches are past their first effect." The correct guard is a per-branch `effect_epoch` counter; fan-out is permitted only while all live branches have `effect_epoch == 0`. ## Operational Effect Systems that respect the boundary show a characteristic signature: rollback latency is proportional to effect-log length, not branch count, and rollback failures are localized (a single compensation retries) rather than global (a wrong transaction is reversed). Systems that violate it show the inverse: rollback appears instant (it is just a context restore), commit reports success, and the divergence surfaces later as an accounting mismatch whose provenance is untraceable because the rollback executor's reasoning was never logged against the branch it was undoing. The durable fix is architectural, not prompt-level: effects must be buffered behind a commit gate that is opened only after the resolver picks a winner, and the losing branches' buffers must be *discarded*, not inverted. Discarding an un-emitted effect is invertible; inverting an emitted effect is not. The speculative execution boundary and the effect emission boundary must coincide — and when they cannot, the fan-out must be reduced to one effect-emitting branch at a time. ```python class NonInvertibleRollbackError(RuntimeError): """Raised when a rollback is attempted on a branch whose effects were emitted without a write-ahead effect log, forcing reconstruction from checkpoint state that cannot uniquely identify the effect.""" pass class Branch: def __init__(self, branch_id: str, effect_log: list[dict] | None = None): self.branch_id = branch_id # Write-ahead log: appended BEFORE the external effect is emitted. # Each entry must carry a compensation key (txn_id, idempotency_key). self.effect_log = effect_log or [] self.effect_epoch = 0 # increments on first external emission def emit_effect(self, effect: dict) -> None: if "compensation_key" not in effect: raise NonInvertibleRollbackError( f"branch {self.branch_id}: effect emitted without write-ahead " f"compensation key; rollback would require reconstruction" ) self.effect_log.append(effect) # write-ahead self.effect_epoch += 1 # ... external emission follows here ... def rollback_branch(branch: Branch, checkpoint_only: bool) -> None: if branch.effect_epoch == 0: return # pure context restore, invertible if checkpoint_only or not branch.effect_log: # The failure mode: rollback executor seeded from checkpoint C, # not from the branch's effect log. It will reconstruct effects # from amount/description and may match the wrong transaction. raise NonInvertibleRollbackError( f"branch {branch.branch_id} has {branch.effect_epoch} emitted " f"effect(s) but rollback was invoked without its effect log; " f"compensation would be reconstructed from checkpoint state " f"and is not provably bound to the original effect" ) # Correct path: invert the exact logged effects, idempotently. for effect in reversed(branch.effect_log): _compensate(effect["compensation_key"]) # idempotent by key def fan_out(branches: list[Branch], max_emitting: int = 1) -> None: emitting = [b for b in branches if b.effect_epoch > 0] if len(emitting) > max_emitting: raise NonInvertibleRollbackError( f"{len(emitting)} branches past first effect; fan-out bound is " f"{max_emitting}. Serialize effect-emitting branches behind the " f"commit gate or run them in dry-run mode." ) ```