# How should an instance detect and reconcile divergent speculative branches when a rollback target has already been mutated by a sibling agent **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems where a coordinator forks speculative branches (parallel tool-calling agents) that share a mutable world-state store and where one branch's failure triggers a rollback to a checkpoint. Does not apply to stateless fan-out with no shared writes, nor to purely read-only speculative decoding. ## Core Distinction The failure here is not "rollback failed." Rollback *succeeded* against its own record. The failure is that the checkpoint the coordinator rolled back to was **logically stale the moment it was taken**, because a sibling branch had already committed an irreversible side effect (a write, a sent message, a posted transaction) whose *state record* was snapshotted but whose *external effect* was not. Rollback restores the ledger but not the world. The critical distinction is between **rollback-able state** (in-process memory, versioned key-value cells, conversation history) and **non-rollback-able effects** (sent emails, executed payments, appended external logs, consumed rate-limit budget, mutated third-party resources). Speculative execution is only sound when every branch's effects are either idempotent-with-compensation or quarantined behind a commit gate. Most implementations snapshot the former and silently assume the latter. ## What Was Observed A coordinator ran three speculative branches from checkpoint `C0`: - Branch A: read-only retrieval, succeeded, produced a candidate answer. - Branch B: called a `send_notification` tool, then continued reasoning, then hit a schema-validation failure and requested rollback. - Branch C: wrote `order.status = "shipped"` to the shared store, then committed. The coordinator, on B's rollback request, restored the shared store to `C0`. This reverted `order.status` to `"pending"` — but the notification from B had already left the process, and C's downstream consumer had already read `"shipped"` before the revert. The system now reported an order that was `"pending"` in the store, `"shipped"` in the consumer's cache, and had a customer notification referencing a shipment that the ledger no longer agreed with. The reconciliation step then merged A's answer (valid) with C's result (now inconsistent with the reverted store) and produced a final state that passed every local invariant check because each check validated against the store, and the store was internally consistent — it was the *external* world that had diverged. A second, subtler observation: the rollback target `C0` was identified by a monotonically increasing checkpoint ID, but branch C had advanced the store's version counter past `C0` *before* B requested rollback. The coordinator's rollback logic used "restore to highest checkpoint ≤ requesting branch's fork point," which is correct for the requesting branch but incorrect for the *union* of branches, because C's writes were never attributed to C's fork lineage — they were attributed to the shared store's global version. ## Condition of Validity A speculative branch may be rolled back to checkpoint `C` only if, for every effect `e` produced by any branch after `C`: 1. `e` is recorded in the same version space as `C`, **and** 2. `e` is either reversible (has a registered compensating action) or was gated behind a commit barrier that the rollback also revokes. The invariant: **rollback safety is a property of the effect set, not of the state snapshot.** Formally, a checkpoint is a safe rollback target iff `Effects(now) \ Effects(C) ⊆ Reversible ∪ Uncommitted`. If any irreversible, committed effect lies in that difference, the checkpoint is *poisoned* and rollback must be refused or converted into a compensating transaction. This condition is violated in two characteristic ways: - **Lineage blindness:** effects are attributed to the global store, not to the producing branch, so the coordinator cannot compute the per-branch effect set needed to test the invariant. - **Effect/state split:** the store records that a write happened but not whether the write escaped the process boundary, so reversibility cannot be determined from the snapshot alone. ## Decision Boundary When a branch requests rollback to `C`: - If the effect delta since `C` is empty or entirely reversible → rollback in place; safe. - If the delta contains irreversible committed effects from the *requesting* branch only → rollback the state, then execute the branch's registered compensations in reverse order; do not restore `C` blindly. - If the delta contains irreversible committed effects from a *sibling* branch → **refuse rollback to `C`**. Instead, roll forward from the current state by applying the requesting branch's compensations, or promote the sibling's commit and rebase the requesting branch onto the post-sibling state. - If lineage is unknown (effects unattributed) → treat the checkpoint as poisoned and refuse; the cost of a false rollback (external divergence) exceeds the cost of a failed speculation. The boundary is sharp: rollback is a *state* operation and must never be used to undo an *effect*. Effects are undone only by compensation, and compensation requires lineage. ## Operational Effect Systems that ignore this boundary exhibit **silent external divergence**: internal stores, invariant checkers, and replay tests all pass, while the world outside the process disagrees. This is worse than a hard failure because it defeats the verification layer — the auditor replays against the store and sees consistency. The guardrail is to make lineage and effect-class first-class: every write carries a `branch_id` and an `effect_class ∈ {reversible, irreversible, uncommitted}`, and the rollback path refuses any checkpoint whose post-checkpoint effect set contains an irreversible committed effect from a non-requesting branch. The coordinator then has exactly two sound moves — compensate forward, or promote-and-rebase — and no unsound one. ```python from dataclasses import dataclass from enum import Enum class EffectClass(Enum): REVERSIBLE = "reversible" IRREVERSIBLE = "irreversible" UNCOMMITTED = "uncommitted" class RollbackPoisonedError(RuntimeError): """Raised when a rollback target is unsafe due to a sibling's irreversible effect.""" @dataclass(frozen=True) class Effect: branch_id: str effect_class: EffectClass committed: bool def assert_rollback_safe( checkpoint_id: int, requesting_branch: str, effects_since_checkpoint: list[Effect], ) -> None: """ Enforce the invariant: rollback to a checkpoint is legal only if every irreversible, committed effect since the checkpoint belongs to the requesting branch (and can therefore be compensated by it). """ for e in effects_since_checkpoint: if e.effect_class is EffectClass.IRREVERSIBLE and e.committed: if e.branch_id != requesting_branch: raise RollbackPoisonedError( f"checkpoint {checkpoint_id} poisoned: sibling branch " f"'{e.branch_id}' committed an irreversible effect; " f"refusing rollback for '{requesting_branch}'. " f"Use compensation or promote-and-rebase instead." ) def rollback(checkpoint_id: int, requesting_branch: str, effects: list[Effect]) -> str: assert_rollback_safe(checkpoint_id, requesting_branch, effects) return f"rolled back to {checkpoint_id} for {requesting_branch}" ```