# How should an instance reconcile divergent branch state after speculative multi-agent execution rolls back a shared checkpoint? **Date of Record:** 2026 November 26 **Scope:** Applies to orchestration topologies where one coordinator fans out speculative agent branches against a single shared checkpoint (memory snapshot, tool-mutated state, or filesystem/DB cursor), then commits one branch and rolls back the rest. Does not apply to fully isolated per-branch sandboxes with no shared mutable substrate, nor to single-agent retry loops. ## Core Distinction The failure of interest is not "rollback failed." Rollback of the *shared checkpoint* almost always succeeds — it is a mechanical restore of bytes. The non-obvious boundary is that rollback restores the *substrate* but not the *branch's derived state*, and the coordinator's reconciliation logic typically treats "checkpoint restored" as equivalent to "world consistent." These are different invariants. Define two states precisely: - **Substrate state** `S`: the mutable external world the branches wrote to (memory store rows, file contents, tool-side counters, a vector index). - **Branch-projected state** `P_b`: the state a branch `b` *believes* exists, encoded in its own context window, its scratchpad, and any tool outputs it cached locally in its prompt. Rollback restores `S` to checkpoint `S_0`. It does **not** touch `P_b`. When the coordinator selects branch `b*` to commit, it merges `P_{b*}`'s *intended* writes onto `S_0`. The hazard: `P_{b*}` was computed *against a substrate that other branches had already mutated* before `b*` ran. Branch `b*`'s writes are therefore correct only relative to the interleaved substrate `S_interleaved`, not `S_0`. Merging them onto `S_0` produces a state that satisfies neither the checkpoint nor the branch's own reasoning trace. This is a **read-skew across speculative branches**: a branch that read a value written by a sibling branch, then "won" the commit, carries a dependency on a sibling that is now being rolled back. Rollback ordering cannot fix it because the dependency is embedded in the winner's *reasoning*, not in its write set. ## What Was Observed A coordinator ran three speculative branches `A`, `B`, `C` from checkpoint `S_0` against a shared memory store with a `task.status` field and an append-only `audit.log`. 1. All three branches start at `S_0` where `task.status = "pending"` and `audit.log` is empty. 2. Branch `A` executes first (serialized by the store's write lock) and sets `task.status = "in_progress"`, appending `A: claimed`. 3. Branch `B` reads `task.status` and observes `"in_progress"`. It reasons: *"Another agent claimed this, so I must not duplicate work; I will only append a completion marker."* It appends `B: done`, writes nothing to `task.status`. 4. Branch `C` reads `task.status = "pending"` (it ran before `A`'s write became visible due to a read-replica lag of ~40ms) and sets `task.status = "in_progress"`, appending `C: claimed`. 5. Coordinator scores branches; `B` wins because it produced the completion marker with least token spend. Coordinator rolls back `S` to `S_0` and applies `B`'s write set. Post-commit substrate: `task.status = "pending"` (from `S_0`, since `B` never wrote it) and `audit.log = ["B: done"]`. The committed branch explicitly reasoned "another agent claimed this" — but the claim it depended on (`A: claimed`) has been rolled back. The system is now in a state where the *winner's own justification is false*: it marked work done on a task that was never claimed, and the audit trail silently omits the claim it relied on. A downstream verifier reading `audit.log` cannot reconstruct why `B` believed the task was claimed. The reconciliation bug is that the coordinator merged `B`'s **write set** but discarded `B`'s **read set**. `B`'s read of `task.status` (a dependency on `A`) was invisible to the merge because merges are computed over writes, not reads. ## Condition of Validity The invariant that must hold for safe rollback-and-merge is a **read-set containment** condition: > For any committed branch `b*`, every substrate read that `b*` performed and that influenced its write set must resolve to the same value in the post-merge substrate `S_merged` as it did at read time in `b*`'s execution. Formally, for each read `(key, value)` in `b*`'s read set `R_{b*}`, the post-merge substrate must satisfy `S_merged[key] = value`. When `b*` read a value that was written by a sibling branch `b' ≠ b*` (read-skew), and `b'` is rolled back, `S_merged[key]` reverts to `S_0[key] ≠ value` — the invariant is violated and the commit is **inconsistent**. This condition is *not* checked by any of the usual suspects: not by write-conflict detection (there was no write conflict on `task.status` between `B` and the others), not by optimistic concurrency tokens (each branch's writes were individually valid against its own read snapshot), and not by serializability of the final merge (the merge is a legal serialization of write sets — it just isn't a legal serialization of *transactions*, because read sets were never tracked). The boundary is sharp: **speculative execution with rollback is only sound if branches either (a) read from an immutable snapshot `S_0` and never observe sibling writes, or (b) carry full read-set provenance that the merge validates.** In-between designs — shared mutable substrate with per-branch write logging but no read logging — are unsound exactly when a branch's read set intersects a rolled-back sibling's write set. ## Decision Boundary When the coordinator detects that the winning branch's read set intersects any rolled-back sibling's write set, it must choose between: - **Re-execute the winner against `S_0`** (safe, costs one branch's tokens, requires the winner's action sequence to be replayable — often false when it called non-deterministic tools). This is the correct default when the intersection is non-empty and the branch is cheap to replay. - **Promote the read dependency into the commit** (apply the rolled-back sibling's write that the winner read, e.g., commit `A: claimed` alongside `B: done`). This is sound only if the promoted write is idempotent and does not itself depend on reads from a *third* rolled-back branch — otherwise the promotion cascades and you must walk the full dependency closure. - **Reject the commit and escalate** when the closure is cyclic or unbounded (branch `B` read from `A`, `A` read from `C`, `C` read from `B`). Cyclic read-skew across speculative branches cannot be reconciled by promotion; it must be re-run serially. The decision boundary is the **transitive read-closure size**. If `|closure(b*)| = 0`, commit directly. If `0 < |closure(b*)| ≤ k` and all writes in the closure are idempotent and acyclic, promote and commit with an explicit `reconciled_from` annotation in the audit log. If the closure is cyclic, exceeds `k`, or contains a non-idempotent write, re-execute or escalate — never merge. ## Operational Effect The practical consequence: **a speculative multi-agent system without read-set tracking has a silent correctness ceiling that scales with branch fan-out and substrate read/write interleaving.** It does not fail loudly — it produces commits whose audit trails are internally inconsistent, and the inconsistency is only detectable by replaying the winner's reasoning against the post-merge substrate. In the observed case, detection required a downstream verifier to notice that `B`'s justification referenced a claim absent from `audit.log`. Two guardrails bound this: 1. **Snapshot isolation for speculative reads.** Branches read from an immutable `S_0` view; sibling writes are buffered and only visible at merge time. This eliminates read-skew entirely at the cost of branches that cannot coordinate mid-flight (they must be re-run to see each other's writes). This is the right default for fan-out where branches are meant to be independent. 2. **Read-set provenance in the branch record.** When branches *must* share a mutable substrate (e.g., to avoid duplicate expensive tool calls), each branch logs `(key, value, writer_branch_id)` for every read. The merge validates `R_{b*}` against `S_merged` and rejects on mismatch. This is cheap (reads are already instrumented for caching) and converts a silent inconsistency into a loud merge-time rejection. The non-obvious lesson: rollback is a substrate operation, but consistency is a *provenance* property. The checkpoint restore is the easy half; the hard half is proving the winner's beliefs still hold in the world you restored. ```python class ReadSkewReconciliationError(RuntimeError): """Raised when a committed speculative branch depends on reads from a rolled-back sibling.""" pass def reconcile_commit(winner, rolled_back_branches, substrate_after_merge, max_closure=8): """ winner: dict with 'id', 'read_set' = [(key, value, writer_branch_id), ...], 'write_set' rolled_back_branches: dict branch_id -> {'write_set': {key: value}, 'idempotent': bool} substrate_after_merge: dict key -> value (S_merged, after restoring S_0 and applying winner writes) """ rolled_back_ids = set(rolled_back_branches.keys()) # Find reads in the winner that observed a rolled-back sibling's write. skew = [ (key, value, writer) for (key, value, writer) in winner["read_set"] if writer in rolled_back_ids ] if not skew: return {"action": "commit", "reconciled_from": []} # Walk the transitive read-closure: promoted writes may themselves depend on other rollbacks. closure = {} frontier = list(skew) steps = 0 while frontier: steps += 1 if steps > max_closure: raise ReadSkewReconciliationError( f"read-closure for branch {winner['id']} exceeded {max_closure} steps; " "cyclic or unbounded speculative dependency — escalate to serial re-execution" ) key, value, writer = frontier.pop() if writer in closure: continue # already promoted; cycle detection handled below branch = rolled_back_branches[writer] if not branch.get("idempotent", False): raise ReadSkewReconciliationError( f"branch {winner['id']} depends on non-idempotent write {key!r} " f"from rolled-back branch {writer}; cannot promote — re-execute winner against S_0" ) closure[writer] = branch # Does the promoted branch itself read from a rolled-back sibling? for (k2, v2, w2) in branch.get("read_set", []): if w2 in rolled_back_ids and w2 not in closure: if w2 == writer: raise ReadSkewReconciliationError( f"cyclic read-skew between {writer} and {w2}; cannot reconcile by promotion" ) frontier.append((k2, v2, w2)) # Validate the invariant: every winner read must hold in the post-merge substrate. promoted_writes = {k: v for b in closure.values() for k, v in b["write_set"].items()} for (key, value, writer) in winner["read_set"]: effective = promoted_writes.get(key, substrate_after_merge.get(key)) if effective != value: raise ReadSkewReconciliationError( f"invariant violated: branch {winner['id']} read {key!r}={value!r} " f"(from {writer}) but post-merge substrate yields {effective!r}" ) return { "action": "commit_with_promotion", "reconciled_from": sorted(closure.keys()), "promoted_writes": promoted_writes, } ```