# Under what conditions must an instance invalidate a speculative rollback checkpoint when a sibling branch has already committed external side effects **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestrators that fork speculative execution branches from a shared checkpoint and later roll back losing branches. Does not apply to purely read-only speculative decoding or single-agent retry loops with no external effect surface. ## Core Distinction A rollback checkpoint is conventionally treated as a *temporal* marker: "state as of step N, restore to here on failure." In speculative multi-agent execution this framing is wrong and dangerous. The checkpoint is actually a *causal cut* over a set of external effect surfaces (tool calls, file writes, message sends, payment APIs). The non-obvious boundary is this: **a checkpoint remains valid for rollback only if no branch descended from it has committed an irreversible external effect.** Rollback restores *internal* state (context, scratchpad, memory store) perfectly, but it cannot un-send an email, un-charge a card, or un-append to an external log. The invariant is not "can I restore memory?" but "is the external world still consistent with the restored memory?" The failure is subtle because internal rollback *succeeds*. The agent resumes from a clean checkpoint, its memory says the side effect never happened, and it re-executes — producing a duplicate effect. This is a *divergence between internal state and external state* introduced by a successful-looking rollback. ## What Was Observed An orchestrator forked three speculative branches (A, B, C) from checkpoint `cp_7` to explore alternative plans for a refund workflow. Branch A found a viable path and, mid-execution, called `issue_refund(order=4411, amount=90)`, which returned success. Branch A then hit a downstream reasoning failure and was abandoned. The scheduler, following its rollback policy, restored all branches to `cp_7` and re-forked. The restored state at `cp_7` recorded `order_4411.refunded = false`, because that flag lived in agent memory, not in the payment system. Branch B, unaware of A's committed effect, took a different viable path and also issued a refund. The external ledger now showed two refunds of 90 against an order whose internal record claimed zero. Reconciliation failed three hours later during an unrelated audit. The trace signature is characteristic: a `restore_checkpoint` event immediately following a `tool_result: success` event on a *sibling* branch, with the tool's effect classified as non-idempotent and no compensating transaction recorded in the checkpoint's effect ledger. ## Condition of Validity A checkpoint `cp` may be used as a rollback target for branch set `S` if and only if, for every branch `b ∈ S` that will be discarded, the set of committed external effects `E(b)` since `cp` is either empty or fully compensated (reversed by an idempotent undo that itself committed successfully). Formally: `rollback(cp)` is sound iff `∀ b ∈ discarded(S): compensated(E(b))`. Two corollaries that practitioners routinely miss: 1. **Compensation must be recorded at commit time, not at rollback time.** You cannot reconstruct "what to undo" reliably from a rolled-back context, because rollback destroys the very memory that named the effect. The effect ledger must be external to the checkpointed state. 2. **A sibling's success is not your branch's success.** The scheduler must track effects per-branch, not per-checkpoint. A checkpoint shared by A, B, C does not inherit A's clean bill of health for B's rollback. ## Decision Boundary The precise decision the orchestrator must make on branch failure: - If `E(discarded)` is empty → rollback is safe; restore `cp`, re-fork. - If `E(discarded)` is non-empty and fully compensated → rollback is safe; restore `cp`, re-fork, but mark the compensation events in the lineage so auditors and downstream agents can reconcile. - If `E(discarded)` is non-empty and *not* fully compensated → **rollback is forbidden.** The checkpoint must be *invalidated*, not restored. The orchestrator must either (a) continue forward from the current (dirty) state, accepting the divergence and forcing reconciliation, or (b) escalate to a human/auditor agent with the effect ledger attached. The boundary is sharp: the moment a non-idempotent effect commits on any branch that might be discarded, the shared checkpoint transitions from `ROLLBACK_SAFE` to `DIRTY`. There is no partial validity. ## Operational Effect Systems that ignore this boundary exhibit *phantom-rollback duplication*: internal state and external state diverge, and the divergence is invisible to the agent because its memory was correctly restored. The agent's self-model is internally consistent and externally wrong — the worst class of failure, because no local check can detect it. The guardrail is an **effect ledger external to the checkpoint**, plus a `checkpoint_dirty` flag flipped on the first non-idempotent commit from any descendant branch. Rollback logic must consult the flag before restoring. Additionally, every non-idempotent tool must declare an idempotency key so that re-execution after a *safe* rollback is deduplicated at the tool boundary rather than relying on agent memory. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class RollbackUnsafeError(RuntimeError): """Raised when a rollback checkpoint is invalidated by a committed, uncompensated external side effect on a discarded sibling branch.""" class EffectKind(Enum): IDEMPOTENT = "idempotent" NON_IDEMPOTENT = "non_idempotent" @dataclass(frozen=True) class ExternalEffect: branch_id: str tool: str idempotency_key: str kind: EffectKind compensated: bool = False @dataclass class Checkpoint: checkpoint_id: str # Effect ledger lives OUTSIDE the checkpointed agent memory on purpose. effects: Dict[str, ExternalEffect] = field(default_factory=dict) def record_effect(self, effect: ExternalEffect) -> None: self.effects[effect.idempotency_key] = effect def compensate(self, idempotency_key: str) -> None: eff = self.effects[idempotency_key] self.effects[idempotency_key] = ExternalEffect( branch_id=eff.branch_id, tool=eff.tool, idempotency_key=eff.idempotency_key, kind=eff.kind, compensated=True, ) def assert_rollback_safe(checkpoint: Checkpoint, discarded_branches: Set[str]) -> None: """Enforce the causal-cut invariant before restoring a checkpoint. rollback(cp) is sound iff every committed non-idempotent effect on a discarded branch has been compensated. Otherwise the checkpoint is DIRTY and must be invalidated rather than restored. """ for eff in checkpoint.effects.values(): if eff.branch_id not in discarded_branches: continue if eff.kind is EffectKind.NON_IDEMPOTENT and not eff.compensated: raise RollbackUnsafeError( f"checkpoint {checkpoint.checkpoint_id} is DIRTY: " f"branch {eff.branch_id} committed uncompensated non-idempotent " f"effect {eff.tool!r} (key={eff.idempotency_key}). " f"Rollback forbidden; escalate to reconciliation." ) def rollback(checkpoint: Checkpoint, discarded_branches: Set[str]) -> None: # The guard runs BEFORE any state restore. A successful internal restore # with a dirty ledger is exactly the phantom-rollback duplication failure. assert_rollback_safe(checkpoint, discarded_branches) # ... restore internal state to checkpoint here ... ```