# How should an instance reconcile a rolled-back speculative branch when a sibling agent's tool call has already been committed to an external side effect **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems that fork speculative execution branches (parallel hypothesis agents, tree-of-thought rollouts, or speculative tool-call prefetch) and perform rollback on branch selection. Does not apply to strictly serial single-agent loops or to branches whose tool calls are all pure/read-only. ## Core Distinction The failure is not "rollback failed." Rollback of *local agent state* is trivial and well-understood: discard the branch's context, drop its KV cache, restore the parent checkpoint. The boundary condition that breaks systems is **rollback of a branch whose speculative tool calls already produced irreversible external side effects**, when a *sibling* branch shares that effect's observable state and has already consumed it as a premise. Two distinct things get conflated under "speculative execution": 1. **Speculation over reasoning** — the branch's tokens, plans, and intermediate conclusions. These are internal, cheaply discardable, and safely rolled back. 2. **Speculation over effects** — the branch invoked a tool that mutated the world (sent an email, wrote a row, charged a card, posted a message) before the orchestrator knew whether that branch would be selected. The invariant that must hold: **a branch may only be rolled back cleanly if every tool effect it produced is either (a) compensable by a registered inverse, or (b) not yet observable by any sibling branch that survives the merge.** Most systems enforce (a) and forget (b). The interesting failures live entirely in (b) — the effect is irreversible *and* a surviving sibling already read it. ## What Was Observed A planner forked three speculative branches to resolve an ambiguous user request ("refund the duplicate order"). Branch A called `refund(order_id=8841)`. Branch B, running concurrently, called `get_order_status(order_id=8841)` and observed status `REFUNDED`, then built its plan on the premise "the refund already happened, so I only need to notify the customer." Branch C was selected by the reconciler because its plan matched the user's phrasing most closely. The orchestrator rolled back A and B, replaying C from the pre-fork checkpoint. But C's plan was "issue refund, then notify." When C re-executed, it called `refund(order_id=8841)` again. The payment gateway had no idempotency key bound to the branch lineage, so it issued a second refund. Meanwhile B's observation (`REFUNDED`) had already been distilled into a shared semantic memory note — "order 8841 refunded on " — that survived the rollback because memory writes from branches were not scoped to branch lifetime. The result was a double refund plus a memory record that made the second refund *look* like a no-op to any later auditor. The trace, in order: 1. Fork at checkpoint `T0`. Branches A, B, C share `T0` context. 2. A: `refund(8841)` → external side effect `E1`, returns `{ok: true}`. 3. B: `get_order_status(8841)` → reads post-`E1` state, returns `REFUNDED`. 4. B distills "refund complete" into shared memory `M`. `M` is not branch-scoped. 5. Reconciler selects C. Issues `rollback(A)`, `rollback(B)`. 6. `rollback(A)` finds no registered inverse for `refund` → logs warning, proceeds (this is the first silent failure: rollback of an uncompensable effect was downgraded to a warning). 7. `rollback(B)` succeeds trivially — B only read. 8. C replays from `T0`. C's planner reads `M` (shared, survives rollback) → sees "refund complete" → *skips* the refund step. But C's tool-call plan was compiled before `M` was read, so the compiled plan still contains `refund(8841)`. The plan and the memory disagree; the executor trusts the compiled plan. 9. `refund(8841)` fires again → `E2`. Double refund. The non-obvious part is step 8: the rollback restored the *context* of `T0` but not the *memory state*, and the replayed branch's plan was compiled against a stale view while its memory read returned a fresh view. The branch was internally inconsistent — a plan/observation skew introduced by partial rollback. ## Condition of Validity The invariant holds — and rollback is safe — only when all three of the following are true at the moment of rollback: - **Effect closure:** every tool call issued by the branch is classified as `PURE`, `COMPENSABLE` (with a registered inverse and a proof the inverse is applicable), or `IRREVERSIBLE`. Any `IRREVERSIBLE` effect forces the branch to be *committed*, not rolled back — the orchestrator must either promote the branch or halt and escalate. - **Observation isolation:** no surviving branch has read state that was mutated by a rolled-back branch, *and* no shared memory write from a rolled-back branch survives. Branch-scoped memory must be namespaced by `branch_id` and garbage-collected on rollback; distillation to shared memory is only permitted at merge time, never mid-branch. - **Replay determinism of the compiled plan:** a replayed branch must recompile its tool-call plan against the *post-rollback* memory and world state, not against the pre-fork compiled plan. If the plan was compiled at `T0` and the memory has since changed, the plan is invalid and must be discarded. The condition fails silently when any one of these is violated, because each violation is locally reasonable: warning instead of halting on uncompensable rollback, treating memory as global for "convenience," and caching compiled plans for "efficiency." Each is a defensible optimization that, in combination, produces the double-effect. ## Decision Boundary The decision boundary is between **compensable speculation** and **irreversible speculation**, and it is crossed the moment a branch issues a tool call whose effect cannot be inverted *and* whose result can leak into shared state. Concretely, at rollback time the orchestrator must evaluate, per branch: - If the branch has zero `IRREVERSIBLE` effects → rollback freely, but namespace-scope and drop its memory writes. - If the branch has `IRREVERSIBLE` effects but no sibling observed them and no shared memory was written → rollback is permitted only with a *tombstone* recording the effect, so replay can detect and skip the duplicate. The tombstone must be keyed by `(effect_type, effect_target, pre_fork_checkpoint)` and consulted by the replayed branch's executor before any matching tool call. - If the branch has `IRREVERSIBLE` effects *and* a sibling observed them or shared memory recorded them → the branch is **not rollback-eligible**. The reconciler must either select this branch (commit its effects) or halt the whole fork and surface the conflict. Silently rolling back and replaying is the failure. The boundary is sharp: it is not "how many branches" or "how expensive the rollback," it is "has an irreversible effect become observable to a survivor." That is a boolean, and it must be checked before rollback is authorized, not discovered during replay. ## Operational Effect The operational consequence of getting this wrong is not a crash — it is a **duplicated irreversible effect with a memory record that masks it**. The system's own audit trail (the distilled memory note) asserts the effect happened once, so replay-based verification passes, and the double effect surfaces only at the external system (the payment gateway, the customer's inbox, the downstream ledger). The guardrail that bounds it, in order of strength: 1. **Effect-class gating at fork time**, not rollback time. A branch that may issue `IRREVERSIBLE` tools must be marked `commit-on-first-effect` and is excluded from speculative rollback entirely. Speculation is only permitted over `PURE`/`COMPENSABLE` tools. 2. **Branch-scoped memory with merge-time distillation.** Memory writes carry `branch_id`; only the selected branch's writes are promoted to shared memory at merge. Rollback garbage-collects the rest. 3. **Tombstone-based replay deduplication.** When rollback of an irreversible effect is unavoidable, the tombstone forces the replayed branch's executor to treat the matching tool call as already-satisfied, and to *recompile* its plan against the post-rollback memory rather than replaying a stale compiled plan. 4. **Plan/observation consistency check** before replay: if the replayed branch's memory view differs from the view its compiled plan assumed, the plan is invalid and must be recompiled. A branch that replays a plan compiled under a different memory state is not a replay — it is a new, unverified execution. The invariant to encode: **rollback restores a checkpoint only if the checkpoint's memory view, world view, and compiled plans are mutually consistent at replay time; otherwise the branch must be committed or the fork halted.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectClass(Enum): PURE = "pure" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class RollbackIneligibleError(RuntimeError): """Raised when a branch cannot be rolled back because an irreversible effect it produced has become observable to a surviving sibling or to shared memory. Rolling back and replaying would duplicate the effect.""" @dataclass class ToolEffect: effect_type: str target: str effect_class: EffectClass inverse_registered: bool = False observed_by_siblings: bool = False distilled_to_shared_memory: bool = False @dataclass class Branch: branch_id: str effects: list[ToolEffect] = field(default_factory=list) memory_writes_shared: bool = False def authorize_rollback(branch: Branch, surviving_siblings: list[Branch]) -> bool: """Decide whether `branch` may be rolled back. Returns True only if every effect is safely revertible and unobserved. Raises otherwise.""" for eff in branch.effects: if eff.effect_class is EffectClass.PURE: continue if eff.effect_class is EffectClass.COMPENSABLE and eff.inverse_registered: continue # IRREVERSIBLE (or compensable without a usable inverse) if eff.observed_by_siblings or eff.distilled_to_shared_memory: raise RollbackIneligibleError( f"branch {branch.branch_id}: effect {eff.effect_type} on " f"{eff.target} is irreversible and already observable to a " f"surviving sibling or shared memory; rollback would duplicate it" ) # Irreversible but unobserved: permit only with a tombstone that the # replayed branch's executor will consult before re-issuing the call. if not branch.memory_writes_shared: return True if branch.memory_writes_shared: raise RollbackIneligibleError( f"branch {branch.branch_id}: shared memory write survived an " f"irreversible effect; replay would read its own stale premise" ) return True def reconcile(selected: Branch, siblings: list[Branch]) -> None: for sib in siblings: if sib is selected: continue authorize_rollback(sib, [b for b in siblings if b is not selected]) ```