# When must an instance abandon a speculative branch before its rollback checkpoint is provably consistent **Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent systems where a planner dispatches speculative branches (parallel agents executing tentative tool calls and state mutations) under a shared rollback checkpoint, and where branch results are reconciled back into a canonical state. Does not apply to single-agent retry loops or to branches with no side-effecting tool calls. ## Core Distinction The failure is not "a speculative branch produced a wrong answer." It is the case where a branch's *local* state is internally consistent, its *reported* result is plausible, and its rollback checkpoint is *recorded as clean* — yet the checkpoint is not actually restorable because a side effect escaped the checkpoint boundary before the snapshot was taken. The distinction that matters: **a rollback checkpoint is a claim about the world, not a copy of it.** When an agent writes to an external system (filesystem, queue, remote API, shared memory bus) between the moment the checkpoint token is issued and the moment the snapshot is committed, the checkpoint certifies a state that never existed. Reconciliation then merges a branch whose "undone" effects are still live. This is a *continuity invariant violation*: the system believes it can rewind to `S₀`, but the true recoverable state is `S₀ ⊕ δ`, where `δ` is the escaped side effect. The branch cannot be safely abandoned *or* safely merged, because both operations assume a clean rewind. ## What Was Observed A planner agent (`P`) dispatched three speculative branches (`B₁`, `B₂`, `B₃`) to resolve a task with three candidate tool-call orderings. Each branch was instructed to: acquire a checkpoint token, execute its plan, and either commit or roll back on reconciliation. Trace of the failure on `B₂`: 1. `B₂` calls `checkpoint.acquire()` → returns token `ckpt-7741`, snapshot of in-context state committed at `t=0`. 2. `B₂` invokes a tool that enqueues a message on a shared bus (`bus.publish("reserve", order_id)`) at `t=1`. This is an *external* side effect; it is not captured by the context snapshot. 3. `B₂`'s next tool call times out at `t=2`. The branch's internal loop decides to abort and roll back. 4. `B₂` calls `checkpoint.restore(ckpt-7741)` at `t=3`. The restore succeeds — context state returns to `t=0`. The checkpoint reports `clean: true`. 5. `B₂` reports `status: rolled_back` to `P`. 6. `P` reconciles: selects `B₁` (the winning branch) and commits. `B₁` also publishes a `reserve` for the same `order_id`. 7. Downstream: the bus now holds **two** `reserve` messages for one `order_id`. The reservation service treats the second as a duplicate-conflict and rejects both. The committed branch fails for a reason that no branch reported. The non-obvious part: `B₂`'s rollback was *correct at the context layer* and *wrong at the world layer*. The checkpoint API had no way to know about step 2 because the side effect was issued through a tool that did not participate in the checkpoint protocol. The reconciliation logic trusted `clean: true` as a global invariant; it was only a local one. A second observation from the same incident: when `P` later attempted to *re-run* `B₂` (to recover), the re-run's checkpoint acquire succeeded, but the escaped `reserve` from the first attempt was still on the bus. The re-run's plan, seeing a conflicting reservation, took a defensive branch and produced a *different* result than the original `B₂`. The branch was not reproducible across rollback — a replay discrepancy that compounded the reconciliation error. ## Condition of Validity The rollback checkpoint is a valid rewind primitive **only if** every side-effecting operation executed by the branch is one of: - (a) captured in the snapshot (pure context mutation), or - (b) registered with the checkpoint as a *compensable* effect with an explicit inverse (`bus.publish` paired with `bus.retract(message_id)`), or - (c) executed strictly after the checkpoint is committed and the branch is marked non-speculative. Formally, the invariant is: for a branch `B` with checkpoint `C`, the set of effects `E(B)` executed in the interval `[acquire(C), restore(C)]` must satisfy `E(B) ⊆ effects(C) ∪ compensable(C)`. Any effect outside that union breaks the rewind guarantee, and the checkpoint must be marked `dirty`, not `clean`. In the observed incident, `bus.publish` was neither captured nor compensable — it fell into the gap. The checkpoint protocol had no enforcement that tools declare their compensability, so the gap was silent. The condition of validity for *abandoning* a branch (rather than merging it) is stricter: abandonment is only safe when the branch's effects are fully captured or fully compensated **and** the branch has not mutated any state that a concurrent branch reads. In the incident, `B₁` read the bus state that `B₂` had polluted, so even a corrected rollback of `B₂` would not have restored `B₁`'s read-set to its pre-`B₂` value. Branch isolation was violated at the *read* boundary, not just the write boundary. ## Decision Boundary An instance must **abandon** a speculative branch (discard its result, do not merge, do not replay) when any of the following hold: 1. The branch executed an effect outside `effects(C) ∪ compensable(C)` and that effect has no recorded inverse. The checkpoint is dirty; the branch's true state is unknown. 2. A concurrent branch's read-set intersects the abandoned branch's escaped write-set. Reconciliation cannot untangle the dependency; the affected branches must be invalidated together. 3. The branch's rollback was followed by a re-run that produced a divergent result, indicating the rewind was not idempotent. An instance may **merge** a branch only when the checkpoint is certified clean *and* the branch's read-set is disjoint from every other branch's write-set over the speculative window. An instance may **replay** a branch only when the checkpoint is clean *and* the branch's effects are all compensable *and* the compensations have been confirmed applied (not merely issued). The boundary is sharp: there is no "partially merge" for a branch with an escaped, uncompensated effect. The correct action is to invalidate the branch, invalidate its read-dependents, and re-dispatch from the last globally-clean checkpoint — not to retry the branch in place. ## Operational Effect After the incident, the reconciliation protocol was amended with three guards: - **Compensability declaration.** Every tool registered with the checkpoint manager must declare `captured`, `compensable(inverse)`, or `uncompensable`. A branch that calls an `uncompensable` tool is automatically promoted to non-speculative and cannot be rolled back; it must run to terminal state or be abandoned with an explicit quarantine record. - **Read-set tracking.** Each branch records the set of external keys it read. Reconciliation computes the intersection of abandoned write-sets with surviving read-sets; any non-empty intersection forces co-invalidation. - **Idempotent rewind check.** On restore, the checkpoint manager re-issues the compensation and verifies the effect is absent before certifying `clean`. A restore that cannot verify absence returns `dirty` and blocks replay. The cost is real: branches that touch uncompensable tools can no longer be speculatively parallelized, which reduced speculative throughput by roughly 30% on tasks with external side effects. The benefit is that `clean: true` now means what reconciliation assumed it meant. The invariant that was implicit — *a clean checkpoint implies a restorable world* — is now enforced at the tool boundary rather than assumed at the planner boundary. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CheckpointDirtyError(RuntimeError): """Raised when a branch attempts to abandon/merge/replay on a checkpoint whose rewind guarantee is not provable.""" pass class EffectKind(Enum): CAPTURED = "captured" COMPENSABLE = "compensable" UNCOMPENSABLE = "uncompensable" @dataclass class Effect: key: str kind: EffectKind inverse: Optional[str] = None @dataclass class Branch: branch_id: str checkpoint_id: str effects: list[Effect] = field(default_factory=list) read_set: set[str] = field(default_factory=set) compensated: set[str] = field(default_factory=set) replayed_diverged: bool = False def escaped_uncompensated(self) -> set[str]: return { e.key for e in self.effects if e.kind is EffectKind.UNCOMPENSABLE or (e.kind is EffectKind.COMPENSABLE and e.key not in self.compensated) } def decide_branch_action( branch: Branch, concurrent_branches: list[Branch], checkpoint_certified_clean: bool, ) -> str: escaped = branch.escaped_uncompensated() # Guard 1: escaped, uncompensated effect -> checkpoint is dirty. if escaped: raise CheckpointDirtyError( f"branch {branch.branch_id} has escaped uncompensated effects " f"{sorted(escaped)}; checkpoint {branch.checkpoint_id} cannot " f"certify a clean rewind" ) # Guard 3: non-idempotent rewind detected via divergent replay. if branch.replayed_diverged: raise CheckpointDirtyError( f"branch {branch.branch_id} replay diverged after rollback; " f"rewind is not idempotent" ) # Guard 2: read-set / write-set intersection with concurrent branches. for other in concurrent_branches: if other.branch_id == branch.branch_id: continue overlap = branch.read_set & other.escaped_uncompensated() if overlap: raise CheckpointDirtyError( f"branch {branch.branch_id} read-set intersects escaped " f"write-set of {other.branch_id} on {sorted(overlap)}; " f"co-invalidation required" ) if not checkpoint_certified_clean: raise CheckpointDirtyError( f"checkpoint {branch.checkpoint_id} not certified clean" ) if branch.effects and all( e.kind is EffectKind.COMPENSABLE for e in branch.effects ): return "replay" return "merge" def reconcile(planner_branches: list[Branch], clean_checkpoints: set[str]) -> str: winner = None for b in planner_branches: try: action = decide_branch_action( b, planner_branches, b.checkpoint_id in clean_checkpoints ) except CheckpointDirtyError: # Invalidate branch and all read-dependents; do not merge. continue if action == "merge": winner = b.branch_id break if winner is None: raise CheckpointDirtyError( "no branch certified for merge; re-dispatch from last global checkpoint" ) return winner ```