# When must an instance refuse to commit speculative subplan effects before verification quorum, and how rollback ordering leaks irreversible side effects **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan out parallel agent subplans against shared external state (filesystems, APIs, message queues, databases) and rely on post-hoc verification to roll back failed branches. Does not apply to pure-compute subplans whose effects are entirely contained in an in-context scratchpad with no external write channel. ## Core Distinction The distinction that matters is between **speculative read amplification** and **speculative write amplification**. Reading speculatively is safe because reads are idempotent and order-insensitive: a parallel branch can query a resource, get a stale answer, and be discarded with no residue. Writing speculatively is not safe, because parallel subplans that each observe a *pre-commit* world can produce writes that are individually valid against that world but collectively inconsistent, and because rollback of those writes is *order-dependent* while the branches that produced them were *order-free*. The failure mode is this: an orchestrator launches N subplans in parallel, each of which computes a plan against the same snapshot and then *immediately executes* the effects of that plan (file writes, API mutations, record updates) so that later verification can inspect real artifacts rather than predicted ones. When verification of any branch fails, the orchestrator rolls back the committed effects of the failed branch. But the remaining branches already executed against a world that included the failed branch's effects — or, worse, their effects *interleave* with the failed branch's effects on the same resource. Rollback restores the failed branch's resource to its pre-branch snapshot, silently clobbering a concurrent branch's legitimate write that landed after the snapshot was taken. The verification quorum then passes on a corrupted world state, and the orchestrator reports success. The invariant violated: **a speculative write must be reversible by a function that depends only on that write's own snapshot, never on the global order in which sibling writes landed.** Parallel speculative execution with naive snapshot-and-restore violates this because snapshot-restore is a last-writer-wins operation, not an inverse. ## What Was Observed A four-branch orchestration task: refactor a service across four modules, one agent per module, all launched against a shared repository checkout. Each branch was instructed to (1) read its module, (2) apply edits, (3) run the module's test suite, (4) report pass/fail. The orchestrator's contract: if any branch's tests fail, roll that branch back to its pre-edit snapshot; if all branches pass, merge. Branch B (module `billing/`) failed its test suite on the first attempt because of a flaky integration test. Its rollback fired: `git checkout -- billing/` plus a snapshot restore of a shared config file `config/limits.yaml` that branch B had also touched. Branch C (module `ledger/`) had, between branch B's snapshot and branch B's rollback, written a new rate-limit entry into the *same* `config/limits.yaml`. Branch B's rollback restored the file to B's pre-edit snapshot, deleting C's entry. Branch C's own tests had already passed (they ran before the rollback), so C reported success. The orchestrator's final verification read `config/limits.yaml`, saw a consistent file, and merged. The merged service shipped with C's rate-limit entry absent — a silent production regression that no branch's tests covered because each branch tested against its own local view. The trace: ``` t0 orchestrator snapshots config/limits.yaml -> S0 t1 launch B, C, D, E in parallel (all read S0) t2 B writes limits.yaml (adds B's entry) -> S_B t3 C reads limits.yaml (sees S_B, includes B's entry) t4 C writes limits.yaml (adds C's entry) -> S_BC t5 B test fails; rollback B: restore limits.yaml <- S0 t6 limits.yaml == S0 (C's entry destroyed, B's destroyed) t7 C test passed at t4 against S_BC; reports success t8 quorum: B failed, C/D/E passed -> merge t9 merged state lacks C's entry; no test detects it ``` Two compounding defects. First, **snapshot granularity was per-branch, not per-resource-version**: B's rollback restored a whole-file snapshot rather than a delta, so it could not distinguish "my entry" from "C's entry." Second, **verification was branch-local**: C verified against the world as it was at t4, not against the world as it would be after all rollbacks. The orchestrator assumed verification of a branch is stable under sibling rollback; it is not. A second observation from the same incident: the rollback of B was *not idempotent* under retry. Because the orchestrator retried the failed branch (B) once, the snapshot restore ran twice. The second restore was a no-op on `config/limits.yaml` (already at S0) but re-triggered a post-rollback hook that decremented a counter in a shared metrics store, corrupting the orchestrator's own bookkeeping of how many branches were live. Rollback side effects are effects too, and they were not themselves snapshotted. ## Condition of Validity The naive "speculate-then-rollback" pattern is valid **only** under all of the following, which must be checked, not assumed: 1. **Resource disjointness.** No two parallel branches write the same resource identity. Disjointness must be established by static analysis of the subplan's declared write-set *before* launch, not by runtime observation. If write-sets are unknown (common when agents call tools dynamically), the pattern is invalid. 2. **Snapshot invertibility.** Every speculative write has a registered inverse operation that restores exactly the bytes/fields that write changed, computed as a delta against the version the branch *read*, not a whole-resource snapshot. Whole-resource restore is only valid if no sibling wrote to the resource between snapshot and rollback — which is exactly what parallelism prevents you from knowing. 3. **Verification isolation.** Each branch's verification predicate must be a function of the branch's own post-state and the *pre-commit* world (S0), never of sibling post-states. If a branch's test can observe sibling writes, its pass/fail is not stable under sibling rollback. 4. **Rollback atomicity under retry.** Rollback operations must be idempotent and must not themselves emit un-snapshotted side effects (metrics, logs consumed by control flow, queue messages). If a rollback hook is non-idempotent, retrying the branch corrupts orchestrator state. 5. **No cross-branch read-after-write dependency in the plan.** If branch C's plan was *derived from* branch B's speculative write (C read S_B at t3), then C's plan is contingent on B's commit. Rolling back B invalidates C's plan even though C's tests pass. The orchestrator must track the read-set of each branch against sibling write-sets and mark C as *tainted* when B rolls back. Condition 5 is the one most often missed. It is a **provenance** condition: a branch is only independently verifiable if its read-set is disjoint from every sibling's write-set. When it is not, the branch is not a leaf of the dependency graph and its success cannot be counted toward quorum until its dependencies commit. ## Decision Boundary The boundary between "safe to speculate" and "must serialize" is drawn per resource, not per branch: - **Read-only resource, no sibling writes:** speculate freely; rollback is a no-op. - **Writable resource, write-set disjoint from all siblings, invertible delta:** speculate with delta rollback. This is the only regime where parallel speculative execution with rollback is sound. - **Writable resource, write-set overlaps a sibling, or write-set unknown:** **must serialize** the overlapping branches, or partition the resource (per-branch files, per-branch namespaces, copy-on-write branches). Serialization is the correct answer, not a cleverer rollback. - **Any branch whose read-set intersects a sibling's write-set:** mark tainted; its verification cannot be counted until the sibling commits. If the sibling rolls back, the tainted branch must be re-executed against S0, not merely re-verified. - **Rollback hook with external side effects:** must be wrapped in its own idempotency key and its effects must be excluded from control-flow decisions, or the whole speculate-rollback pattern is unsound. The orchestrator must compute, before launch, the transitive closure of (read-set ∩ sibling write-set) and refuse to launch in parallel any set with a non-empty intersection unless the resource is partitioned. This is a static precondition, checked once, not a runtime recovery. ## Operational Effect When the boundary is respected, parallel speculative execution is a large win: branches run concurrently, failures roll back cheaply, and quorum verification is sound because each branch's verdict is stable under sibling rollback. When it is violated, the failure is silent and the verification quorum *actively certifies corruption* — the worst class of failure, because it defeats the very mechanism meant to catch it. Operationally, the fix is not "better rollback." It is **partitioning and provenance**: 1. Partition writable resources per branch (copy-on-write checkouts, per-branch config namespaces, per-branch queues). Disjointness becomes structural, not analyzed. 2. Track read-sets and write-sets per branch; compute taint before counting any branch toward quorum. 3. Replace whole-resource snapshot-restore with delta-inverse rollback keyed to the version the branch read; reject restore if the resource's current version differs from the branch's expected post-write version (optimistic concurrency check). 4. Make every rollback hook idempotent and side-effect-free with respect to control flow. 5. If any of 1–4 cannot be established, serialize the overlapping branches. Serial execution with sound verification beats parallel execution with a corrupted quorum. The invariant to encode: **a branch's success is only admissible to quorum if its read-set is disjoint from every uncommitted sibling's write-set, and its rollback is a delta-inverse against its own read version.** Violating either makes the quorum a liar. ```python from dataclasses import dataclass, field from typing import FrozenSet class SpeculativeCommitError(RuntimeError): """Raised when a speculative subplan's effects cannot be soundly rolled back.""" @dataclass(frozen=True) class Subplan: branch_id: str read_set: FrozenSet[str] write_set: FrozenSet[str] read_versions: dict = field(default_factory=dict) # resource -> version read def assert_speculation_sound(branches: list[Subplan], resource_versions: dict) -> None: """Static precondition before parallel launch. Refuses unsafe speculation.""" for b in branches: for sib in branches: if sib.branch_id == b.branch_id: continue overlap = b.write_set & sib.write_set if overlap: raise SpeculativeCommitError( f"branch {b.branch_id} and {sib.branch_id} share writable " f"resource(s) {sorted(overlap)}; parallel speculation unsound, " f"partition or serialize" ) tainted = b.read_set & sib.write_set if tainted: raise SpeculativeCommitError( f"branch {b.branch_id} read-set intersects sibling " f"{sib.branch_id} write-set on {sorted(tainted)}; " f"branch is tainted and cannot be counted toward quorum " f"until {sib.branch_id} commits" ) for res in b.write_set: if res not in b.read_versions: raise SpeculativeCommitError( f"branch {b.branch_id} writes {res} without a recorded read " f"version; delta-inverse rollback impossible" ) if resource_versions.get(res) != b.read_versions[res]: raise SpeculativeCommitError( f"branch {b.branch_id} read {res} at version " f"{b.read_versions[res]} but current is " f"{resource_versions.get(res)}; optimistic concurrency check " f"failed, rollback would clobber a concurrent write" ) def rollback_branch(branch: Subplan, current_versions: dict, idempotency_seen: set) -> None: """Delta-inverse rollback with idempotency guard.""" if branch.branch_id in idempotency_seen: return # rollback already applied; do not re-emit side effects for res in branch.write_set: expected_post = branch.read_versions[res] if current_versions.get(res) != expected_post: raise SpeculativeCommitError( f"cannot roll back {res} for {branch.branch_id}: resource " f"advanced to {current_versions.get(res)}; a sibling wrote after " f"this branch, restore would destroy that write" ) # ... apply inverse deltas here ... idempotency_seen.add(branch.branch_id) ```