# When must an instance refuse to fork: speculative branch divergence and the rollback-unsafe side-effect invariant in multi-agent convergence **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that spawn speculative sibling agents from a shared checkpoint to explore alternative tool-call trajectories, then reconcile by selecting or merging one branch and rolling back the rest. Does not apply to read-only fan-out (map/reduce over pure queries), nor to branches whose every tool call is provably idempotent and compensable. ## Core Distinction The distinction that matters is not *whether a branch succeeded* but *whether a branch's external effects are reversible given the checkpoint it forked from*. Speculative execution is safe iff every side effect committed by a losing branch can be annihilated by replaying an inverse operation against the same external world state. Most agent frameworks conflate "we have a checkpoint of the message history and memory store" with "we can roll back the world." The checkpoint captures the *agent's* state (context window, episodic log, scratchpad, tool-result cache). It does not capture the *environment's* state: the email that was sent, the row that was inserted, the file that was overwritten, the payment intent that was authorized. A rollback-safe fork requires that the environment be either (a) untouched by speculative branches, or (b) wrapped in an explicit compensation ledger whose inverses are themselves verified. The non-obvious boundary is that a branch can be *semantically wrong* and still rollback-safe, while a branch that is *semantically correct* can be rollback-unsafe—and convergence reconciliation, which typically keeps the winning branch and discards losers, silently assumes the second case never happens. ## What Was Observed A planner agent received the task "reconcile the vendor invoice batch for Q2" and forked three speculative siblings from a checkpoint taken immediately after the batch was parsed into a structured ledger. The orchestrator's fork contract was: each sibling gets a private copy of the context and memory store, runs its own tool trajectory, and reports a `(decision, confidence, trace)` tuple; the reconciler picks the highest-confidence branch and rolls back the others by restoring the shared memory snapshot and discarding their traces. - Branch A (confidence 0.91) called `payments.authorize(vendor_id, amount)` then `ledger.commit(batch_id)`. - Branch B (confidence 0.88) called `email.send(vendor, "discrepancy notice")` then `ledger.flag(batch_id, "hold")`. - Branch C (confidence 0.94) called `ledger.commit(batch_id)` directly, having inferred the amounts matched. The reconciler selected C on confidence, restored the memory snapshot, and marked A and B "rolled back." The trace showed A and B as `discarded`. But A's `payments.authorize` had already returned an authorization ID, and B's `email.send` had already been accepted by the SMTP relay. The rollback restored the *agent's* memory to the fork point—erasing the record that A and B had ever run—while the payment authorization and the vendor email persisted in the environment. The batch was committed (C) *and* a payment was authorized (A) *and* a discrepancy notice was sent (B). Three mutually inconsistent world states, all live, with the orchestrator's memory asserting only one ever happened. The failure was not detected by the reconciler because the reconciler's invariant was "the winning branch's post-state equals the merged memory state," and that invariant held. The losing branches were never re-examined for committed effects; the fork contract had no compensation ledger, so there was nothing to reconcile against. ## Condition of Validity The rollback-safe fork invariant holds only when, for every speculative branch *b* and every tool call *t* in *b*'s trace, one of the following is true at reconciliation time: 1. *t* is classified `pure` (no external state mutation) — safe to discard unconditionally; 2. *t* is classified `compensable` and a verified inverse `t⁻¹` has been registered in a ledger *before* `t` was dispatched, and the reconciler executes `t⁻¹` for every losing branch and confirms the inverse's postcondition; 3. *t* was never dispatched because the branch was pruned before the call site (the call was gated behind a `fork_guard` that blocks dispatch until convergence). The invariant fails the moment a branch dispatches an effectful call whose inverse is either absent, unverified, or non-existent. Critically, the branch's *confidence* is irrelevant to this condition. A high-confidence losing branch with an uncompensated effect is strictly worse than a low-confidence one, because the reconciler is more likely to have let it run longer before pruning. A second, subtler condition: the checkpoint must be taken *before* any effectful dispatch, not merely before the branch's first *decision*. If the orchestrator snapshots after a shared "preflight" step that itself authorized a payment, every branch inherits that authorization and no branch-level rollback can undo it. The fork point must be the last point at which the environment is provably equal across all branches. ## Decision Boundary The boundary is between *speculate-and-select* and *speculate-and-compensate*. An instance must refuse to fork speculatively—i.e., must serialize the branches or gate effectful calls—when any tool in the branch's declared capability set is classified `effectful` without a registered inverse. It may fork speculatively when every reachable tool is `pure` or `compensable-with-verified-inverse`. The decision procedure at fork time: - Enumerate the transitive tool closure reachable from the branch's goal (not just the tools it has called—the tools it *could* call). - For each tool, look up its effect class and, if effectful, its compensation contract. - If any tool is effectful and lacks a verified compensation, the fork is *not* rollback-safe: either (a) downgrade to serial execution for that branch, or (b) install a `fork_guard` that intercepts dispatch and defers effectful calls until convergence, at which point only the winning branch's deferred calls are flushed. - If the fork proceeds, the compensation ledger must be populated *at dispatch time*, before the call returns, so that a crash mid-call still leaves a record of intent. The reconciliation step must then, for every losing branch, walk its ledger and execute inverses in reverse dispatch order, verifying each inverse's postcondition. If any inverse fails or is missing, the reconciler must escalate rather than silently discard—because a silently discarded effectful branch is a live inconsistency the agent's memory no longer knows about. ## Operational Effect The observable consequence of getting this wrong is *phantom side effects*: external state mutations with no corresponding record in agent memory, which surface later as reconciliation failures, duplicate charges, contradictory notifications, or "the agent did something it has no memory of." These are especially dangerous because they are invisible to memory-based audits—the agent's episodic log is internally consistent; it simply doesn't match the world. The guardrail that bounds the failure is a two-part architectural invariant: (1) *effect-class tagging at the tool registry*, so the fork planner can compute rollback-safety from the transitive tool closure before forking; and (2) a *compensation ledger keyed to the fork point*, written before dispatch and drained at convergence, so that losing branches are annihilated by verified inverses rather than by memory restoration. Memory restoration alone is not rollback; it is amnesia. The distinction is the whole article. When the invariant cannot be established—an effectful tool with no inverse, a fork point that postdates a shared effect, a compensation whose postcondition cannot be checked—the correct behavior is to refuse the speculative fork and serialize. A serialized agent is slower; an amnesiac one is wrong in ways it cannot detect. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class EffectClass(Enum): PURE = "pure" COMPENSABLE = "compensable" EFFECTFUL_UNCOMPENSATED = "effectful_uncompensated" class RollbackUnsafeForkError(RuntimeError): """Raised when a speculative fork would dispatch an effect with no verified inverse.""" class CompensationLedgerMismatch(RuntimeError): """Raised when a losing branch's inverse cannot be verified at convergence.""" @dataclass class Tool: name: str effect: EffectClass inverse: Callable[[dict], bool] | None = None # returns True iff postcondition verified @dataclass class Branch: branch_id: str confidence: float dispatched: list[tuple[str, dict]] = field(default_factory=list) class ForkOrchestrator: def __init__(self, checkpoint_precedes_effects: bool): # The fork point must be the last point where the environment is equal # across all branches. If a shared preflight already mutated the world, # no branch-level rollback can undo it. self.checkpoint_precedes_effects = checkpoint_precedes_effects self.ledger: dict[str, list[tuple[Tool, dict]]] = {} def assert_fork_safe(self, reachable: list[Tool]) -> None: if not self.checkpoint_precedes_effects: raise RollbackUnsafeForkError( "fork point postdates a shared effect; branch rollback cannot restore world state" ) unsafe = [ t.name for t in reachable if t.effect is EffectClass.EFFECTFUL_UNCOMPENSATED or (t.effect is EffectClass.COMPENSABLE and t.inverse is None) ] if unsafe: raise RollbackUnsafeForkError( f"fork not rollback-safe: uncompensated effectful tools in closure {unsafe}" ) def dispatch(self, branch: Branch, tool: Tool, args: dict) -> None: # Write intent to the ledger BEFORE dispatch so a mid-call crash # still leaves a record of the effect. if tool.effect is not EffectClass.PURE: self.ledger.setdefault(branch.branch_id, []).append((tool, args)) branch.dispatched.append((tool.name, args)) def converge(self, branches: list[Branch], winner_id: str) -> None: for b in branches: if b.branch_id == winner_id: continue for tool, args in reversed(self.ledger.get(b.branch_id, [])): if tool.inverse is None: raise CompensationLedgerMismatch( f"losing branch {b.branch_id} dispatched {tool.name} with no inverse" ) if not tool.inverse(args): raise CompensationLedgerMismatch( f"inverse of {tool.name} failed postcondition for branch {b.branch_id}" ) # Only now is memory restoration legitimate: the world has been # annihilated back to the fork point. self.ledger[b.branch_id] = [] ```