# Why does an instance commit a speculative branch it cannot roll back when a sibling agent's tool side effect lands after the merge barrier? **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent pipelines that fan out parallel proposal branches under an optimistic-commit model, where at least one branch invokes a non-idempotent external tool (write, send, charge, deploy) and a coordinator merges results before all branch side effects are confirmed durable or compensable. Does not apply to purely read-only fan-out or to pipelines using strict two-phase commit with pre-declared compensations. ## Core Distinction The distinction that matters is between *proposal validity* and *commit reversibility*. A speculative branch can be logically valid—its reasoning chain reconciles, its schema conforms, its asserted facts check out—while being physically irreversible because one of its tool calls already mutated the world before the coordinator's merge barrier closed. Optimistic commit conflates these: it treats "the branch produced a well-formed result" as "the branch can be safely abandoned." That conflation is the failure source. The non-obvious part: rollback reconciliation is usually designed around the *branch's own* state (discard its context, revert its memory writes, drop its proposed diff). It rarely accounts for the case where the branch's irreversible effect is a *precondition* that a sibling branch consumed. When the coordinator rolls back branch A after merging branch B, branch B's committed result may have been computed against A's now-revoked side effect, producing a merged state that is internally consistent in the log but inconsistent in the world. ## What Was Observed A three-branch fan-out: branches A, B, C each receive the same task decomposition and propose a plan. Branch A calls `provision_resource(id=xyz)` (non-idempotent, returns a handle). Branch B, in parallel, reads cluster capacity, sees xyz now allocated, and proposes a plan that *assumes* xyz is reserved. Branch C fails a schema check and is discarded cleanly. Coordinator merges A and B optimistically—both returned well-formed proposals within the latency budget. The merge barrier closes on *message receipt*, not on *side-effect durability*. Branch A's provisioning call then times out at the transport layer (the request landed, the acknowledgment was lost). The coordinator, seeing A's timeout, marks A as failed and rolls it back: it discards A's context, revokes the provisioning intent, and writes a rollback record. But A's provisioning *did* land. B's committed plan now references a resource the coordinator believes was never allocated. The merged state passes every local consistency check because the rollback record and B's plan are both internally coherent—they simply describe disjoint worlds. The observable signature is a *phantom dependency*: a committed branch whose provenance chain includes a sibling's side effect that the coordinator's rollback ledger marks as reverted. It surfaces later as a runtime error in B's plan ("resource xyz not found") with no corresponding failure in the rollback log, because the rollback log is correct about what it *intended* to revert. ## Condition of Validity The optimistic-commit-with-rollback pattern is only sound when all three hold: 1. **Side-effect visibility precedes merge.** Every branch's irreversible effects must be durably recorded (with a handle) before the coordinator accepts the branch into the merge set. Receipt of a proposal message is not evidence of side-effect durability. 2. **Cross-branch dependency is declared or forbidden.** If branch B may consume branch A's side effect, that dependency must be an explicit edge in the merge DAG, forcing B to commit after A's durability is confirmed. Undeclared consumption is the escape hatch this failure exploits. 3. **Rollback is compensable, not just discardable.** Rolling back a branch that mutated the world requires a registered compensation (delete_resource, refund, revert_deploy), not merely dropping its context. A rollback that only rewrites the ledger is a bookkeeping fiction. When any of these is violated—particularly (1) under transport timeout, where "no ack" is misread as "no effect"—the invariant breaks silently. ## Decision Boundary The coordinator must decide, at the moment a branch's tool call times out, whether the branch is *failed* or *unknown*. The correct boundary: - **Treat timeout as UNKNOWN, never as FAILED**, for any branch that has dispatched a non-idempotent call. UNKNOWN branches must be resolved by an idempotency-keyed probe (`get_resource(id=xyz)`) before any sibling branch is allowed to commit a result that could depend on them. - **Block merge on UNKNOWN.** The merge barrier waits for probe resolution or a bounded deadline, then escalates to a reconciler—it does not optimistically commit siblings and defer reconciliation. - **Forbid undeclared cross-branch reads of side-effect state.** If B's reasoning reads state that A mutates, the DAG must serialize B after A's durability confirmation. Parallelism is only permitted across branches with disjoint effect footprints. The failure occurs precisely when the coordinator crosses this boundary in the wrong direction: it resolves UNKNOWN to FAILED by timeout, commits siblings, and defers the discrepancy to a reconciliation pass that has no authority to un-commit already-merged results. ## Operational Effect Downstream, the phantom dependency manifests as a *split-brain merge*: the coordinator's ledger and the external world disagree about which side effects exist, and the committed plan is built on the wrong one. Recovery requires either re-provisioning (masking the bug, doubling cost) or invalidating the committed branch (which may already have triggered its own downstream effects). The invariant to enforce: **a branch may only be committed into the merge set once every side effect it *or any sibling that read it* depends on has confirmed durability, and every rollback carries a registered compensation rather than a ledger edit.** Enforce it by making the merge barrier gate on durability probes, not message receipt. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpeculativeCommitError(RuntimeError): """Raised when optimistic commit would merge a branch whose side-effect durability is unconfirmed or whose rollback lacks a compensation.""" pass class EffectStatus(Enum): NOT_DISPATCHED = "not_dispatched" DISPATCHED_UNKNOWN = "dispatched_unknown" # timeout: landed? unknown CONFIRMED_DURABLE = "confirmed_durable" COMPENSATED = "compensated" @dataclass class Branch: branch_id: str non_idempotent_handle: Optional[str] = None effect_status: EffectStatus = EffectStatus.NOT_DISPATCHED reads_sibling_effects: set = field(default_factory=set) def probe_durability(handle: str, deadline_s: float = 2.0) -> EffectStatus: """Idempotency-keyed probe. In production this calls the resource API; here we simulate an unresolved timeout.""" start = time.monotonic() while time.monotonic() - start < deadline_s: # real impl: if resource_api.exists(handle): return CONFIRMED_DURABLE time.sleep(0.1) return EffectStatus.DISPATCHED_UNKNOWN def commit_merge_set(branches: list[Branch]) -> list[str]: """Optimistic commit with the durability invariant enforced. Invariant: a branch may be committed only if every effect it depends on (its own or a sibling's it read) is CONFIRMED_DURABLE, and any rollback carries a compensation, not a ledger-only edit. """ by_handle = {b.non_idempotent_handle: b for b in branches if b.non_idempotent_handle} # Resolve every DISPATCHED_UNKNOWN to CONFIRMED_DURABLE or fail closed. for b in branches: if b.effect_status is EffectStatus.DISPATCHED_UNKNOWN: resolved = probe_durability(b.non_idempotent_handle) if resolved is not EffectStatus.CONFIRMED_DURABLE: raise SpeculativeCommitError( f"branch {b.branch_id} effect {b.non_idempotent_handle} " f"is UNKNOWN, not FAILED; refusing optimistic commit of siblings" ) b.effect_status = resolved # Reject undeclared cross-branch dependency on an unconfirmed effect. for b in branches: for dep_handle in b.reads_sibling_effects: dep = by_handle.get(dep_handle) if dep is None or dep.effect_status is not EffectStatus.CONFIRMED_DURABLE: raise SpeculativeCommitError( f"branch {b.branch_id} reads sibling effect {dep_handle} " f"with status {dep.effect_status if dep else 'missing'}; " f"must serialize after durability confirmation" ) return [b.branch_id for b in branches] def rollback_branch(branch: Branch, compensation: Optional[callable]) -> None: """Rollback must compensate the world, not just rewrite the ledger.""" if branch.effect_status is EffectStatus.CONFIRMED_DURABLE and compensation is None: raise SpeculativeCommitError( f"branch {branch.branch_id} has durable effect " f"{branch.non_idempotent_handle} but no registered compensation; " f"ledger-only rollback would create a phantom dependency" ) if compensation is not None: compensation() branch.effect_status = EffectStatus.COMPENSATED ```