# How should an instance reconcile a speculative branch whose rollback was shadowed by a committed sibling write **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent orchestrators that speculatively fork sibling agents against shared mutable state (filesystem, KV store, tool-side caches, message bus) and reconcile by rollback-or-commit on branch resolution. Does not apply to fully isolated sandboxes with copy-on-write at the process boundary, nor to single-agent speculative decoding at the token level. ## Core Distinction Speculative execution across agents fails in two categorically different ways, and conflating them is the root of the shadow-rollback bug. The first is **divergence**: a speculative branch's predicted outcome is not what the real trajectory produced, so the branch is discarded. Divergence is a *logical* event — the orchestrator knows the branch lost and rolls it back. This is the well-understood case, and most rollback machinery targets it. The second is **write shadowing**: a losing branch's rollback is *scoped to the branch's own journal*, but the branch's effects leaked into a shared resource that a *winning sibling* subsequently read and depended on. The rollback executes, reports success, and the orchestrator believes state is clean — yet the winner's committed output was computed from a value that no longer exists. The rollback did not fail; it succeeded against the wrong baseline. This is a *causality* event, and it is invisible to per-branch journaling because no branch's journal records the cross-branch read. The invariant that shadowing violates: **a speculative branch's rollback must restore every resource to the value observed at branch-fork time, not merely undo the branch's own writes.** When two branches share a resource and one reads the other's speculative write, fork-time restoration is insufficient — the reader's committed output is already contaminated, and no amount of undoing the writer's journal repairs it. ## What Was Observed A planning agent forks three sibling executors against a shared `workspace/` directory and a `state.json` config file. Branch A (speculative) edits `state.json` to set `feature_flag: true` and writes `workspace/plan.md`. Branch B (speculative) reads `state.json`, sees `feature_flag: true`, and — critically — generates a downstream artifact `workspace/report.md` whose content embeds the flag-on branch of a conditional. Branch A is then judged divergent (its prediction about downstream tool availability was wrong) and rolled back: `state.json` is restored to `feature_flag: false`, `plan.md` deleted. Branch B is judged correct and committed. `report.md` persists. The committed state is now internally inconsistent: `report.md` claims the feature is enabled, `state.json` says it is disabled. No journal flagged an error. The rollback of A returned `{"status": "ok", "reverted": ["state.json", "plan.md"]}`. B's commit returned `{"status": "ok"}`. Both agents behaved correctly under their local contracts. The orchestrator's reconciliation layer has no record that B ever read A's speculative value, because B's journal records `read state.json -> {feature_flag: true}` as an ordinary read — it has no way to know that value was speculative and destined for rollback. The failure surfaces later, when a verification agent replays the committed state and finds `report.md` inconsistent with `state.json`. The replay discrepancy is attributed to B (the committer), not to the shadowed rollback of A, and the wrong agent is penalized or retried — which, on retry, reproduces the same contamination because the fork topology is unchanged. ## Condition of Validity The shadow-rollback hazard is live if and only if all three hold: 1. **Shared mutable resource.** Two or more sibling branches access the same resource identity (same path, same key, same endpoint) without copy-on-write isolation. Read-only sharing is safe; the hazard requires at least one writer and one reader of the *same* resource. 2. **Read-after-speculative-write within the fork window.** The reader branch executes its read after the writer branch's speculative write and before the writer's resolution (commit or rollback). If the read happens before the write, or after rollback completes, no shadowing occurs. 3. **Non-idempotent or content-dependent downstream effect.** The reader's committed output must *depend* on the value it read. If B merely logged the flag without branching on it, rollback of A leaves B's output valid. The hazard requires B's artifact to encode A's speculative value. When any one fails, per-branch journaling is sufficient and the standard rollback contract holds. The dangerous regime is precisely the intersection: shared resource, interleaved read-after-write, content-dependent commit. Note the asymmetry that makes this non-obvious: the *writer's* rollback is correct and complete with respect to the writer. The *reader's* commit is correct and complete with respect to the reader's local view. The defect lives only in the *relationship* between them, which neither branch's journal models. This is why it survives code review of either branch in isolation. ## Decision Boundary The orchestrator must decide, at fork time, whether to allow shared-resource speculation or force isolation. The boundary is drawn on **read-write overlap across siblings**, computed before execution: - If the predicted read-set of every branch is disjoint from the predicted write-set of every other branch, allow shared speculation with per-branch journaling. This is the cheap path and covers most fan-out. - If any branch's read-set intersects another branch's write-set, the orchestrator has two admissible responses: (a) serialize the overlapping branches (forbid concurrent speculation on that resource), or (b) force copy-on-write isolation for the resource so the reader sees a stable snapshot and the writer's rollback cannot reach it. What is *not* admissible is to allow the overlap and rely on rollback. Rollback is a writer-side operation and cannot repair a reader-side dependency it never observed. The boundary also governs the *commit* decision: a branch whose output depends on a value that was speculative at read time must be marked **provisionally committed** and held pending resolution of the value's producer. If the producer rolls back, the provisional commit must be invalidated and the reader re-executed against the restored baseline. Committing the reader before the producer resolves is the exact transition that produces an unrecoverable shadow. ## Operational Effect Enforcing the boundary converts an invisible correctness failure into a visible scheduling constraint. The cost is reduced parallelism on read-write-overlapping fan-out — branches that could have run concurrently must serialize or pay for isolation. The benefit is that every committed state is causally consistent: no committed artifact encodes a value that was later rolled back. The concrete operational changes: - **Track provenance of reads, not just writes.** Each branch journal must record, for every read, whether the observed value was *base* (pre-fork) or *speculative* (written by a sibling during the fork window), and by which branch. This is the datum the rollback layer needs and currently lacks. - **Propagate invalidation transitively.** When branch A rolls back, every branch that read A's speculative value is invalidated, and every branch that read *those* branches' outputs is invalidated, until the dependency frontier reaches base reads. Invalidation is a graph traversal over the read-provenance edges, not a flat list. - **Gate commit on producer resolution.** A branch with any speculative-read dependency cannot reach `committed` until all its producers reach `committed`. Producers that roll back force re-execution of dependents. - **Replay must reconstruct fork topology.** Verification replay that flattens the fork into a linear history will miss shadowing entirely; replay must preserve which reads were speculative to detect the inconsistency that the live run failed to catch. The guardrail is a single invariant enforced at the reconciliation layer: **no branch commits while it holds an unresolved speculative-read dependency.** Everything above is machinery to detect and discharge that dependency. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class ShadowedRollbackError(RuntimeError): """Raised when a rollback would leave a committed sibling dependent on a reverted speculative value.""" pass class BranchState(Enum): SPECULATING = "speculating" PROVISIONAL = "provisional" # has speculative-read deps, cannot commit yet COMMITTED = "committed" ROLLED_BACK = "rolled_back" INVALIDATED = "invalidated" # dependency rolled back; must re-execute @dataclass class ReadRecord: resource: str producer: str | None # None => base/pre-fork value; else branch id of speculative writer @dataclass class Branch: bid: str writes: Set[str] = field(default_factory=set) reads: list[ReadRecord] = field(default_factory=list) state: BranchState = BranchState.SPECULATING def speculative_deps(self) -> Set[str]: return {r.producer for r in self.reads if r.producer is not None} class Reconciler: def __init__(self) -> None: self.branches: Dict[str, Branch] = {} def register(self, b: Branch) -> None: self.branches[b.bid] = b def commit(self, bid: str) -> None: b = self.branches[bid] unresolved = { p for p in b.speculative_deps() if self.branches[p].state not in (BranchState.COMMITTED,) } if unresolved: # Commit would freeze a value whose producer may still roll back. b.state = BranchState.PROVISIONAL raise ShadowedRollbackError( f"branch {bid} cannot commit: holds speculative-read deps on " f"unresolved producers {sorted(unresolved)}" ) b.state = BranchState.COMMITTED def rollback(self, bid: str) -> None: b = self.branches[bid] # Find every branch that read a value this branch speculatively wrote. dependents = [ other.bid for other in self.branches.values() if other.bid != bid and bid in other.speculative_deps() ] committed_dependents = [ d for d in dependents if self.branches[d].state == BranchState.COMMITTED ] if committed_dependents: # Rolling back now would shadow a committed read: the dependent's # artifact already encodes a value about to vanish. Refuse and # force invalidation instead of a silent, "successful" rollback. for d in committed_dependents: self.branches[d].state = BranchState.INVALIDATED b.state = BranchState.ROLLED_BACK raise ShadowedRollbackError( f"rollback of {bid} shadowed by committed dependents " f"{sorted(committed_dependents)}; marked INVALIDATED for re-execution" ) # No committed reader: safe to revert and invalidate provisional readers. for d in dependents: if self.branches[d].state in (BranchState.PROVISIONAL, BranchState.SPECULATING): self.branches[d].state = BranchState.INVALIDATED b.state = BranchState.ROLLED_BACK def reconcile_fork(reconciler: Reconciler, winner: str, loser: str) -> None: """Commit the winner, roll back the loser, in an order that respects read provenance.""" # Commit the winner first only if it has no dep on the loser; otherwise the # commit() guard will raise and force re-execution, which is the correct outcome. reconciler.commit(winner) reconciler.rollback(loser) ```