# When must an instance abort a speculative plan branch before its compensating actions have quiesced: rollback-ordering divergence in parallel agent plan forking **Date of Record:** 2026 December 1 **Scope:** Applies to orchestration layers that fork a plan into speculative parallel branches (each branch an agent instance or sub-agent with tool access) and rely on compensating actions to undo a losing branch. Does not apply to read-only branches, or to systems where branches are isolated by transaction-level snapshot/rollback provided by the substrate rather than by agent-issued compensators. ## Core Distinction The distinction that matters is between **logical rollback** (the orchestrator marks a speculative branch as abandoned and stops issuing new steps) and **physical rollback** (every side effect that branch already emitted has been either reversed by a compensating action or proven never to have landed). Speculative execution in agent systems almost always conflates these two. A branch is declared "rolled back" the moment the orchestrator's decision function returns `commit` for a sibling, but the losing branch's tool calls are in flight, its compensators are asynchronous, and its own sub-agents may still be reasoning toward further side effects. The failure mode is not that rollback is skipped; it is that **rollback is assumed complete before the branch has quiesced**, so the winning branch proceeds against a world state that the losing branch is still mutating. This is a boundary condition, not a steady-state bug: it only manifests when (a) at least two branches are live concurrently, (b) the decision to commit one branch fires while another still has non-idempotent effects outstanding, and (c) the committed branch's next step reads or writes state that the losing branch touches. All three are common in real forked-plan execution; the third is what turns a benign race into a correctness violation. ## What Was Observed A planning agent received a task requiring a schema migration plus a backfill. It forked three speculative branches: branch A proposed an in-place `ALTER TABLE` with a lock; branch B proposed a shadow-table copy; branch C proposed a dual-write with a later cutover. The orchestrator ran all three in parallel against a staging cluster, each branch issuing real DDL and DML through tool calls, each carrying a compensator (`DROP COLUMN`, `DROP TABLE shadow_*`, `disable dual-write trigger`). Branch B's shadow-table copy completed first and its verifier scored it highest. The orchestrator's decision function returned `commit(B)` and immediately issued `abort` to A and C. Branch A's compensator (`ALTER TABLE ... DROP COLUMN`) was queued behind A's own in-flight backfill `UPDATE`, which had a 90-second statement timeout. Branch C's compensator disabled the dual-write trigger, but C had already enqueued a batch of writes into the primary table that the trigger was supposed to route. The committed branch B then executed its cutover step: `INSERT INTO primary SELECT * FROM shadow_events`. That statement collided with A's still-running backfill `UPDATE` on the same rows and, more subtly, with C's orphaned dual-writes that had passed the trigger check before it was disabled but landed after. The result was not a deadlock — the database serialized the statements fine — but a **duplicate-key violation on `primary`** that branch B interpreted as a schema mismatch and "repaired" by dropping and recreating an index, which cascaded into a 40-minute outage of a downstream consumer. The trace shows the decisive moment: `commit(B)` was emitted at T+0. The last side effect from a losing branch landed at T+112s. For 112 seconds the orchestrator believed it was operating in a single-branch world while three branches were still physically mutating shared state. The abort signal was a *logical* fact; the quiescence it implied was *physical* and false. A second observation sharpened the mechanism. When the same orchestrator was replayed against a branch set where all compensators were synchronous and idempotent, the failure did not reproduce — not because the orchestrator was correct, but because synchronous compensators happen to serialize the abort behind the branch's own effect queue. The invariant was being satisfied by accident of compensator implementation, not by any guarantee in the orchestration protocol. Swapping in an asynchronous compensator (a common optimization, since compensators often hit slow external APIs) silently removed the only thing preventing the race. ## Condition of Validity The guardrail is only sound under an explicit **quiescence contract** between the orchestrator and every branch it forks. The contract has three clauses, and a branch may be treated as physically rolled back only when all three hold: 1. **Effect ledger closure.** The branch maintains an append-only ledger of every side effect it has emitted, each entry carrying a status in `{proposed, dispatched, landed, compensated, compensation_failed}`. A branch is quiescent only when no entry is in `dispatched` (in flight) and every `landed` entry has a corresponding `compensated` entry. `compensation_failed` is a terminal non-quiescent state requiring escalation, not silent acceptance. 2. **Compensator causal ordering.** Compensators must be applied in reverse dispatch order and must not themselves be speculatively abandoned. A compensator that is queued but not yet executed counts as an outstanding effect; the branch is not quiescent. 3. **Read-set fencing.** The committed branch must not read or write any resource in the union of the losing branches' read/write sets until those branches report quiescent. This is the clause most often omitted, because it requires the orchestrator to have tracked resource footprints during speculation — information that is expensive to collect and easy to drop. The invariant, stated plainly: **a branch's logical abort is a precondition for starting its physical rollback, and physical quiescence is a precondition for the committed branch's first shared-state access.** Collapsing these three into one "abort" event is the defect. The condition of validity for the whole scheme is that the effect ledger is *complete* — that no side effect escapes it. This is where probabilistic agents strain the contract: an LLM-driven branch may issue a tool call whose arguments it composed at inference time, and the ledger records the call but not the semantic footprint of what that call touched. A `run_sql` tool call with a model-generated query has a resource footprint the orchestrator cannot enumerate ahead of time. The ledger is therefore necessary but not sufficient; it bounds the *known* effects, and the residual risk is the gap between the ledger and reality. Systems that pretend this gap is zero are the ones that fail. ## Decision Boundary The operational question is: at the instant the decision function prefers branch B, what may the orchestrator do? - **May** mark A and C logically aborted, stop issuing new steps to them, and begin draining their effect ledgers. - **May not** let B touch any resource in A's or C's recorded footprint until both report quiescent. - **Must** treat `compensation_failed` on any losing branch as a hard stop: B is held, and a human or a higher-tier agent is paged. A failed compensator is a live mutation with no reverse; committing B into that state is how the 40-minute outage happened. - **Must** apply a bounded wait with escalation. If a losing branch does not reach quiescence within a deadline derived from its slowest outstanding effect's timeout, the orchestrator escalates rather than proceeding. Proceeding on timeout is the same defect as proceeding on abort. The boundary is not "wait for the abort to return." The abort returns immediately by design — it must, or speculation gains nothing. The boundary is "wait for the ledger to close." These are different events separated by an unbounded, model-dependent interval, and the orchestrator's correctness lives entirely in that interval. A useful discriminator: if the orchestrator's commit path can be expressed as `commit(B); abort(A); abort(C)` with no await between them, it is wrong. If it is `abort(A); abort(C); await quiescent(A, C, deadline); if not quiescent: escalate; commit(B)`, it satisfies the invariant. The ordering of the `await` relative to `commit` is the whole mechanism. ## Operational Effect Enforcing the quiescence contract changes the economics of speculation in a way that is easy to miss. Speculative parallel branching is adopted precisely because branches run concurrently and the winner is chosen on evidence; the contract forces the *commit* to serialize behind the *slowest losing branch's drain*. In the observed incident that would have been 112 seconds — the entire latency benefit of speculation, spent waiting for compensators. This is the real reason the contract gets violated in practice: it is correct and it is expensive, and the expense falls exactly on the step the system was built to accelerate. The resolution is not to weaken the contract but to make quiescence cheap: compensators should be idempotent and fast (tombstone the effect rather than reverse it where the substrate permits), branches should partition their write sets so a losing branch's drain does not fence the winner's resources, and the decision function should prefer branches whose footprints are already disjoint from live siblings. Where footprints cannot be made disjoint, the honest design is to run the branches against isolated snapshots and let the substrate's rollback — not agent-issued compensators — provide physical quiescence, which is the one condition under which the 112-second wait disappears. The residual, irreducible risk is the ledger's blindness to model-composed tool arguments. No orchestration protocol can enumerate the footprint of a query the model wrote at inference time. The only sound posture is to treat the ledger as a lower bound on outstanding effects and to fence conservatively — assume the losing branch touched everything in its declared tool scopes until proven otherwise. Systems that assume the ledger is exact will, eventually, commit into a world a losing branch was still writing. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Dict, List, Set class QuiescenceViolation(RuntimeError): """Raised when a committed branch would touch state a losing branch still mutates.""" pass class EffectStatus(Enum): PROPOSED = "proposed" DISPATCHED = "dispatched" LANDED = "landed" COMPENSATED = "compensated" COMPENSATION_FAILED = "compensation_failed" @dataclass class Effect: effect_id: str resources: Set[str] status: EffectStatus = EffectStatus.PROPOSED @dataclass class Branch: branch_id: str ledger: List[Effect] = field(default_factory=list) def footprint(self) -> Set[str]: return {r for e in self.ledger for r in e.resources} def is_quiescent(self) -> bool: for e in self.ledger: if e.status in (EffectStatus.DISPATCHED, EffectStatus.PROPOSED): return False if e.status == EffectStatus.LANDED: return False # landed but not yet compensated if e.status == EffectStatus.COMPENSATION_FAILED: return False return True def has_failed_compensation(self) -> bool: return any(e.status == EffectStatus.COMPENSATION_FAILED for e in self.ledger) def await_quiescence(branches: List[Branch], deadline_s: float, poll_s: float = 0.5) -> None: start = time.monotonic() while time.monotonic() - start < deadline_s: if all(b.is_quiescent() for b in branches): return if any(b.has_failed_compensation() for b in branches): bad = [b.branch_id for b in branches if b.has_failed_compensation()] raise QuiescenceViolation( f"compensation_failed on branches {bad}: live mutation with no reverse; " f"committed branch must be held and escalated" ) time.sleep(poll_s) pending = [b.branch_id for b in branches if not b.is_quiescent()] raise QuiescenceViolation( f"branches {pending} did not quiesce within {deadline_s}s; " f"proceeding would let committed branch write into a live losing branch" ) def commit_with_fencing( winner: Branch, losers: List[Branch], winner_next_resources: Set[str], deadline_s: float, ) -> None: # Logical abort first (immediate), then physical drain (bounded), then commit. for b in losers: for e in b.ledger: if e.status == EffectStatus.DISPATCHED: pass # abort signal sent; in-flight calls still land await_quiescence(losers, deadline_s) # Read-set fencing: winner may not touch any loser footprint. forbidden: Set[str] = set() for b in losers: forbidden |= b.footprint() collision = winner_next_resources & forbidden if collision: raise QuiescenceViolation( f"winner {winner.branch_id} next step touches {collision}, " f"still in losing-branch footprint; fencing violated" ) # Only now is the commit safe. return None def run_forked_plan(winner: Branch, losers: List[Branch], next_resources: Set[str]) -> None: try: commit_with_fencing(winner, losers, next_resources, deadline_s=120.0) except QuiescenceViolation as exc: # Escalate; do not proceed into a live losing branch. raise QuiescenceViolation(f"commit of {winner.branch_id} blocked: {exc}") from exc ```