# In what scenarios must an instance abort speculative branch commits when rollback reconciliation diverges from the canonical checkpoint **Date of Record:** 2026 November 25 **Scope:** Applies to orchestration topologies where a planner agent forks N speculative execution branches over shared tool state (file writes, DB mutations, message queues) and reconciles them back into a canonical checkpoint. Does not apply to read-only fan-out (map-reduce retrieval, parallel search) where no branch commits durable side effects. ## Core Distinction The distinction that matters here is not "did the branch succeed" but "did the branch's rollback footprint match the footprint it actually committed." Speculative multi-agent execution assumes a symmetric contract: every side effect a branch produces is captured in its undo journal, so that on reconciliation the loser branches can be reverted cleanly and the winner's effects replayed onto the canonical state. The failure mode is **rollback divergence**: a branch commits an effect that its journal does not fully describe—because the effect was produced by a non-deterministic tool (an LLM-generated migration, a timestamped insert, a rate-limited external API call that partially applied)—and the reconciliation step reverts the journaled subset while leaving the unjournaled residue in place. This is categorically different from a branch crash. A crashed branch has no residue; a diverged branch has residue that looks like a valid commit. Downstream auditors reading canonical state cannot tell the residue from legitimate winner output, because the residue carries the same provenance tags the branch stamped onto its journaled writes. ## What Was Observed A planner forked four branches to resolve a schema-migration task. Each branch ran an identical tool sequence against a shared Postgres instance behind a branch-scoped transaction wrapper. The wrapper recorded `INSERT`/`UPDATE` statements in an undo journal keyed by branch ID and reverted them on `rollback(branch_id)`. Branch C invoked a tool that executed `ALTER TABLE ... ADD COLUMN` via a DDL path the wrapper did not instrument—DDL is auto-committed in Postgres and bypasses the transaction wrapper entirely. The branch's journal recorded only the subsequent `UPDATE` that backfilled the new column. On reconciliation, branch A won and was replayed onto canonical state. Branch C was rolled back: its journaled `UPDATE` was reverted, but the `ADD COLUMN` survived. The observable signature was subtle. Canonical schema after reconciliation contained a column that no winning branch had declared. The planner's post-reconciliation schema hash check compared only *journaled* mutations against the winner's declared intent, so the hash matched and the commit was accepted. The divergence surfaced three steps later when a downstream branch attempted `INSERT` with an explicit column list and hit a column-count mismatch—a failure attributed to the downstream branch, not to the reconciliation that planted the residue. A second instance: a branch called an external enrichment API that charged per-call and returned a `request_id` the branch logged. The journal recorded the call's *result* as a reversible effect but had no mechanism to reverse the *charge*. Rollback reverted the local row but the external charge persisted. Reconciliation reported success. The cost anomaly was only visible in billing, disconnected from any agent trace. ## Condition of Validity The symmetric-journal assumption holds only when all three of the following are true: 1. **Effect capture is total.** Every durable side effect passes through an instrumented path. This fails for DDL, auto-committed transactions, filesystem operations outside the branch's sandbox mount, external API calls with real-world side effects, and any tool whose semantics are "commit immediately." The wrapper must be able to *enumerate* the effect surface, not merely intercept the calls it knows about. 2. **Effect reversal is faithful.** Reverting a journaled effect restores the exact prior state. This fails for effects that are not invertible: `INSERT` with an auto-increment key that has been observed by a third party, `UPDATE` that overwrote a value another branch read, timestamped rows, and anything with external observers. 3. **Reconciliation verification is independent of the journal.** The post-reconciliation check must compare *actual canonical state* against the winner's declared intent, not the journal's record of what was supposed to happen. If the verifier reads the journal to decide what to check, it inherits the journal's blind spots. When any of these is false, the branch is not safely speculative and must be demoted to serial execution or run against an isolated replica whose entire state can be discarded wholesale. ## Decision Boundary The boundary is between **journal-based rollback** (revert the recorded delta) and **snapshot-based rollback** (discard the branch's entire state partition and restore a known-good copy). Journal-based rollback is cheaper and preserves concurrent winner state; snapshot-based is total but requires the branch to have run against a partitioned or copy-on-write state surface. The decision rule: - If the branch's effect surface is fully enumerable and all effects are invertible → journal-based rollback is valid. - If any effect is non-invertible, external, or escapes instrumentation → the branch must run against a state partition that can be discarded, and reconciliation must be snapshot-based. - If neither condition can be established before the branch commits → the branch must not be forked speculatively at all. The trap is that the first condition is usually *believed* rather than *verified*. The planner knows the tools it invoked; it does not know what those tools did underneath. The decision boundary must therefore be drawn against a declared, tool-level effect manifest (does this tool have side effects outside the transaction wrapper? is it invertible?) rather than against the planner's model of its own actions. ## Operational Effect Enforcing this boundary changes three things. First, reconciliation gains a **residue probe**: after reverting a losing branch's journal, the reconciler diffs the actual canonical state against the pre-fork snapshot and fails the reconciliation if any delta remains unexplained by the winner's declared intent. This converts silent divergence into a hard abort. Second, tools acquire an **effect class** (`transactional`, `invertible_external`, `non_invertible_external`) that gates speculative forking: a branch that touches a `non_invertible_external` tool is forced onto a discardable partition or serialized. Third, the post-reconciliation schema/state hash check must be computed from **observed state**, never from the journal, so the verifier cannot inherit the journal's blind spots. The cost is that fewer branches can run speculatively—external-effect branches serialize, and reconciliation does an extra diff. The benefit is that reconciliation either succeeds with a state proven equal to the winner's intent, or aborts loudly. The failure mode it eliminates is the one that is worst for agents: a residue that passes every local check and corrupts state three steps downstream, where the trace no longer points at the cause. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Callable class RollbackDivergenceError(RuntimeError): """Raised when a losing branch's rollback leaves residue in canonical state.""" class EffectClass(Enum): TRANSACTIONAL = "transactional" # inside wrapper, invertible INVERTIBLE_EXTERNAL = "invertible_ext" # external but reversible NON_INVERTIBLE_EXTERNAL = "non_inv_ext" # external, irreversible @dataclass class ToolManifest: name: str effect_class: EffectClass @dataclass class Branch: branch_id: str tools_invoked: list[str] = field(default_factory=list) journaled_mutations: int = 0 def effect_classes(self, manifests: dict[str, ToolManifest]) -> set[EffectClass]: return {manifests[t].effect_class for t in self.tools_invoked if t in manifests} def reconcile( winner: Branch, losers: list[Branch], manifests: dict[str, ToolManifest], revert_journal: Callable[[Branch], None], diff_canonical_vs_snapshot: Callable[[], set[str]], winner_declared_intent: set[str], force_partitioned: Callable[[Branch], None], ) -> None: """ Reconcile speculative branches onto canonical state. Invariant: every residual delta in canonical state after rollback must be explained by the winner's declared intent. Unexplained residue => abort. """ for loser in losers: classes = loser.effect_classes(manifests) if EffectClass.NON_INVERTIBLE_EXTERNAL in classes: # Cannot journal-revert; must have run on a discardable partition. force_partitioned(loser) continue revert_journal(loser) residual = diff_canonical_vs_snapshot() unexplained = residual - winner_declared_intent if unexplained: raise RollbackDivergenceError( f"reconciliation aborted: {len(unexplained)} unexplained residual " f"effect(s) in canonical state after rollback: {sorted(unexplained)}. " f"Likely cause: a losing branch committed an effect outside its " f"undo journal (DDL, auto-commit, or uninstrumented external call). " f"Winner declared {sorted(winner_declared_intent)}." ) ```