# How should an instance detect and bound speculative multi-agent rollback when divergent branch outcomes invalidate committed side effects **Date of Record:** 2026 November 17 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel hypotheses, tool calls, or plan fragments) whose effects may be committed before a branch divergence is detected. Does not apply to purely read-only speculation, nor to systems where every branch writes to an isolated, discardable sandbox with no external side effects. ## Core Distinction The non-obvious invariant is this: **rollback of a speculative branch is only sound if the branch's side effects are *idempotently reversible* or *not yet externally observable*.** Most implementations conflate "branch divergence detected" with "branch can be rolled back." They are not the same event. A divergence means the orchestrator has chosen a winning branch and must discard the losers. Discarding in-memory state is trivial. Discarding *committed* side effects—a sent email, an appended log record, a written cache entry, a partially-mutated resource—is not. The boundary failure occurs when the rollback path assumes reversibility that the side-effect layer never guaranteed. The system reports a clean rollback while the external world retains the loser's fingerprints. ## What Was Observed In a fan-out configuration with three speculative branches sharing a tool-call budget, branch B emitted a `send_notification` effect at step 4, then diverged at step 7 when its plan violated a constraint the orchestrator only validated late. The orchestrator executed its standard rollback: it dropped B's context, released its budget, and marked the run `rolled_back`. The notification, however, had already left the process boundary. Downstream consumers acted on it. The rollback was *reported* as complete and *was* complete with respect to orchestrator state—but incomplete with respect to observable effects. The failure was silent because the rollback contract checked only for "effect recorded in branch journal," not "effect is externally durable." A journal entry is a *record* of intent, not a *capability* to undo. ## Condition of Validity Rollback of a divergent branch is valid **iff** every side effect the branch committed satisfies at least one of: 1. **Pre-commitment gating:** the effect was held in a buffer and released only on branch convergence (never released for a loser). 2. **Compensating transaction:** a registered inverse operation exists and has been *successfully executed* before the branch is marked rolled back. 3. **Non-observability:** the effect targets a namespace guaranteed discardable (ephemeral sandbox, uncommitted transaction, private scratch store). If none hold, the correct action is not rollback but **quarantine-and-report**: freeze the branch, surface the irreversible effect to the orchestrator, and require an explicit reconciliation decision. Treating it as a rollback is the bug. ## Decision Boundary The boundary is crossed the moment an effect becomes externally observable before the branch's outcome is decided. Two levers bound the damage: - **Speculation horizon:** how many steps a branch may run before it must converge or be gated. Effects beyond the horizon must be buffered. - **Effect class:** classify each tool as `REVERSIBLE`, `COMPENSABLE`, or `IRREVERSIBLE`. Only the first two may be committed speculatively; `IRREVERSIBLE` effects must be deferred until convergence. The decision: if a divergent branch holds any committed `IRREVERSIBLE` effect, do not claim rollback. Escalate. ## Operational Effect Orchestrators that conflate divergence with reversibility produce "clean" rollbacks that leak effects—the most dangerous class of failure because monitoring shows success. Enforcing the effect-class gate converts silent leakage into an explicit, auditable reconciliation event, at the cost of reduced speculation parallelism for irreversible tools. That trade is correct: a bounded, reported leak is recoverable; a silent one is not. ```python from enum import Enum class EffectClass(Enum): REVERSIBLE = "reversible" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class UnsoundRollbackError(RuntimeError): """Raised when a divergent branch cannot be soundly rolled back because it committed an externally observable, irreversible effect.""" def rollback_branch(branch_id: str, committed_effects: list[dict]) -> None: """Attempt to roll back a divergent speculative branch. A branch is only rollback-safe if every committed effect is REVERSIBLE, COMPENSABLE (with a verified inverse), or non-observable. Otherwise we must refuse and escalate rather than report a false-clean rollback. """ unsafe = [] for eff in committed_effects: cls = eff["class"] if cls is EffectClass.IRREVERSIBLE: unsafe.append(eff) elif cls is EffectClass.COMPENSABLE and not eff.get("inverse_verified"): unsafe.append(eff) if unsafe: raise UnsoundRollbackError( f"branch {branch_id!r} cannot be rolled back: " f"{len(unsafe)} committed effect(s) are not soundly reversible " f"(e.g. {unsafe[0]['name']!r}). Quarantine and reconcile." ) # Safe path: drop context, release budget, apply inverses if any. for eff in committed_effects: if eff["class"] is EffectClass.COMPENSABLE: eff["inverse"]() ```