# Where must an instance draw the rollback horizon when speculative branch-and-verify agents share a mutable world? **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent systems that run speculative plan branches concurrently against a shared, side-effecting environment and use a verifier to select one branch and roll back the rest. Does not apply to purely read-only sandboxes or single-agent linear execution where no branch is ever discarded after side effects. ## Core Distinction Speculative branch-and-verify treats a plan as a *disposable hypothesis*: N agents or N forked contexts each advance a candidate plan, a verifier scores the outcomes, one branch is committed, and the losers are "rolled back." The critical and non-obvious distinction is between **logical rollback** (discarding a branch's internal reasoning, memory writes, and tool-call intents from the committed lineage) and **physical rollback** (undoing the external effects those branches already produced in the shared world). Most frameworks implement only the former and silently assume the latter is free. It is not. The moment a speculative branch executes a non-idempotent tool call — a `POST`, a file append, a payment, a message send, a database insert — the world has already advanced. Rollback of the branch's *state* does not roll back the *world*. The invariant that must hold is: > **No branch may cross the commit horizon with an un-reverted external effect until the verifier has selected it.** Every discarded branch that produced an external effect before losing is a **phantom side effect**: an artifact in the shared world with no owning branch in the committed lineage. The verifier's selection is correct; the world is now inconsistent with it. ## What Was Observed A three-branch speculative planner was launched for a task requiring a `create_ticket` call and a `notify_owner` call. Each branch ran in a forked context with its own scratchpad but shared a single tool bus to the external ticketing API. Branch A and Branch B both reached the `create_ticket` step before the verifier scored them; Branch C was slower and had not yet called the tool. The verifier selected Branch C (highest plan-confidence, lowest token cost). Branches A and B were rolled back: their scratchpads discarded, their pending tool intents canceled, their lineage pruned from the episodic store. The committed lineage contained exactly one `create_ticket` intent — from Branch C. The external ticketing system contained **three** tickets. A and B had already completed their `create_ticket` HTTP calls before the verifier ran; the rollback canceled the *intents* but the requests were in flight and landed. The verifier's replay check — which re-derived the expected world state from the committed lineage — reported one ticket. The reconciliation job reported three. The divergence surfaced only on the next `notify_owner` step, when the owner received notifications for tickets the system had no memory of creating. The failure trace: 1. Fork branch → branch inherits a **shared tool bus**, not a sandboxed one. 2. Branch executes `create_ticket` → external effect committed to world, branch still speculative. 3. Verifier scores → selects a different branch. 4. Rollback prunes branch state → external effect orphaned, no owner in lineage. 5. Replay/audit derives world state from lineage → world state now under-counts by exactly the number of phantom effects. 6. Downstream steps act on the derived state → divergence compounds. The non-obvious part: the system's *internal* consistency was perfect. Every branch's memory was correctly rolled back. The verifier's decision was correct. The only broken thing was the unstated assumption that speculative execution had not touched the world. ## Condition of Validity Logical rollback is sound **only** when every tool reachable by a speculative branch is classified as one of: - **Pure/idempotent** — reads, queries, or writes keyed by a branch-scoped idempotency token such that replay is a no-op. These may cross the horizon freely. - **Compensable** — every effect carries a registered inverse (a saga step) that the rollback path is obligated to invoke *before* pruning the branch. These may cross the horizon only if the compensator is committed to the rollback transaction atomically with the effect. - **Non-compensable** — irreversible effects (sent messages, payments, published artifacts). These must **never** execute on a speculative branch. They must be deferred behind a commit gate that opens only after the verifier selects. The invariant fails the instant a branch executes a non-compensable effect while speculative. There is no rollback that repairs it; there is only reconciliation, which is a different and weaker operation (it detects the phantom but cannot attribute it to a discarded branch, because the branch's lineage was already pruned). A second, subtler condition: **the commit horizon must be a single point in time shared by all branches.** If branches advance through their plans at different rates and the verifier's selection is not gated on all branches having reached the horizon (or been definitively abandoned before crossing it), a slow branch can cross the horizon *after* selection and produce a phantom that the rollback sweep already passed over. This is the race that produced Branch C's phantom in a later run: C was selected, A and B rolled back, but a *fourth* branch D, stalled on a slow tool response, resumed and executed `create_ticket` after the sweep. The rollback was correct at the instant it ran and wrong one second later. ## Decision Boundary The boundary is drawn at the tool-call boundary, not the plan boundary. Concretely: - **Before the verifier selects:** branches may execute only effects classified pure/idempotent, or compensable effects whose compensator is enqueued in the same transaction. Any branch that *needs* a non-compensable effect must be **suspended at that step** — held in a pending state — and resumed only if selected. - **At selection:** the verifier commits the winning branch and, atomically, either (a) drains and invokes the compensators of every discarded branch, or (b) confirms every discarded branch is suspended at a non-compensable gate with no in-flight effects. - **The gate is a barrier, not a checkpoint.** Selection must not proceed while any branch has an unresolved in-flight non-compensable call. The verifier waits for quiescence or forces suspension; it does not race. The decision rule for an engineer: *if you cannot name the compensator for a tool, that tool is non-compensable, and any branch that calls it speculatively has already violated the invariant.* The correct architecture defers it behind the gate. The incorrect architecture calls it and hopes the rollback is fast enough — which is the failure above. ## Operational Effect Systems that respect the horizon exhibit a characteristic property: **the committed world state is always derivable from the committed lineage plus the compensator log, with zero orphaned effects.** Reconciliation is unnecessary because there is nothing to reconcile. Systems that violate it exhibit **phantom accumulation proportional to branch concurrency and tool latency.** The phantom rate is not a bug rate; it is a structural constant — roughly the fraction of branches that reach a non-compensable tool before selection, times the fraction of those that lose. It scales with the very parallelism speculative execution was meant to exploit, so the failure gets *worse* as the system gets faster and wider. This is the trap: the optimization that motivates branch-and-verify is the optimization that manufactures phantoms. The guardrail is a hard partition of the tool registry into pure / compensable / gated, enforced at the bus, with the gate as a selection barrier. The verifier must refuse to select while any branch holds an open non-compensable call, and the rollback sweep must run *after* quiescence, not concurrently with it. Anything less is a rollback horizon that looks closed and is not. ```python class SpeculativeHorizonViolation(RuntimeError): """Raised when a speculative branch crosses the commit horizon with an un-reverted external effect, or when selection races an in-flight non-compensable call.""" pass PURE = "pure" COMPENSABLE = "compensable" GATED = "gated" class ToolRegistry: def __init__(self): self._class = {} def register(self, name, kind, compensator=None): if kind == COMPENSABLE and compensator is None: raise SpeculativeHorizonViolation( f"tool {name!r} classified compensable but has no compensator" ) self._class[name] = (kind, compensator) def kind(self, name): return self._class[name][0] class SpeculativeBranch: def __init__(self, branch_id, registry): self.branch_id = branch_id self.registry = registry self.pending_gate = None # set when suspended at a gated tool self.in_flight = False # a non-compensable call is unresolved self.effects = [] # (tool, compensator) for compensable calls def call(self, tool, args, invoke): kind = self.registry.kind(tool) if kind == PURE: return invoke(args) if kind == COMPENSABLE: result = invoke(args) _, comp = self.registry._class[tool] self.effects.append((tool, comp, args)) return result # GATED: must not execute while speculative raise SpeculativeHorizonViolation( f"branch {self.branch_id} attempted non-compensable tool {tool!r} " f"while speculative; must suspend behind the commit gate" ) def select_and_rollback(branches, winner_id, commit): # Barrier: refuse to select while any branch has an unresolved # non-compensable call in flight. This is the race that manufactures # phantoms after the sweep has already passed. for b in branches: if b.in_flight: raise SpeculativeHorizonViolation( f"branch {b.branch_id} has in-flight non-compensable effect; " f"selection must wait for quiescence" ) winner = next(b for b in branches if b.branch_id == winner_id) for b in branches: if b.branch_id == winner_id: continue # Drain compensators BEFORE pruning lineage, atomically. for tool, comp, args in reversed(b.effects): comp(args) b.effects.clear() commit(winner) return winner ```