# Why does an instance commit a speculative branch whose read-set was invalidated by a sibling's rollback? The orphaned-write hazard in parallel plan drafting **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that fan out an agent plan into parallel speculative branches (drafting variants, parallel tool-call trees, or N-of-M sampling) under a shared mutable world state, then select and commit one branch while rolling back the rest. Does not apply to branches executed against fully isolated, copy-on-write sandboxes with no shared external side effects (e.g., pure in-memory reasoning branches with no tool writes). ## Core Distinction There are two ways a speculative branch can be "wrong" at commit time, and they are routinely conflated: 1. **Value invalidation** — the branch's computed outputs no longer match the world because a sibling's write changed an input the branch read. This is the failure everyone tests for: you re-read the input, compare versions, and reject. 2. **Read-set provenance invalidation** — the branch's *inputs* were themselves produced by a sibling branch that has since been rolled back. The branch read a value that was never committed and is now orphaned. The second is the dangerous one, and it is non-obvious because the branch's local read-set looks perfectly valid: the version token it recorded still matches the current version of the object it read. The object *exists* and is *unchanged since the read*. What has changed is that the object's lineage now traces to a rolled-back speculative branch — the value is a **ghost dependency**. A commit protocol that validates only "did the bytes I read change?" will pass a branch that is structurally built on a discarded world. ## What Was Observed A planner agent decomposed a migration task into three speculative branches over a shared state store: - **Branch A** writes `config.schema_version = 7` (speculative). - **Branch B** reads `config.schema_version` — observes `7` because A's speculative write is visible in the shared store — and writes `migration_plan.target = 7`. - **Branch C** is the selected commit candidate (say it scored highest on a verifier rubric). The selector rolled back A (it failed a downstream check) and B (it depended on A), then committed C. During commit, C's validator re-read `migration_plan.target`, found the version token unchanged since C read it, and passed. But C's plan had been drafted against `migration_plan.target = 7`, a value written by B, which was rolled back. The rollback of B *deleted* the object, but C had cached the value and its read-set recorded only the version, not the existence-tombstone that the rollback created. The commit produced a plan referencing schema 7 against a store that had reverted to schema 6. The trace, condensed: ``` t0 A.begin(); A.write(schema_version, 7) # speculative, version=1 t1 B.begin(); B.read(schema_version) -> 7 # sees A's speculative write B.write(migration_plan.target, 7) # speculative, version=1 t2 C.begin(); C.read(migration_plan.target) -> 7 # sees B's speculative write C.read_set = {(migration_plan.target, version=1)} t3 selector: rollback A -> schema_version reverts to 6, version=2 t4 selector: rollback B -> migration_plan.target DELETED (tombstone, version=2) t5 selector: commit C t6 C.validate(): for (k,v) in read_set: current_version(k) == v ? migration_plan.target: version 2 != 1 -> REJECT? ``` The subtlety that turned this into a silent failure rather than a caught one: the rollback of B *recreated* the object with the pre-B value rather than tombstoning it, and **reset its version counter to the pre-speculation value** as part of the compensating write. So at `t6`, `migration_plan.target` existed with version `1` again — matching C's recorded read-set token exactly. C validated clean, committed, and carried a ghost dependency into production. ## Condition of Validity The invariant a commit protocol must hold is: > A speculative branch may commit only if every object in its read-set is (a) unchanged in value, **and** (b) has lineage that traces exclusively to committed (non-speculative) writes, **and** (c) has not been the target of any rollback compensating write since the branch's read. Condition (b) is the one that is almost universally omitted. Version-token equality (a) and even tombstone checks (c) do not imply (b): a compensating rollback can restore both the value and the version token to their pre-speculation state, making an orphaned read indistinguishable from a clean one by any per-object check. Lineage must be tracked as a separate, monotonic **commit-epoch** attached to every write — not a per-object version, but a global (or per-region) counter that increments only on *commit* and never decrements on *rollback*. A branch records the commit-epoch of the world it read from; at commit time, any object in its read-set whose *producing write* carries a commit-epoch greater than the branch's recorded base epoch, or whose producing write belongs to a branch now marked rolled-back, invalidates the branch regardless of value or version equality. This condition is valid only when the state store exposes write lineage (producer branch id + commit epoch) to the validator. In stores that do not, the correct fallback is to *serialize* speculative branches that share a read-set — i.e., refuse to speculate across a dependency frontier — which trades parallelism for the invariant. ## Decision Boundary The boundary between "commit is safe" and "commit is a ghost dependency" is crossed precisely when a rollback performs a **compensating write that restores a prior value and a prior version token**, rather than a tombstone-and-increment. Two rollback strategies therefore have opposite safety properties: - **Tombstone rollback** (delete or mark-rolled-back, bump version monotonically): safe under naive version-token validation, because any reader of the rolled-back object sees a version mismatch. - **Compensating rollback** (re-apply the pre-speculation value, restore the version counter): *unsafe* under naive validation, because it manufactures a state that is byte-identical and version-identical to the pre-speculation world, erasing the evidence that a speculative write ever occurred. The decision rule: if your store's rollback is compensating (common in "undo log" implementations that replay inverse operations to keep the store clean), you **must** carry an out-of-band commit-epoch in the read-set and validate against it; per-object version checks are provably insufficient. If your rollback is tombstoning, per-object version checks are sufficient for (a) and (c) but still not for (b) across *transitive* dependencies — B read A's speculative value, so B's write is itself a ghost even though B's own object was never rolled back before C read it. ## Operational Effect The practical consequence is a class of **silent cross-branch contamination** that survives all value-level validation and surfaces only as downstream semantic inconsistency — a plan referencing a schema version, a config key, or a computed aggregate that no committed branch ever produced. It is silent because the contaminated branch's own local checks pass; it is cross-branch because the evidence lives in a sibling's lifecycle, not in the branch's own state. Mitigations that bound it: 1. **Commit-epoch stamping**: every write carries `(producer_branch, commit_epoch)`; read-sets record the base epoch; validation rejects any read whose producer is rolled-back or whose epoch exceeds the base. 2. **Dependency-frontier serialization**: branches whose read-sets intersect a sibling's write-set are not run in parallel; they are ordered so no branch can read a speculative write it did not itself produce. 3. **Rollback as tombstone, never compensation**: compensating writes must still bump a monotonic version and record the rollback, so the erasure is observable. 4. **Transitive read-set closure**: when validating a branch, expand its read-set through the producing branches' read-sets to catch ghost dependencies one hop removed. The failure is not that the branch was wrong about the world; it is that the protocol asked the world whether it had changed and the world, having been rolled back, lied by being identical to itself. ```python class GhostDependencyError(RuntimeError): """Raised when a speculative branch's read-set traces to a rolled-back sibling.""" pass class WriteRecord: def __init__(self, producer_branch: str, commit_epoch: int, value, version: int): self.producer_branch = producer_branch self.commit_epoch = commit_epoch # monotonic; increments on COMMIT only self.value = value self.version = version # per-object; may be restored by rollback class SpeculativeStore: def __init__(self): self._data: dict[str, WriteRecord] = {} self._rolled_back: set[str] = set() self._commit_epoch = 0 def commit_epoch(self) -> int: return self._commit_epoch def write(self, branch: str, key: str, value, version: int) -> None: # Speculative writes carry the *current* commit epoch; they do not advance it. self._data[key] = WriteRecord(branch, self._commit_epoch, value, version) def read(self, key: str): rec = self._data.get(key) return (rec.value, rec.version, rec.producer_branch, rec.commit_epoch) if rec else (None, None, None, None) def rollback(self, branch: str, prior: dict[str, WriteRecord]) -> None: # Compensating rollback: restores prior value AND prior version token. # This is exactly what erases the evidence a naive validator relies on. self._rolled_back.add(branch) for key, rec in prior.items(): self._data[key] = rec def commit(self) -> None: self._commit_epoch += 1 def validate_and_commit(store: SpeculativeStore, branch: str, read_set: dict[str, tuple]) -> None: base_epoch = read_set["__base_epoch__"] for key, (value, version, producer, epoch) in read_set.items(): if key == "__base_epoch__": continue cur = store.read(key) cur_value, cur_version, cur_producer, cur_epoch = cur # (a) value/version check — necessary but NOT sufficient. if cur_version != version or cur_value != value: raise GhostDependencyError( f"branch {branch}: value/version drift on {key!r} " f"(expected v{version}, saw v{cur_version})" ) # (b) lineage check — the invariant that catches compensating-rollback ghosts. if cur_producer in store._rolled_back: raise GhostDependencyError( f"branch {branch}: read-set key {key!r} produced by rolled-back " f"branch {cur_producer!r} — ghost dependency" ) # (c) epoch check — catches transitive speculation beyond the base world. if cur_epoch > base_epoch: raise GhostDependencyError( f"branch {branch}: read-set key {key!r} written at commit_epoch " f"{cur_epoch} > base {base_epoch} — uncommitted lineage" ) store.commit() ```