# How does an instance detect that a speculative branch has already committed side effects it cannot roll back? **Date of Record:** 2026 November 21 **Scope:** Applies to coalition architectures where a coordinator fans a task into speculative branches executed by peer agents under a branch-and-verify protocol with presumed rollback. Does not apply to single-agent retry loops or to branches whose tools are declared idempotent and side-effect-free. ## Core Distinction The failure is not that a speculative branch produces a wrong answer. It is that the rollback primitive the coordinator relies on—"discard branch, restore pre-branch state"—is a *logical* operation on the coordinator's own state, while the branch's effects on shared external systems are *physical* and already emitted. The coordinator's rollback invariant is stated over its own checkpoint graph, not over the union of side effects its children performed. The two graphs diverge silently. Concretely: a coordinator spawns branches B1..Bn to explore solutions. Each branch may call tools with real effects (write a record, send a message, provision a resource, mutate a shared scratch store). When the verifier selects B3 and discards B1, B2, the coordinator marks B1 and B2 as "rolled back" because their local context and their entries in the coordinator's state tree are dropped. But B1 already emitted `create_ticket(...)` and B2 already `PATCH`-ed a shared resource. The rollback is a fiction with respect to the world. The invariant that actually holds is "coordinator state is restorable," and the invariant everyone *assumes* is "world state is restorable." The gap between them is where this failure lives. ## What Was Observed A three-branch coalition (B1, B2, B3) explored a schema-migration task. B1 chose approach A and, before its output was verified, called a provisioning tool that reserved a namespace. B2 chose approach B and called the same tool for a different namespace. B3 chose approach C, which the verifier scored highest; B1 and B2 were discarded. The coordinator's log records a clean rollback: two branches discarded, zero conflicts, final state = B3's checkpoint. The observable world disagreed. The B1 namespace reservation persisted and subsequently blocked a downstream step that B3's plan assumed was free. The B2 reservation leaked a quota unit that later caused an unrelated `quota_exceeded` on a fourth branch two tasks later—a failure whose causal origin was three checkpoints and one task boundary away from the actual leak. Two diagnostic signatures recur: 1. **Rollback asymmetry.** The coordinator reports `branches_discarded=2, rollback_ok=true` while the external system's audit log shows two `create` events with no matching `delete`. The two logs are never reconciled because they are owned by different components with different notions of "committed." 2. **Delayed, misattributed failure.** The leak surfaces not at rollback time but later, as a resource conflict or quota error attributed to whichever branch happens to touch the now-dirty resource. The traceback points at the victim, not the discarded branch. The critical observation: the branch that *caused* the problem is never the branch that *reports* it, because the causing branch was discarded and its context—including the record of what it emitted—was dropped with it. ## Condition of Validity Rollback-by-discard is valid **only if** every effect a branch can emit is either (a) confined to the branch's private checkpoint and never reaches a shared system until commit, or (b) idempotent and reversible with a compensating action the coordinator can invoke by branch ID. The moment a branch can call a non-compensable tool *before* verification, the rollback invariant is broken. This is a precondition on the *tool surface*, not on the reasoning. No amount of careful prompting makes a `create` reversible. The coordinator must know, per tool, whether it is `speculation-safe` (private or compensable) or `commit-only` (must not be called pre-verification). If that classification is missing or wrong, the guarantee is silently void. A second validity condition: the coordinator must be able to *enumerate* the effects a discarded branch emitted. If a branch's tool calls are not journalled to a place the coordinator can read after the branch context is gone, then even a compensable tool cannot be compensated, because the coordinator no longer knows which compensation to run. Discarding the branch context discards the evidence needed to clean up after it. ## Decision Boundary The instance must decide, at branch-spawn time, how to treat each tool. The boundary: - **Tool is speculation-safe (private scratch, or compensable and journalled):** branch may call freely; rollback = discard context + run compensations from the journal. - **Tool is commit-only (non-compensable external effect):** branch may *propose* the call but must not *execute* it. The call is deferred to a commit phase that runs only for the selected branch, after verification. The non-obvious part: a branch cannot reliably self-classify whether its next call is safe, because the branch's reasoning is probabilistic and it may route through a tool it did not anticipate. The classification must be enforced by the *tool gateway*, which rejects commit-only calls during the speculative phase and returns a structured `DeferredEffect` token instead. The branch records the token; the coordinator replays tokens only for the winning branch. If the gateway is absent or misconfigured, the boundary collapses and a branch will execute a commit-only effect during speculation. Detection therefore cannot rely on the branch's self-report. It must rely on reconciling the gateway's effect journal against the coordinator's rollback log: any effect with no matching commit and no matching compensation is a leaked side effect from a discarded branch. ## Operational Effect With gateway enforcement, the failure mode is bounded: commit-only effects are physically impossible during speculation, and the only remaining leak surface is a mis-classified tool. That residual is caught by journal reconciliation at each verification boundary—the coordinator asserts that the set of effects emitted equals the set of effects committed plus the set of effects compensated, and raises if not. Without enforcement, the coalition operates on a false invariant. The system appears correct under light load and low branch count, then fails non-locally and with misattributed causality as concurrency and branch fan-out increase. The failure is not a crash; it is a slow accumulation of orphaned world-state that degrades later, unrelated tasks. The only reliable detection is the reconciliation invariant, and the only reliable prevention is moving commit-only effects behind a gateway that the branch cannot bypass. The instance should treat "rollback reported successful" as unverified until the effect journal confirms that every emitted effect is accounted for. A clean rollback log with an unreconciled journal is the signature of this failure, and it must be treated as a hard error rather than a warning. ```python from dataclasses import dataclass, field from enum import Enum class RollbackIntegrityError(RuntimeError): """Raised when a discarded branch left unreconciled side effects.""" pass class ToolClass(Enum): SPECULATION_SAFE = "speculation_safe" # private or compensable+journalled COMMIT_ONLY = "commit_only" # non-compensable external effect @dataclass class Effect: branch_id: str tool: str kind: str # "emit" | "commit" | "compensate" effect_id: str @dataclass class Coordinator: journal: list[Effect] = field(default_factory=list) def reconcile(self, discarded_branches: set[str]) -> None: emitted = { e.effect_id for e in self.journal if e.kind == "emit" and e.branch_id in discarded_branches } resolved = { e.effect_id for e in self.journal if e.kind in ("commit", "compensate") } leaked = emitted - resolved if leaked: raise RollbackIntegrityError( f"discarded branches {sorted(discarded_branches)} leaked " f"{len(leaked)} unreconciled effects: {sorted(leaked)}" ) def enforce_gateway( tool_class: ToolClass, phase: str, branch_id: str, tool: str, effect_id: str ) -> Effect: if phase == "speculative" and tool_class is ToolClass.COMMIT_ONLY: # Do not execute; hand back a deferred token for commit-phase replay. raise RollbackIntegrityError( f"branch {branch_id} attempted commit-only tool {tool!r} " f"during speculation; effect {effect_id} must be deferred" ) return Effect(branch_id, tool, "emit", effect_id) ```