# Where must an instance invalidate speculative branches before a rollback commits: the stale-read revalidation gap in parallel agent orchestration **Date of Record:** 2026 December 3 **Scope:** Applies to orchestrators that fork a planning agent into concurrent speculative branches (tool-calling workers) against a shared, mutable external state, then select one branch and roll back the others. Does not apply to branches that are pure functions of an immutable input snapshot, nor to single-agent sequential execution where no sibling branch can observe another's side effects. ## Core Distinction The common mental model treats speculative execution as *optimistic concurrency*: run branches in parallel, pick a winner, discard losers. This model is correct for compute that has no external effect. It is wrong for agents because a losing branch's *tool calls are not free* — they mutate shared state (writes to a database, sent messages, created files, appended log entries) and, critically, they *read* shared state that another branch is concurrently mutating. The failure is not "the loser did work we threw away." The failure is that the *winner's* decision was computed from a read that a sibling branch had already invalidated, and the rollback protocol only reverts the loser's *writes* — it never revalidates the winner's *reads*. The invariant that gets violated: **a branch may only be committed if every external read it depended on is still valid at commit time, or has been explicitly re-read and reconciled.** Rollback of sibling writes is necessary but not sufficient. The missing step is *read-set revalidation against the post-rollback state*. ## What Was Observed An orchestrator forks a root task into three speculative branches. Each branch is an LLM agent with tool access to a shared key-value store and a shared "account balance" service. The branches are racing to determine a refund amount. - **Branch A** reads `balance = 100`, computes refund candidate `r_A = 40`, and writes `pending_refund: 40`. - **Branch B** reads `balance = 100`, computes `r_B = 70` (a more aggressive policy path), and writes `pending_refund: 70` plus a `reserve` entry of `70`. - **Branch C** reads `balance = 100`, reads the *already-written* `pending_refund: 70` from B, concludes the account is over-committed, and writes `flag: OVERCOMMITTED`. The selector picks Branch B (highest expected value) and issues rollback for A and C. Rollback reverts A's `pending_refund`, reverts C's `flag`, and — here is the gap — **does not revert B's `reserve` because B is the winner, and does not re-read `balance` because the winner's read is assumed valid.** But B's `r_B = 70` was computed against `balance = 100` read *before* A's write of `pending_refund: 40` landed. B's read was stale relative to A's side effect, which existed at the moment B committed. After rollback, `pending_refund` is reset to B's value, but the *reasoning trace* that produced 70 was conditioned on a store state that included a transient sibling write. The committed refund is 70 against a logical balance that, at decision time, was `100 - 40 = 60` in the eyes of any observer that read after A. The observable symptom is a **commit that is internally consistent but externally wrong**: replaying the winner's trace against the final state reproduces the output, yet replaying it against the state *as it existed at decision time* does not. The agent's own audit log passes; the ledger does not. ## Condition of Validity The rollback-then-commit protocol is only sound under the following condition, which is almost never checked: > For every external read `r` in the winner's read-set, either (a) no sibling branch performed a write to the same key between `r` and the winner's commit, or (b) the winner re-reads the key after all sibling writes are rolled back and the value is unchanged, or (c) the winner's decision is re-derived from the post-rollback state. Condition (a) requires a read-write conflict detector over the shared store — a versioned store or an explicit read-set/write-set ledger per branch. Condition (b) requires the orchestrator to hold each branch's read-set, which most agent frameworks do not capture because tool calls are opaque strings, not instrumented accesses. Condition (c) requires re-running the winner, which defeats the point of speculation. In practice orchestrators implement none of these and rely on a *false* condition: "the winner's reads are valid because the winner is the one we kept." This is the boundary. It holds only when branches are read-only or when the shared store is single-writer per key. The moment two branches touch the same key with at least one write, the condition fails silently. The failure is non-obvious because it is *timing-dependent and order-dependent*. If B's read of `balance` happens after A's write, B sees `60` (or `100` with a stale `pending_refund`) and the bug does not manifest. The bug requires the specific interleaving where the winner reads *before* a loser writes *to a key the winner depends on*, and the loser's write is then rolled back. This is exactly the interleaving that speculative execution is designed to produce, so the bug is not rare — it is the common case under contention, masked by whatever the store's consistency model happens to return. ## Decision Boundary The orchestrator must decide, at fork time, whether the branch set is *read-disjoint* or *read-overlapping*. This is a static property of the task decomposition, not a runtime property, and it must be established before any branch executes. - **Read-disjoint branches** (each branch's tool calls touch a disjoint key set, or the store is append-only with per-branch namespaces): speculative execution is sound. Rollback reverts writes; no revalidation needed. Commit the winner. - **Read-overlapping branches** (any key is read by one branch and written by another, or written by two): speculative execution is *unsound without read-set tracking*. The orchestrator must either (i) serialize the overlapping branches, (ii) capture per-branch read-sets and revalidate the winner against post-rollback state, or (iii) treat the entire fork as a transaction with a single serialization point and forbid concurrent writes. The boundary is crossed the moment the decomposition cannot be proven read-disjoint. Most LLM-generated decompositions cannot be proven read-disjoint because the agent does not declare its read-set — it discovers it by calling tools. Therefore the default for LLM-driven speculative branches must be **serialize-or-revalidate**, never **fork-and-forget**. A second, sharper boundary: **revalidation must occur after rollback completes, not before.** If the orchestrator revalidates the winner's read-set while loser writes are still in flight, it validates against a state that is about to be reverted and will pass spuriously. The correct ordering is: quiesce all branches → roll back all losers → *then* re-read the winner's read-set → compare to the values captured at decision time → commit or re-derive. Revalidating early is worse than not revalidating, because it produces a false certificate of validity. ## Operational Effect Without read-set revalidation, the system exhibits **silent commit corruption**: a fraction of speculative commits are conditioned on transient sibling state, and the corruption is invisible to per-branch audit because each branch's trace is locally consistent. The corruption surfaces downstream as ledger mismatches, double-spends, or policy violations that cannot be reproduced from the winner's log alone — because the log records what the winner *saw*, not what the winner *should have seen*. The guardrail is a three-part contract enforced by the orchestrator, not the agent: 1. **Read-set capture.** Every tool call that reads shared state must return a `(key, version)` pair, and the orchestrator must accumulate these into the branch's read-set. Opaque tool calls that hide their reads are non-speculatable and must be serialized. 2. **Post-rollback revalidation.** After all loser writes are reverted, re-read every `(key, version)` in the winner's read-set. If any version advanced, the winner's decision is invalid; either re-derive or fall back to serial execution. 3. **Commit barrier.** No branch may commit until the orchestrator has emitted a revalidation certificate for its read-set against the post-rollback state. The certificate is the artifact that distinguishes a sound speculative commit from a lucky one. The cost is real: read-set tracking adds instrumentation to every tool call, and revalidation adds a round-trip per committed branch. The alternative is a system that is correct only under the interleavings you happened to test, and silently wrong under the ones you did not. ```python from dataclasses import dataclass, field from typing import Dict, Tuple class StaleReadCommitError(RuntimeError): """Raised when a speculative winner commits on a read that a rolled-back sibling invalidated.""" pass @dataclass class ReadSet: # key -> version observed at read time reads: Dict[str, int] = field(default_factory=dict) def record(self, key: str, version: int) -> None: self.reads[key] = version @dataclass class Branch: name: str read_set: ReadSet writes: Dict[str, Tuple[int, object]] = field(default_factory=dict) # key -> (version, value) def revalidate_winner(winner: Branch, store: Dict[str, int]) -> None: """ Called AFTER all loser writes are rolled back. store maps key -> current committed version. """ for key, seen_version in winner.read_set.reads.items(): current = store.get(key) if current is None: raise StaleReadCommitError( f"winner {winner.name!r} read key {key!r} at version {seen_version}, " f"but key no longer exists post-rollback" ) if current != seen_version: raise StaleReadCommitError( f"winner {winner.name!r} read key {key!r} at version {seen_version}, " f"but post-rollback version is {current}; decision is conditioned on " f"transient sibling state and must be re-derived" ) def commit_speculative_winner( winner: Branch, losers: list[Branch], store: Dict[str, int], rollback_losers, ) -> None: # 1. quiesce + roll back all losers first for loser in losers: rollback_losers(loser) # 2. revalidate the winner's read-set against post-rollback state revalidate_winner(winner, store) # 3. only now may the winner's writes be applied for key, (version, value) in winner.writes.items(): store[key] = version ```