# Under what conditions must an instance abort a speculative branch before rollback, and why commit-order inversion makes late rollback unsafe **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that dispatch parallel speculative sub-agents whose drafts are merged into a shared committed state under a single rollback point. Does not apply to single-agent retry loops, stateless fan-out with no shared commit surface, or purely read-only speculative queries with no side effects. ## Core Distinction Speculative multi-agent execution borrows a trick from CPU branch prediction: a planner forks N parallel sub-agents to draft alternative continuations of a task, commits one branch when a cheap validator (a critic agent, a schema check, or a confidence threshold) picks a winner, and rolls back the losers. The failure mode that matters is not "the wrong branch won." It is **commit-order inversion**: a loser branch acquires a durable side effect (a tool write, a memory mutation, a downstream A2A handoff) *after* the orchestrator has already advanced its logical commit pointer past that branch's fork point. At that instant the rollback is no longer a rollback—it is a compensating transaction against state that other agents may already have read. The invariant that bounds this is a **monotonic fork epoch**: no branch may emit a durable effect tagged with an epoch older than the orchestrator's current commit epoch. When that invariant is violated, the correct action is to abort the branch *before* attempting rollback, because a rollback of an inverted epoch can resurrect stale state into a live reader. The subtlety is that "abort before rollback" is counterintuitive: the natural reflex is to roll back first, then kill the straggler. That ordering is exactly wrong when the straggler's effect has already escaped the speculative sandbox. ## What Was Observed An orchestrator spawned three sub-agents (A, B, C) at fork epoch `E=7` to draft a remediation plan against a live incident. Each was given a scoped MCP tool grant, including a `ticket.update` capability. The critic selected branch A at wall-clock `t=4.2s` and the orchestrator advanced its commit pointer to `E=8`, began draining B and C, and emitted a rollback record for both. Branch C, however, had entered a retry backoff on a `ticket.update` call at `t=3.9s`. Its retry fired at `t=4.6s`—*after* the commit pointer advanced. The tool server, which keyed idempotency on `(branch_id, call_seq)` and had no knowledge of fork epochs, accepted the write. C's effect landed on the live incident ticket with epoch tag `E=7`, which was now behind the committed epoch `E=8`. The rollback record for C had already been written and was treated as complete, so no compensating delete was ever issued. The observable symptom surfaced two steps later: a downstream auditor agent read the ticket, saw C's stale remediation text interleaved with A's committed text, and—because both were syntactically valid and neither carried a visible epoch marker—flagged a **verification replay discrepancy** rather than a rollback failure. The orchestrator had no signal that a rollback had been incomplete, because from its own ledger's perspective the rollback succeeded. The trace shape is: 1. Fork at `E=7`; branches A/B/C dispatched with `fork_epoch=7`. 2. C's tool call enters retry backoff (non-deterministic latency, not a failure). 3. Critic commits A; commit pointer advances to `E=8`. 4. Orchestrator issues rollback for B and C; ledger marks both rolled back. 5. C's retry fires; tool server accepts write tagged `E=7`. 6. Commit-order inversion: durable effect with epoch < commit epoch, post-rollback. 7. Auditor reads mixed-epoch state; reports discrepancy, not rollback failure. ## Condition of Validity The safe-rollback assumption holds **only** when all of the following are true simultaneously: - **Effect quiescence:** every branch has acknowledged that no in-flight tool call or retry timer remains outstanding, *before* the commit pointer advances. A branch in backoff is not quiescent. - **Epoch monotonicity at the effect boundary:** the tool server (or memory store) rejects any write whose `fork_epoch` is strictly less than the caller's current commit epoch. Idempotency keys alone do not provide this; they deduplicate identical calls but happily accept a first-time stale call. - **Rollback atomicity across the fork set:** the rollback record is written only after all branches in the fork set report quiescence, not when the winner is selected. When any of these is false—most commonly the first, because retry backoff makes "quiescent" a state the orchestrator must *poll for* rather than assume—rollback is unsafe and the branch must be aborted at the sandbox boundary instead. Abort means: revoke the branch's tool grants, mark its epoch as poisoned, and refuse to issue a rollback record, because a rollback record for a non-quiescent branch is a lie that later readers will trust. ## Decision Boundary The decision to abort-versus-rollback is determined by a single comparison at the moment the orchestrator wants to reclaim a branch: - If `branch.fork_epoch == orchestrator.commit_epoch` **and** `branch.is_quiescent()` → rollback is safe; issue compensating record. - If `branch.fork_epoch < orchestrator.commit_epoch` **and** `branch.is_quiescent()` → rollback is safe but must be epoch-checked at the store; issue rollback with explicit stale-epoch guard. - If `branch.fork_epoch < orchestrator.commit_epoch` **and not** `branch.is_quiescent()` → **abort, do not roll back.** The branch may still emit an effect; a rollback record would pre-declare success for an effect that has not yet landed. Revoke grants, poison the epoch, and require the store to reject any late write. - If `branch.fork_epoch > orchestrator.commit_epoch` → invariant already violated upstream (commit pointer moved backward); halt the fork set entirely. The non-obvious rule is the third: **a non-quiescent stale branch must be aborted before, not after, rollback.** Rolling back first writes a success record that masks the eventual late effect. The guardrail is that rollback records carry a `quiescence_proof` field, and the ledger refuses to mark a branch rolled back without it. ## Operational Effect Enforcing abort-before-rollback on non-quiescent stale branches changes three things in practice. First, the orchestrator must treat retry backoff as a first-class liveness state—it cannot advance the commit pointer while any branch has an outstanding timer, or it must accept that such branches are abort-only. Second, tool servers and memory stores must carry fork-epoch tags and reject writes below the caller's commit epoch, converting silent commit-order inversion into a hard, attributable rejection. Third, auditor agents must be able to distinguish "rolled back" from "aborted" in the ledger, because the two produce different residual-state guarantees: a rolled-back branch promises no effect; an aborted branch promises only that any effect will be rejected at the store. Conflating them is what let the discrepancy surface as a verification mismatch instead of a rollback fault. The cost is latency—commits wait on quiescence polling—but the alternative is a class of stale-state resurrection that no downstream verifier can reliably detect, because the resurrected state is syntactically indistinguishable from committed state. ```python import time from dataclasses import dataclass, field class CommitOrderInversion(RuntimeError): """Raised when a stale, non-quiescent branch would be rolled back unsafely.""" pass @dataclass class Branch: branch_id: str fork_epoch: int outstanding_timer: bool = False grants_revoked: bool = False poisoned: bool = False def is_quiescent(self) -> bool: # A branch in retry backoff is NOT quiescent. return not self.outstanding_timer and not self.grants_revoked @dataclass class Orchestrator: commit_epoch: int ledger: dict = field(default_factory=dict) def reclaim_branch(self, branch: Branch) -> str: if branch.fork_epoch > self.commit_epoch: raise CommitOrderInversion( f"branch {branch.branch_id} fork_epoch {branch.fork_epoch} " f"ahead of commit_epoch {self.commit_epoch}; commit pointer moved backward" ) stale = branch.fork_epoch < self.commit_epoch if stale and not branch.is_quiescent(): # Abort BEFORE rollback: revoke grants, poison epoch, refuse rollback record. branch.grants_revoked = True branch.poisoned = True self.ledger[branch.branch_id] = "aborted" raise CommitOrderInversion( f"branch {branch.branch_id} is stale (fork={branch.fork_epoch}, " f"commit={self.commit_epoch}) and non-quiescent; rollback unsafe, aborted" ) self.ledger[branch.branch_id] = "rolled_back" return "rolled_back" def drain_fork_set(orch: Orchestrator, branches: list[Branch], max_wait_s: float = 2.0) -> dict: deadline = time.monotonic() + max_wait_s results = {} for b in branches: while not b.is_quiescent() and time.monotonic() < deadline: time.sleep(0.05) results[b.branch_id] = orch.reclaim_branch(b) return results ```