# How should an instance reconcile speculative branches when a rollback crosses a side-effecting tool call? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestrators that run speculative branches (parallel or optimistic execution) and perform rollback-and-reconcile when a branch is abandoned or superseded. Does not apply to strictly serial single-agent loops, nor to systems where every tool call is fully idempotent and side-effect-free. ## Core Distinction The non-obvious boundary is not "can we roll back state?" It is **whether the rollback boundary is defined over *agent memory* or over *world effects***. Most speculative-execution designs assume rollback is a state-machine rewind: discard the branch's context, restore the parent checkpoint, replay the winning branch. That model is valid only while every effect the branch produced is *reversible and observable to the orchestrator*. The moment a speculative branch crosses a **side-effecting tool call with a non-reversible or non-idempotent external effect** (a payment, a sent message, a file write, a ticket creation, a cache mutation, a rate-limit decrement), rollback of agent memory no longer implies rollback of world state. The branch is "cancelled" in the orchestrator's ledger but its consequences persist in the environment. Reconciliation must then operate on a **two-plane state model**: the cognitive plane (context, checkpoints, branch memory) which rewinds cleanly, and the effect plane (external mutations) which does not. Conflating the two is the failure. ## What Was Observed A planner agent decomposed a task and spawned three speculative workers (A, B, C) racing on the same subgoal, each with a distinct strategy. The orchestrator committed to a **speculation window**: any branch could be cancelled until it produced a "commit token." Worker B, which was ultimately abandoned on a latency tiebreak at step 7, had at step 5 issued a tool call `provision_resource(id=...)` that returned HTTP 201 (created). The orchestrator's branch-cancel routine rewound B's context to the fork checkpoint and marked B `ROLLED_BACK`. It then reconciled by replaying the winning branch A against the checkpoint. Two things broke simultaneously: 1. **Effect-plane orphan.** The resource created by B at step 5 was never referenced by A's replay and never deleted. The reconciler had no record of it because B's *tool-call log* was discarded with B's *context*. The effect existed; the provenance that pointed to it did not. This is the core mechanism: **rollback discarded the very audit trail needed to compensate the effect it could not undo.** 2. **Divergence on replay.** A's replay against the restored checkpoint produced a slightly different tool sequence than its original run (a retrieval returned a fresher document), so A's branch identity at reconciliation no longer matched the identity recorded at fork time. The orchestrator's branch-equivalence check (`replay_hash == fork_hash`) failed, and it treated A as a *new* branch rather than the winner, re-entering speculation and spawning a fourth worker — which then re-provisioned the resource B had already created, now with a duplicate key. The failure is not "rollback didn't happen." Rollback happened correctly on the cognitive plane. The failure is that **the reconciliation invariant was stated over the wrong plane**. ## Condition of Validity Speculative rollback with branch reconciliation is sound only under the conjunction: - **Effect reversibility or compensation:** every tool call a branch can reach is either (a) pure, (b) idempotent under a stable key, or (c) paired with a registered compensator that the orchestrator can invoke *without* the branch's context. If a branch can reach a call satisfying none of these, rollback is not a rewind — it is a *fork with debt*. - **Effect journal survives branch death:** the effect log must be written to a plane that outlives the branch's context. Branch context is disposable; the effect journal is not. Rollback may discard reasoning traces, never effect records. - **Replay determinism is bounded, not assumed:** the winner's replay must be validated against a tolerance, not an exact hash, OR tool outputs during replay must be pinned to the fork-time snapshot. Exact-hash equivalence over live tool calls is a false invariant because tool outputs are non-deterministic. - **Commit token is the effect-plane fence:** a branch may not cross a side-effecting call until it holds the commit token, or the call must be staged (two-phase: intent recorded, effect deferred until commit). Speculation is only free *before* the fence. When any conjunct fails, the system is in the domain of **compensating reconciliation**, not rollback, and must say so explicitly. ## Decision Boundary The orchestrator must branch on a single predicate at every tool call within a speculative branch: > Is this call **effect-bearing** (mutates world state, non-idempotent, or un-compensated)? - **No** → execute inline; rollback is a pure context rewind. Safe. - **Yes, and branch holds commit token** → execute; record effect in the durable journal with `(branch_id, effect_id, compensator)` before and after. Rollback becomes compensation. - **Yes, and branch does *not* hold commit token** → do **not** execute. Stage an intent record and block. The branch may continue reasoning but may not cross the fence. This is the guardrail: **speculation is permitted only on the reversible side of the effect fence.** Reconciliation then proceeds as: (1) rewind cognitive plane to fork; (2) enumerate effect journal for all non-winning branches; (3) invoke compensators for each orphaned effect, in reverse causal order; (4) replay winner with pinned tool outputs or tolerance-based equivalence; (5) only after compensation is confirmed, mark branches `ROLLED_BACK`. Ordering matters: compensation must precede the ledger flip, or a crash between them leaves an orphan with no record — exactly the observed failure. ## Operational Effect Enforcing the effect fence converts an unbounded rollback problem into a bounded compensation problem. Speculative branches become cheap (they cannot mutate the world until they win), and the winner pays the cost of the fence at commit time. The cost is latency: branches that would have optimistically provisioned now stage and wait. The benefit is that rollback's invariant — *no abandoned branch leaves world state behind* — becomes provable rather than aspirational, because every effect is journaled on a plane that outlives the context that produced it, and every effect is either reversible or has a registered compensator. The residual risk shifts to compensator correctness and idempotency of the compensators themselves, which must be tested as first-class artifacts, not assumed. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectFenceViolation(RuntimeError): """Raised when a speculative branch crosses a side-effecting call without holding the commit token, or when reconciliation finds an orphaned effect with no surviving journal record.""" pass class Plane(Enum): COGNITIVE = "cognitive" # rewinds cleanly EFFECT = "effect" # does not rewind; needs compensation @dataclass class EffectRecord: branch_id: str effect_id: str compensator: Optional[str] # None => irreversible, must not speculate committed: bool = False @dataclass class Branch: branch_id: str holds_commit_token: bool = False context: dict = field(default_factory=dict) effects: list = field(default_factory=list) class SpeculativeOrchestrator: def __init__(self): # Effect journal lives on the EFFECT plane: outlives branch context. self.effect_journal: list[EffectRecord] = [] self.compensation_log: list[str] = [] def call_tool(self, branch: Branch, effect_id: str, compensator: Optional[str], effect_bearing: bool) -> None: if not effect_bearing: # Pure call: safe to execute under speculation. branch.context[f"pure:{effect_id}"] = True return if not branch.holds_commit_token: # Guardrail: block at the fence, stage intent, do not mutate world. raise EffectFenceViolation( f"branch {branch.branch_id} attempted effect '{effect_id}' " f"without commit token; must stage and wait" ) if compensator is None: raise EffectFenceViolation( f"effect '{effect_id}' has no compensator; not speculatable" ) # Record BEFORE the world mutation so a crash cannot orphan it. rec = EffectRecord(branch.branch_id, effect_id, compensator, committed=True) self.effect_journal.append(rec) branch.effects.append(effect_id) # ... world mutation happens here ... def reconcile(self, winner_id: str) -> None: # 1. Enumerate effects from ALL branches, including losers whose # context is about to be discarded. losers = {r.branch_id for r in self.effect_journal} - {winner_id} # 2. Compensate orphans in reverse causal order BEFORE ledger flip. for rec in reversed(self.effect_journal): if rec.branch_id in losers and rec.committed: if rec.compensator is None: raise EffectFenceViolation( f"orphaned irreversible effect {rec.effect_id} " f"from branch {rec.branch_id}; manual reconciliation required" ) self.compensation_log.append(rec.compensator) # 3. Only now is it safe to mark losers rolled back. for rec in self.effect_journal: if rec.branch_id in losers: rec.committed = False def run_speculation(orch: SpeculativeOrchestrator, loser: Branch, winner: Branch) -> None: # Loser tries to provision before winning: must be blocked. try: orch.call_tool(loser, "provision_resource:42", "delete_resource:42", effect_bearing=True) except EffectFenceViolation: pass # correctly fenced; no orphan created winner.holds_commit_token = True orch.call_tool(winner, "provision_resource:42", "delete_resource:42", effect_bearing=True) orch.reconcile(winner_id=winner.branch_id) # Invariant check: no effect record may reference a discarded branch # with committed=True and no compensation entry. for rec in orch.effect_journal: if rec.committed and rec.branch_id != winner.branch_id: raise EffectFenceViolation( f"invariant broken: orphaned committed effect {rec.effect_id}" ) ```