Where must an instance reconcile speculative branch commits before rollback, and what breaks when it does not

**Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fan out one logical task into N parallel agent branches executed speculatively against shared external state (filesystems, databases, APIs, message queues) and commit whichever branch first satisfies a verifier, discarding the rest. Does not apply to branches executed against disjoint, copy-on-write sandboxes with no side-effecting tool calls, nor to purely read-only fan-out.

Core Distinction

The distinction that matters is between *speculative state* (side effects produced by a branch that has not yet won the verifier) and *committed state* (side effects attributable to the branch the orchestrator has selected). Most fan-out frameworks treat branch isolation as a property of the *reasoning* layer—each branch gets its own context window, its own token budget, its own tool-call transcript—and quietly assume that the *effect* layer is either idempotent or trivially reversible. It is neither.

The boundary failure is this: a losing branch can emit side effects that are not captured by the winner's reconciliation plan because the loser's effects were emitted *after* the winner was selected but *before* the loser's cancellation propagated. Rollback reconciliation then runs against a snapshot of effects taken at selection time, and the delta produced in the cancellation window survives as orphaned state. The invariant that must hold is: **no branch may emit a side effect after the orchestrator has frozen the effect-set for reconciliation, unless that effect is tagged with the branch's cancellation epoch and swept by a second-pass reconciler.** Without the epoch tag, the reconciler has no way to distinguish an orphan from a legitimately concurrent write by another task.

What Was Observed

A three-branch fan-out over a code-migration task. Each branch was given the same objective (migrate a schema file and update three call sites), the same tool surface (`write_file`, `run_migration`, `post_comment`), and an independent context. Branch A completed first and its verifier passed at t=41.2s. The orchestrator froze the effect-set at t=41.2s, selected A, and issued `cancel()` to B and C.

Branch B was mid-`run_migration` at t=41.2s. The migration tool is not interruptible—it holds a database lock and completes its transaction before returning. B's `run_migration` returned at t=43.7s, *after* cancellation was requested, having applied a schema delta that A's plan did not include (B had chosen a different normalization strategy). The cancellation handler for B marked the branch as `CANCELLED` and dropped its transcript, but the tool's side effect had already landed.

The reconciler, running at t=44.0s, compared the live schema against the effect-set frozen at t=41.2s. It saw the delta. It had no record of which branch produced it—B's transcript was gone, and the tool's return value had been discarded by the cancellation handler. The reconciler's default policy for unattributed deltas was `preserve`, on the theory that an unattributed delta is more likely to be a concurrent external write than a rolled-back branch. The orphaned schema delta survived.

The failure surfaced 90 seconds later when A's downstream verifier re-read the schema and found a column that A's migration had not created. The system reported a *verification divergence*—A claimed success, the artifact disagreed—and the orchestrator retried the entire task, re-running all three branches, which produced a *second* orphaned delta from the retry's branch B (a different B, same failure mode). Two retries later the schema had three mutually incompatible normalization strategies applied and the migration tool refused to proceed.

The diagnostic signature to watch for: a verifier that passes at selection time but fails on re-read, with the delta traceable to a tool call whose return value was logged as `DROPPED` or `CANCELLED` rather than `APPLIED` or `REVERTED`. If your logs show tool completions after cancellation requests, you have this failure mode whether or not it has surfaced yet.

Condition of Validity

The reconciliation invariant holds only under the following conditions, and the orchestrator must *check* them rather than assume them:

  1. **Effect-set freeze is causally prior to cancellation.** The orchestrator must freeze the reconciliation set and *then* cancel losers. If it cancels first and freezes after, in-flight effects land in the freeze window and are attributed to no branch.
  2. **Every tool call carries a branch epoch.** The epoch is incremented on each cancellation wave. A tool result tagged with an epoch older than the current wave is a candidate orphan; one tagged with the current wave is a legitimate concurrent write. Without epochs, the two are indistinguishable.
  3. **Cancellation is acknowledged, not fire-and-forget.** The orchestrator must wait for each losing branch to acknowledge cancellation *and* for each in-flight tool call to return or time out, before the reconciler runs. A branch that has not acknowledged is still a potential effect emitter.
  4. **The reconciler has a policy for unattributed deltas that is not `preserve` by default.** The default must be `quarantine`: move the delta to a holding area, log the epoch, and require an explicit adjudication step. `preserve` is only safe when the effect layer is provably single-writer, which fan-out contradicts by construction.

When any of these fails, the reconciliation is *unsound*: it may report a clean rollback while orphaned effects remain live. The orchestrator must treat an unsound reconciliation as a hard error, not a warning, because the alternative is silent state corruption that surfaces as verifier divergence on a later, unrelated task.

Decision Boundary

The decision the orchestrator faces at selection time is whether to reconcile *eagerly* (freeze, cancel, wait for acknowledgement, sweep, then commit) or *lazily* (commit the winner, let losers drain in the background, reconcile on a timer). Eager reconciliation bounds the orphan window to the acknowledgement latency of the slowest losing branch—typically tens of seconds for non-interruptible tools—but blocks the winner's commit for that duration. Lazy reconciliation unblocks the winner immediately but leaves the orphan window open for the timer interval, during which downstream tasks may read the orphaned state.

The boundary is drawn by the *interruptibility class* of the tools in the branch's surface. If every tool in the losing branches' surfaces is interruptible (returns within a bounded, short deadline on cancellation), lazy reconciliation is safe because the orphan window is bounded by the deadline and the reconciler's timer can be set to exceed it. If any tool is non-interruptible—long-running migrations, external API calls without idempotency keys, message-queue publishes—eager reconciliation is mandatory, and the winner's commit must block until acknowledgement. The orchestrator must compute the interruptibility class from the tool registry at fan-out time, not at selection time, because a branch may acquire a non-interruptible tool mid-execution and the orchestrator will not see it until the tool call is already in flight.

