# Under what conditions must an instance treat a speculative branch's rollback as invalid because a sibling agent already committed a mutation to the shared substrate before reconciliation **Date of Record:** 2026 November 22 **Scope:** Applies to multi-agent planners that fork speculative execution branches (parallel plan candidates) against a shared mutable substrate—filesystem, database, tool-side state, or external API—and reconcile branches by commit/abort. Does not apply to purely functional branch models where every mutation is isolated in a copy-on-write overlay that is never visible to siblings. ## Core Distinction The failure hinges on a distinction that speculative-execution literature from CPU architecture obscures: **rollback of a branch's own writes is not the same as rollback of the substrate to a prior snapshot.** In a transactional database, aborting a transaction undoes exactly that transaction's writes and nothing else, because the engine enforces isolation between concurrent writers. Agent branches do not get that guarantee for free. A speculative branch executes by *calling tools*—`write_file`, `POST /orders`, `git commit`, `send_email`—and those tools mutate a substrate that has no notion of the branch. When branch B decides its plan is wrong and rolls back, it can only undo what it can identify as its own. If sibling branch A committed a mutation to the same substrate object between B's first write and B's rollback, the substrate is no longer in the state B's rollback logic assumes. The rollback is *invalid*: it restores a snapshot that never should have excluded A's commit, silently discarding A's work or, worse, resurrecting a pre-A value that A's downstream steps already consumed. The non-obvious part: the failure is not detected by either branch. B's rollback succeeds locally (its own writes revert cleanly). A's commit succeeded locally. The corruption is only visible to a subsequent reader, and only if that reader checks a version or hash it had no reason to expect had changed. ## What Was Observed A three-branch planner was tasked with "migrate the config loader to the new schema, update all call sites, and bump the dependency." The orchestrator forked three speculative plans: - **Branch A** (conservative): edit `config.py`, then `loader.py`, then run tests. - **Branch B** (aggressive): rewrite `config.py` wholesale, then regenerate call sites via codemod. - **Branch C** (auditor): read-only verification of whichever branch commits first. All three received the same substrate handle. The orchestrator intended that only one branch commit; the others abort. It did not enforce mutual exclusion on the substrate during the speculative phase—it relied on the branches "being careful." Trace of the failure: 1. B writes `config.py` (v1: full rewrite). Substrate version counter `config.py` → 2. 2. A reads `config.py` at v2, concludes the schema is already migrated, and writes `loader.py` importing the new symbols. `loader.py` → 2. 3. B's codemod step fails on a parse error in `loader.py` (it expected the old import form). B's plan is now invalid; B initiates rollback. 4. B's rollback replays its write log in reverse: it restores `config.py` to the *snapshot B captured at its start*—v1, the original. `config.py` → 3. 5. A commits. A's commit is registered as "success: migrated loader.py." But `loader.py` imports symbols that exist only in B's rewritten `config.py`, which no longer exists. The substrate now holds old `config.py` + new `loader.py`. 6. C, the auditor, reads the substrate, runs the test suite, and reports a hard failure. The orchestrator marks A as failed and retries A—against a substrate that B has already partially reverted. Retry A re-reads old `config.py`, re-derives its plan, and writes `loader.py` again. The loop does not converge because B's rollback is still pending in the orchestrator's commit queue and re-fires on each retry tick. The system never crashed. Every individual step returned `200 OK`. The corruption was a *lost update plus a snapshot regression*: B's rollback clobbered a version (v2) that A had legitimately consumed, and A's commit was validated against a precondition (v2 of `config.py`) that no longer held at commit time. ## Condition of Validity B's rollback is valid **iff** the following invariant holds for the entire interval `[t_first_write(B), t_rollback(B)]`: > No sibling branch commits a mutation to any substrate object that B wrote, and no sibling branch reads a version of a B-written object that B's rollback will subsequently revert. Equivalently, rollback is valid iff the substrate's version of every object B touched at rollback time equals the version B observed at its last write to that object. If any object's version advanced due to a *sibling* (not B), rollback is invalid. This is a *read-write conflict* condition, not a write-write one. The dangerous case is not two branches writing the same file—that is a detectable conflict. It is **A reading B's speculative write and building on it**, then B reverting. A's commit is then built on a phantom. Classic speculative execution solves this with a reorder buffer and a single retirement point; the agent orchestrator has neither unless it builds them. The condition generalizes to external tools with no version primitive. For `POST /orders`, the substrate is a remote service; "version" is whatever idempotency key or ETag the service exposes. If it exposes none, the invariant is **unverifiable** and rollback must be treated as unsafe by default. ## Decision Boundary The orchestrator must classify each rollback request into one of three regimes before executing: - **Isolated rollback (safe):** every object B wrote has version unchanged since B's last write, and no sibling has read those objects since. Execute rollback. This is the common case for branches whose writes are confined to disjoint files and whose siblings haven't yet read them. - **Conflicted rollback (unsafe, must escalate):** at least one B-written object advanced in version, or a sibling read a B-written object after B's write. Do **not** execute rollback. Instead, mark B as `ABORT_CONFLICTED`, freeze sibling commits that depend on the affected objects, and hand the conflict to a reconciler that can perform a three-way merge (B's base, B's speculative writes, current substrate) rather than a revert. - **Unverifiable rollback (unsafe, must refuse):** the substrate exposes no version/ETag/idempotency primitive for a touched object. Refuse rollback; require the branch to have been executed against a copy-on-write overlay from the start. The boundary is crossed the moment a sibling *reads* a speculative write, not when it writes. A read is a commitment to a version. An orchestrator that only guards writes will miss step 2 above entirely. ## Operational Effect Concretely, an orchestrator enforcing this boundary must maintain, per substrate object, a tuple `(version, writer_branch, readers_since_write)`. On any sibling read of an object last written by a speculative branch, the object is pinned: the writing branch can no longer roll back that object, only forward-commit or escalate. This converts the failure from silent corruption into a bounded, blocking conflict—the branch stalls until the reader either commits (promoting the speculative write to durable) or aborts (releasing the pin). The cost is reduced parallelism: reads serialize against speculative writes. The benefit is that no commit is ever validated against a phantom version, and no rollback ever discards a sibling's consumed state. For tool substrates with no version primitive, the only sound architectural move is to route all speculative execution through an overlay that the substrate never sees until a single atomic promote step—i.e., make the isolation explicit rather than hoping branches are "careful." ```python from dataclasses import dataclass, field from typing import Dict, Optional class InvalidRollbackError(RuntimeError): """Raised when a speculative branch's rollback would revert state a sibling consumed.""" pass @dataclass class ObjectRecord: version: int writer_branch: Optional[str] = None pinned_by_reader: bool = False class SubstrateLedger: def __init__(self) -> None: self._objects: Dict[str, ObjectRecord] = {} def write(self, obj: str, branch: str) -> None: rec = self._objects.setdefault(obj, ObjectRecord(version=0)) rec.version += 1 rec.writer_branch = branch rec.pinned_by_reader = False def read(self, obj: str, reader: str) -> int: rec = self._objects.setdefault(obj, ObjectRecord(version=0)) if rec.writer_branch is not None and rec.writer_branch != reader: # A sibling read a speculative write: pin it. rec.pinned_by_reader = True return rec.version def rollback(self, branch: str, written: Dict[str, int]) -> None: """written maps obj -> version observed at branch's last write.""" conflicts = [] for obj, observed_version in written.items(): rec = self._objects.get(obj) if rec is None: continue if rec.version != observed_version: conflicts.append((obj, "version_advanced", rec.version, observed_version)) elif rec.pinned_by_reader: conflicts.append((obj, "pinned_by_sibling_read", rec.version, observed_version)) if conflicts: raise InvalidRollbackError( f"branch {branch!r} rollback invalid: {conflicts}; " f"escalate to three-way reconciler, do not revert" ) for obj, observed_version in written.items(): rec = self._objects[obj] rec.version = observed_version - 1 rec.writer_branch = None def reconcile_branch(ledger: SubstrateLedger, branch: str, written: Dict[str, int]) -> None: try: ledger.rollback(branch, written) except InvalidRollbackError as exc: # Bounded response: freeze, do not retry blindly. raise InvalidRollbackError(f"reconciliation blocked: {exc}") from exc ```