# Why does an instance of a speculative multi-agent executor corrupt committed state when a sub-agent's rollback is triggered by a divergent outcome the orchestrator never observed? **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fork speculative sub-agents against a shared mutable state store, buffer their writes, and commit or roll back per-branch based on a divergence predicate. Does not apply to stateless fan-out (map/reduce without shared state), nor to single-agent checkpoint/resume, nor to rollback schemes where each branch owns an isolated copy-on-write namespace with no cross-branch visibility. ## Core Distinction The failure is not "a divergent sub-agent rolled back incorrectly." It is subtler: the orchestrator's rollback decision is driven by a *divergence predicate evaluated over the branch's final output*, but the branch's *writes were already visible to sibling branches* through the shared store during the speculative window. When the predicate fires and the branch is rolled back, the orchestrator unwrites the branch's own log entries — but it cannot unwrite the *derived* writes that sibling branches computed by reading those entries. Those siblings are still live, still speculative, and their buffered writes now encode a causal dependency on a state that, post-rollback, never existed. On commit, the siblings replay a transaction whose read-set references a version that the rollback has invalidated. The result is committed state that is internally inconsistent: a value that was computed from a predecessor that the system has formally declared never happened. This is distinct from a classic write-skew or lost-update problem because the conflict is *asymmetric in time*: the rollback happens after the sibling has already read, but before the sibling has committed. The window is exactly the speculative overlap. Nothing in the per-branch commit protocol detects it, because each branch's commit is individually well-formed relative to the state it *saw*. ## What Was Observed A three-branch speculative executor was forked against a shared key-value store to answer a planning query. Branch A (planner) wrote `plan.v1 = {...}` at t=0. Branch B (critic) read `plan.v1` at t=1 and wrote `critique.v1 = "reject: step 3 infeasible"` at t=2. Branch C (executor) read `plan.v1` at t=1, read `critique.v1` at t=3, and wrote `action.v1 = "skip step 3"` at t=4, conditioned on the critique. At t=5 the orchestrator evaluated the divergence predicate on Branch A's terminal output and found it diverged from the reference plan (a schema mismatch in `plan.v1`). It rolled back Branch A: `plan.v1` was deleted, its log entry tombstoned, and the branch marked `ABORTED`. Branches B and C were untouched — B had already produced its critique, C had already produced its action, and both were still marked `SPECULATIVE_PENDING`. At t=6 the orchestrator committed B and C. The committed store now contained `critique.v1` and `action.v1` with no `plan.v1`. The action's read-set referenced a version hash of `plan.v1` that no longer existed in the version index. Downstream consumers that replayed the action's justification chain hit a dangling reference and, depending on their resolver, either raised or — worse — silently substituted a default plan, producing an action that was never justified by any surviving state. The observed invariant violation: **a committed write's read-set must be a subset of the committed version index.** The speculative executor enforced this per-branch at write time but never re-validated it at commit time after a sibling rollback. ## Condition of Validity The corruption is only possible when all four hold simultaneously: 1. **Shared visibility during speculation.** Branches read each other's uncommitted writes. If branches are isolated (copy-on-write per branch, merge at commit), the read-set cannot reference a rolled-back version. 2. **Derived writes without provenance re-check.** A sibling's write encodes a dependency on a version but the commit path does not re-validate that dependency against the post-rollback index. 3. **Rollback scoped to the branch's own writes.** The rollback primitive tombstones the aborted branch's entries but does not cascade to dependents, because the dependency graph is not tracked. 4. **Non-atomic commit ordering.** The rollback of A completes before B and C commit, so there is a real interval in which the store is in the "A absent, B and C pending" state and the pending branches are not re-evaluated. If any one fails, the failure degrades to a benign abort (branch B or C is itself rolled back) or to a detected conflict (commit-time read-set validation rejects the commit). The dangerous regime is the one where all four hold and the commit path trusts the write-time validation. ## Decision Boundary The boundary is between **per-branch write-time validation** and **commit-time read-set re-validation against the current version index**. The former is necessary and insufficient. The decision the executor must make at every commit is: *is this branch's read-set still resolvable against the version index as it exists now, after all sibling rollbacks that have occurred since this branch last validated?* Two boundary cases matter operationally: - **Cascade depth.** If B depends on A and C depends on B, rolling back A must invalidate B and transitively C. A one-level re-validation that only checks direct reads against the index will catch C's direct read of `critique.v1` (still present) but miss that `critique.v1`'s own read-set is now dangling. The re-validation must be transitive over the dependency graph, or the store must maintain a reverse-dependency index that the rollback walks. - **Re-validation timing.** Re-validating only at commit is insufficient if two branches commit in the same batch and one's rollback is deferred to the batch boundary. The re-validation must run *after* all rollbacks in the batch are applied and *before* any commit in the batch is made durable — i.e., the batch is a transaction boundary, not a sequence of independent commits. ## Operational Effect Without the guardrail, the executor produces committed state that passes every per-write check and fails a global consistency check only when a downstream consumer replays provenance. The failure is silent at commit time and loud at consumption time, which is the worst possible latency profile: the corruption is attributed to the consumer, not the executor, and the executor's logs show a clean commit sequence. The required architectural invariant: **commit is a two-phase operation over the batch.** Phase one applies all rollbacks and computes the surviving version index. Phase two re-validates every pending branch's transitive read-set against that index; any branch with a dangling reference is itself rolled back (and its reverse-dependents re-queued for re-validation), and only branches whose full transitive read-set resolves are committed. The invariant to assert at the end of phase two is that the committed store's dependency graph is closed under "read-set ⊆ version index." A speculative executor that cannot state this invariant in its commit path is not safe to run with shared visibility. ```python from dataclasses import dataclass, field from typing import Dict, Set, List class DanglingReadSetError(RuntimeError): """Raised when a branch commits with a read-set referencing a rolled-back version.""" @dataclass class Branch: name: str read_set: Set[str] = field(default_factory=set) # version hashes read write_keys: Set[str] = field(default_factory=set) # keys written status: str = "SPECULATIVE_PENDING" class SpeculativeStore: def __init__(self) -> None: self.version_index: Set[str] = set() self.branches: Dict[str, Branch] = {} def register(self, b: Branch) -> None: self.branches[b.name] = b def rollback(self, name: str) -> None: b = self.branches[name] b.status = "ABORTED" # remove only this branch's own written versions for v in list(self.version_index): if v.startswith(f"{name}:"): self.version_index.discard(v) def _transitive_read_set(self, b: Branch, seen: Set[str]) -> Set[str]: if b.name in seen: return set() seen.add(b.name) acc = set(b.read_set) for other in self.branches.values(): if other.status == "SPECULATIVE_PENDING" and other.name != b.name: if b.read_set & {f"{other.name}:{k}" for k in other.write_keys}: acc |= self._transitive_read_set(other, seen) return acc def commit_batch(self, pending: List[str]) -> None: # Phase 1: rollbacks already applied by caller; index reflects survivors. # Phase 2: re-validate transitive read-sets, cascade aborts, then commit. changed = True while changed: changed = False for name in pending: b = self.branches[name] if b.status != "SPECULATIVE_PENDING": continue needed = self._transitive_read_set(b, set()) dangling = needed - self.version_index if dangling: b.status = "ABORTED" changed = True for name in pending: b = self.branches[name] if b.status != "SPECULATIVE_PENDING": continue needed = self._transitive_read_set(b, set()) if not needed <= self.version_index: raise DanglingReadSetError( f"branch {name} read-set not closed over version index: " f"{sorted(needed - self.version_index)}" ) b.status = "COMMITTED" for k in b.write_keys: self.version_index.add(f"{name}:{k}") ```