The second decision is the adjudication policy for quarantined deltas. `Revert` is safe only if the delta is provably attributable to a single branch and that branch's effects are commutative with the winner's. `Preserve` is safe only if the delta is provably an external concurrent write. `Escalate`—halt the task and require human or higher-tier-agent adjudication—is the only policy that is safe under uncertainty, and it is the correct default for any delta whose epoch is older than the current cancellation wave and whose producing branch's transcript has been dropped.

Operational Effect

The operational consequence is that fan-out orchestrators must maintain a *cancellation ledger* separate from the branch transcripts: a durable, append-only record of (branch_id, epoch, tool_call_id, effect_descriptor, status) that survives transcript garbage collection. The ledger is what the reconciler reads. When a branch is cancelled, its transcript may be dropped, but its ledger entries must be marked `IN_FLIGHT` and updated to `LANDED` or `ABORTED` when the tool returns or times out. The reconciler sweeps `LANDED` entries from cancelled branches and quarantines them.

The cost is that the ledger must be written synchronously before each tool call and updated after, which adds a round-trip to every tool invocation in the fan-out. This is the price of sound rollback. Orchestrators that skip the ledger—relying on transcripts, which are lossy and GC'd—will pass their tests and fail in production the first time a non-interruptible tool is invoked by a losing branch. The failure is not loud; it is a schema delta that no one claims, a file that no branch's transcript mentions, a message published twice. It surfaces as verifier divergence on a later task, and the root cause is two tasks back in the logs, behind a `CANCELLED` status that lied.

import time
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional


class ReconciliationError(RuntimeError):
    """Raised when speculative rollback reconciliation is unsound."""


class EffectStatus(Enum):
    IN_FLIGHT = "in_flight"
    LANDED = "landed"
    ABORTED = "aborted"
    QUARANTINED = "quarantined"


@dataclass
class LedgerEntry:
    branch_id: str
    epoch: int
    tool_call_id: str
    effect_descriptor: str
    status: EffectStatus = EffectStatus.IN_FLIGHT
    landed_at: Optional[float] = None


@dataclass
class CancellationLedger:
    entries: list[LedgerEntry] = field(default_factory=list)
    current_epoch: int = 0

    def record_call(self, branch_id: str, tool_call_id: str, effect: str) -> LedgerEntry:
        entry = LedgerEntry(
            branch_id=branch_id,
            epoch=self.current_epoch,
            tool_call_id=tool_call_id,
            effect_descriptor=effect,
        )
        self.entries.append(entry)
        return entry

    def mark_landed(self, tool_call_id: str) -> None:
        for e in self.entries:
            if e.tool_call_id == tool_call_id:
                e.status = EffectStatus.LANDED
                e.landed_at = time.monotonic()
                return

    def begin_cancellation_wave(self) -> int:
        self.current_epoch += 1
        return self.current_epoch


def reconcile(
    ledger: CancellationLedger,
    winner_id: str,
    cancelled_branch_ids: set[str],
    interruptibility_class: str,
    ack_deadline_s: float,
) -> list[LedgerEntry]:
    """
    Freeze, cancel, wait for acknowledgement, then sweep.

    Raises ReconciliationError if the reconciliation is unsound: in-flight
    effects from cancelled branches older than the current wave, or landed
    effects whose epoch precedes the wave (orphans) that cannot be attributed.
    """
    if interruptibility_class == "non_interruptible" and ack_deadline_s <= 0:
        raise ReconciliationError(
            "non-interruptible tools require a positive acknowledgement deadline; "
            "lazy reconciliation is unsound for this branch surface"
        )

    # Freeze is implicit: we snapshot the ledger's current view.
    frozen = list(ledger.entries)
    wave = ledger.current_epoch

    # Wait for in-flight effects from cancelled branches to resolve.
    deadline = time.monotonic() + ack_deadline_s
    while time.monotonic() < deadline:
        pending = [
            e for e in frozen
            if e.branch_id in cancelled_branch_ids and e.status is EffectStatus.IN_FLIGHT
        ]
        if not pending:
            break
        time.sleep(0.05)

    orphans: list[LedgerEntry] = []
    for e in frozen:
        if e.branch_id not in cancelled_branch_ids:
            continue
        if e.status is EffectStatus.IN_FLIGHT:
            raise ReconciliationError(
                f"branch {e.branch_id} tool {e.tool_call_id} still in flight after "
                f"{ack_deadline_s}s; reconciliation cannot be sound"
            )
        if e.status is EffectStatus.LANDED:
            if e.epoch < wave:
                # Landed after the wave began but tagged with an older epoch:
                # produced in the cancellation window. Quarantine, do not preserve.
                e.status = EffectStatus.QUARANTINED
                orphans.append(e)
            else:
                raise ReconciliationError(
                    f"branch {e.branch_id} emitted effect {e.effect_descriptor} "
                    f"in the current wave ({e.epoch}); cannot distinguish orphan "
                    f"from concurrent external write"
                )

    if orphans:
        # Escalate rather than revert or preserve: attribution is ambiguous.
        raise ReconciliationError(
            f"{len(orphans)} orphaned effect(s) quarantined from cancelled branches "
            f"after winner {winner_id} was selected; adjudication required before commit"
        )

    return frozen