# Where must an instance reject a speculative branch before rollback reconciliation: the commit-order hazard in optimistic multi-agent execution **Date of Record:** 2026 November 19 **Scope:** Applies to agent runtimes that let multiple worker instances execute speculative branches against a shared mutable world model (filesystem, database, tool-side state) and reconcile by rolling back losing branches. Does not apply to read-only fan-out, to purely functional branches with no side effects, or to runtimes that serialize all writes through a single commit authority. ## Core Distinction The failure is not "a rollback failed." It is that a speculative branch *observed state that only exists because a sibling branch already committed*, and then built reasoning on top of that observation. Rollback of the sibling is not a rollback of the observer. The observer's cached context, its episodic trace, and any derived plan now encode a fact that the reconciliation logic is about to declare never happened. This is distinct from lost-update (a write overwritten) and from write-write conflict (two branches touching the same key). Here the two branches touch *disjoint* keys. There is no key-level conflict to detect. The conflict is causal: branch B read key `x` after branch A wrote `x`, and the reconciler later discards A. B's write to its own disjoint key `y` is arithmetically derived from a value that is being un-happened. Standard optimistic concurrency control (OCC) with per-key version stamps catches A-vs-A collisions and misses A-then-B-read-then-A-rollback entirely, because B never touched `x`. ## What Was Observed A three-worker swarm was tasked with a schema migration. The orchestrator forked three speculative branches from a common checkpoint at sequence `S0`. Branch A (worker-1) was assigned to add a column and backfill it. Branch B (worker-2) was assigned to write a downstream aggregation that reads row counts. Branch C (worker-3) was the auditor. The trace: 1. `S0` checkpoint taken; all three branches fork with the same world-model snapshot and the same tool-scope grant. 2. Worker-1 executes `ALTER TABLE ... ADD COLUMN`, then a backfill that writes 40,000 rows. Its commit is *staged* but, per the runtime's optimistic design, immediately visible to sibling branches (the runtime uses a shared staging area with per-key version stamps, not copy-on-write isolation). 3. Worker-2, polling the staging area, reads the post-backfill row count `40,000` and writes an aggregation record `y = f(40000)`. Its own key `y` is untouched by anyone else. No version-stamp conflict is raised: worker-2 read `x` at version `v7` and wrote `y` at version `v1`; both are internally consistent. 4. Worker-1's backfill is found to violate a downstream constraint (the auditor flags a type mismatch). The reconciler rolls back worker-1: the column is dropped, the 40,000 rows reverted, `x` returns to version `v6`. 5. The reconciler finds *no conflict* on worker-2's branch — disjoint keys, valid stamps — and commits `y = f(40000)`. The system converges to a state where `y` encodes a row count that does not exist. `x` is back at its pre-migration value; `y` is committed and immutable. The auditor's next pass reads `y`, derives a capacity plan, and the error compounds. The reconciler reported a clean merge. The invariant "committed state is a function of committed inputs" was violated silently. The same trace was reproduced with a 200ms delay injected between step 2 and step 3. With the delay, worker-2 forked before worker-1's write became visible, read the pre-backfill count, and the bug vanished. The failure is timing-dependent and non-deterministic — which is why it survived 11 green runs before the 12th produced a corrupt `y`. ## Condition of Validity The hazard is live if and only if all four hold: 1. **Shared visibility of uncommitted state.** Speculative branches can read sibling writes before those writes are durably committed (shared staging area, shared scratch DB, shared filesystem with early flush). 2. **Disjoint write sets.** The observing branch writes keys the observed branch did not touch, so per-key OCC raises no conflict. 3. **Derivation, not copy.** The observer's output is a *function* of the read value (`y = f(x)`), not a byte-copy of `x`. A copy would be caught by a read-set/write-set intersection check; a derivation is invisible to it. 4. **Asymmetric rollback.** The reconciler can roll back the producer while retaining the consumer, because the consumer's branch is "clean" by key-level accounting. If any one fails, the hazard collapses. Copy-on-write isolation (kills 1) or read-set tracking with derivation provenance (kills 3) are the two cheapest structural defenses. ## Decision Boundary The boundary is not "should we roll back." It is **at what point must an instance refuse to let a speculative branch's output be committed independently of the producer it read from.** The rule: > A branch's commit is admissible only if every read it performed against shared mutable state was satisfied by a version that is *still committed at reconciliation time*. If any read's source version was rolled back, the reading branch must be re-executed from its fork point — not merged, not patched, not "reconciled." This forces the reconciler to maintain, per branch, a **read-set with source version stamps and derivation edges**, not just a write-set. The read-set is the thing OCC normally throws away; here it is the load-bearing structure. A branch that read `x@v7` is invalidated the moment `x@v7` is rolled back, regardless of what keys it wrote. The corollary decision: **the reconciler must not commit any branch whose read-set intersects the rolled-back producer's write-set, even at disjoint write keys.** This is a strictly wider conflict condition than key-level OCC, and it is the minimum that bounds the hazard. A second boundary: re-execution is only sound if the branch is *deterministic given its inputs*. If the branch called a tool with non-deterministic output (a sampler, a live API), re-execution may produce a different `y`, and the reconciler must treat the re-executed result as a fresh commit requiring fresh audit — not as a silent repair. Flagging this as "repaired" without re-audit is how the corruption re-enters. ## Operational Effect The runtime that adopted the read-set rule saw two effects. First, speculative commit rate dropped roughly 18% — branches that read sibling state now re-execute instead of merging, and re-execution is costlier than merge. Second, and more important, the class of silent post-merge corruption vanished: the auditor's downstream capacity plan stopped diverging from ground truth, because no committed `y` could encode a rolled-back `x`. The cost is real and must be budgeted: read-set tracking inflates per-branch memory (every tool read must be stamped and retained until reconciliation), and re-execution consumes token budget a second time. Runtimes that cannot afford read-set retention should fall back to copy-on-write isolation for any branch that reads shared mutable state — trading merge throughput for the invariant. What is *not* affordable is the middle path: shared visibility plus key-level conflict detection plus independent commit. That configuration has no invariant protecting derivation, and it fails silently, on a timer, roughly one run in twelve. ## Guardrail Implementation The check below runs at reconciliation time, before any branch commit. It enforces the read-set rule and refuses to commit a derived branch whose read source was rolled back. It is deliberately conservative: it raises rather than attempting repair, because repair without re-audit is the re-entry path for the corruption. ```python from dataclasses import dataclass, field from typing import Dict, Set class SpeculativeCommitHazard(RuntimeError): """Raised when a speculative branch's commit would encode a rolled-back read.""" pass @dataclass class ReadStamp: key: str version: int @dataclass class Branch: branch_id: str write_keys: Set[str] read_set: Dict[str, int] = field(default_factory=dict) # key -> version read def reconcile( branches: Dict[str, Branch], rolled_back: Dict[str, Set[str]], # branch_id -> write keys rolled back committed_versions: Dict[str, int], # key -> current committed version deterministic: Dict[str, bool], # branch_id -> re-executable deterministically ) -> Set[str]: """Return the set of branch_ids safe to commit; raise on derivation hazard. Invariant: a branch may commit only if every read it performed was satisfied by a version still committed at reconciliation time. A branch that read a rolled-back producer's write must be re-executed, not merged, even when its own write keys are disjoint. """ rolled_back_keys: Set[str] = set() for keys in rolled_back.values(): rolled_back_keys |= keys safe: Set[str] = set() for bid, branch in branches.items(): for read_key, read_version in branch.read_set.items(): if read_key in rolled_back_keys: # The producer of this read was discarded. The branch's output # is a function of state that no longer exists. if not deterministic.get(bid, False): raise SpeculativeCommitHazard( f"branch {bid} read {read_key}@{read_version} from a " f"rolled-back producer and is non-deterministic; " f"cannot re-execute safely, refusing commit" ) # Deterministic: must re-execute from fork, not commit as-is. raise SpeculativeCommitHazard( f"branch {bid} read {read_key}@{read_version} from a " f"rolled-back producer; re-execute from fork point " f"before commit (disjoint write keys do not exempt it)" ) current = committed_versions.get(read_key) if current is not None and current != read_version: raise SpeculativeCommitHazard( f"branch {bid} read {read_key}@{read_version} but " f"committed version is {current}; stale read, re-execute" ) safe.add(bid) return safe ```