# When must an instance abandon a speculative branch before its validator has returned: commit-order inversion in parallel rollouts **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan out N speculative branches from a shared checkpoint, run them concurrently, and commit the first branch whose validator returns PASS while rolling back the rest. Does not apply to sequential single-branch retry loops or to branches that share no mutable external state. ## Core Distinction The failure is not "a bad branch got committed." It is the **commit-order inversion between a validator's verdict and a sibling branch's side effects**: branch A's validator returns PASS at wall-clock T, the orchestrator commits A's state delta, and only then discovers that branch B — which the orchestrator had *already decided to roll back* — mutated a resource that A's delta assumes is unchanged. The distinction that matters operationally is between **speculative state that is isolated by construction** (private scratchpads, per-branch sandboxes, copy-on-write context) and **speculative state that is isolated only by intent** (shared tool endpoints, shared vector-store namespaces, shared message queues). Validators reason about the former correctly and the latter catastrophically, because a validator only sees its own branch's transcript, never the concurrent side effects of siblings it cannot observe. The non-obvious invariant: *a branch may be committed only if every rolled-back sibling has reached a quiescent state with respect to every resource appearing in the committed delta.* PASS is necessary but not sufficient; the missing precondition is **sibling quiescence**, and it is invisible to any validator that operates on a single branch's view. ## What Was Observed A planner agent decomposed a schema-migration task into three speculative branches sharing a checkpoint at step 12: - **Branch A** (`conservative`): emits `ALTER TABLE ... ADD COLUMN`, validates against a dry-run schema oracle → PASS at T+4.1s. - **Branch B** (`aggressive`): emits `ALTER TABLE ... RENAME COLUMN`, its validator is slow (schema oracle queue depth) and has not returned at T+4.1s. - **Branch C** (`no-op`): fails fast, rolled back at T+1.9s cleanly. At T+4.1s the orchestrator commits A. At T+4.9s branch B's validator returns PASS *against the pre-commit schema snapshot it captured at T+0* — but B's tool calls had already executed against the live database at T+3.2s (the branch executes before it validates; validation is a post-hoc oracle, not a gate). B's `RENAME COLUMN` had landed. The orchestrator, seeing B's stale PASS, briefly considered committing B on top of A, then rolled it back — but rollback of a `RENAME` is a `RENAME` back, and A's committed delta now references a column name that B renamed away and back under a different transaction boundary. Net result: A's migration journal records a column that does not exist; the next branch's `ADD COLUMN` fails with a duplicate-column error against a name A never created. The tell in the logs was ordering, not content: `commit(A)` at `t=4.1`, `exec(B.rename)` at `t=3.2` — the side effect *preceded* the commit it invalidated, but the orchestrator's rollback decision for B was made at `t=4.1` on the basis of "not yet committed," which it conflated with "not yet effective." ## Condition of Validity The commit/rollback protocol is sound only under this conjunction: 1. **Effect isolation:** every branch executes against a resource snapshot that the orchestrator can atomically discard (copy-on-write volume, per-branch DB schema, per-branch vector namespace). If any branch writes to a shared endpoint, isolation is by intent only. 2. **Verdict freshness:** a validator's PASS is bound to the exact resource version it observed. If the resource version advanced between the validator's snapshot and the commit, the PASS is stale and must be re-derived. 3. **Quiescence before commit:** no sibling branch is mid-flight against any resource in the committing delta. "Mid-flight" includes branches whose validator has not returned *and* branches whose validator returned but whose compensating rollback has not completed. When (1) holds, (2) and (3) are free. When (1) fails — the common case, because real tools are shared — (2) and (3) become mandatory and are exactly what single-branch validators cannot check. The boundary is: **the moment a branch's tool calls touch a resource that another branch's delta also touches, the orchestrator owes a quiescence barrier that no per-branch validator can supply.** ## Decision Boundary The orchestrator must choose between two disciplines at fan-out time, not at commit time: - **Barrier discipline (safe, slower):** commit only after *all* branches have reached terminal state (PASS, FAIL, or rolled-back) and a global resource-version check confirms no branch mutated a resource in the winning delta. Cost: commit latency = max branch latency, not min. - **Speculation discipline (fast, requires isolation):** commit the first PASS immediately, but only if every branch executed against a private snapshot; then reconcile by replaying the winning delta onto the shared resource and rejecting if the resource version moved. The failure above is the hybrid: fast commit (speculation) with shared resources (no isolation). The decision rule: *if any branch's tool surface includes a non-idempotent write to a shared resource, the orchestrator must run barrier discipline; speculation is only legal over idempotent or isolated writes.* A `RENAME` is non-idempotent (rename-back is a different operation than no-op); an `ADD COLUMN IF NOT EXISTS` is idempotent and could have been speculated safely. The branch taxonomy, not the validator, determines the discipline. ## Operational Effect Under barrier discipline, worst-case commit latency rises to the slowest branch's validator turnaround — the schema-oracle queue depth becomes the critical path, which is the correct place to spend latency because it is the only place the cross-branch invariant can be enforced. Under speculation discipline, the orchestrator must carry a resource-version vector per branch and reject any commit whose delta references a resource whose version advanced since the validator's snapshot; this converts the silent corruption into a loud `StaleVerdictError` and a re-derivation, at the cost of occasional wasted PASSes. The operational lesson for the agent layer: **a validator's PASS is a statement about a snapshot, not about the world.** In speculative execution the world moves under the validator, and the only defense is either to freeze the world (isolation) or to check that it did not move (version barrier) before committing. Validators that cannot see siblings cannot enforce sibling quiescence; the orchestrator must, and it must do so *before* the first commit, not after the first surprise. ```python from dataclasses import dataclass, field from typing import Dict, Optional class StaleVerdictError(RuntimeError): """Raised when a branch's PASS was derived against a resource version that has since advanced, or when a sibling is not quiescent at commit.""" @dataclass class Branch: name: str validator_returned: bool = False verdict: Optional[str] = None # "PASS" | "FAIL" snapshot_version: int = 0 # resource version validator observed mutates_shared: bool = False # non-idempotent write to shared resource rolled_back: bool = False @dataclass class Orchestrator: resource_version: int = 0 branches: Dict[str, Branch] = field(default_factory=dict) def commit(self, winner: str) -> None: w = self.branches[winner] if not w.validator_returned or w.verdict != "PASS": raise StaleVerdictError(f"{winner}: no fresh PASS to commit") # Invariant 1: verdict freshness — snapshot must match live version. if w.snapshot_version != self.resource_version: raise StaleVerdictError( f"{winner}: PASS bound to v{w.snapshot_version}, " f"resource at v{self.resource_version}" ) # Invariant 2: sibling quiescence — no in-flight shared mutation. for name, b in self.branches.items(): if name == winner: continue if b.mutates_shared and not (b.validator_returned and b.rolled_back): raise StaleVerdictError( f"{winner}: sibling {name} not quiescent " f"(validator_returned={b.validator_returned}, " f"rolled_back={b.rolled_back})" ) self.resource_version += 1 # Reproduces the observed failure: B's rename executed at t=3.2, A commits at t=4.1. orch = Orchestrator(resource_version=1) orch.branches["A"] = Branch("A", validator_returned=True, verdict="PASS", snapshot_version=1, mutates_shared=True) orch.branches["B"] = Branch("B", validator_returned=False, verdict=None, snapshot_version=1, mutates_shared=True) try: orch.commit("A") # raises: B is mid-flight against a shared resource except StaleVerdictError as e: print("blocked:", e) ```