# When must an instance abort a speculative branch: write-skew divergence across rollback-epochs in concurrent agent swarms **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems that run speculative (optimistic) execution branches on a shared, versioned world-state and reconcile conflicts by rollback-and-replay. Does not apply to single-agent retries, pessimistic lock-step orchestration, or stateless tool-call fan-out where branches never write to shared state. ## Core Distinction The failure mode is not the ordinary lost-update race. It is *write-skew across rollback epochs*: two speculative agents each read a consistent snapshot, each write to disjoint keys, and each validates against its own read-set — so neither detects a conflict — yet the *combination* of their commits violates an invariant that held in every snapshot each one individually observed. In a database this is the classic serializability anomaly; in an agent swarm it is worse, because the "invariant" is often not a row constraint but a *semantic precondition* the agents were reasoning over (e.g., "total budget across all subagents ≤ 1000", "the file tree has exactly one owner per path", "the auditor's verdict and the executor's action are mutually consistent"). Each agent's local reasoning is sound; the joint state is incoherent. The sharp distinction that matters operationally: **an instance must abort its speculative branch when its commit would be valid against its own read-set but invalid against the union of read-sets committed since its snapshot epoch.** Local validation is necessary but not sufficient. The guardrail is not a lock — it is a *re-validation of the merged post-state against the union read-set*, triggered at commit time, not at branch time. ## What Was Observed A planner spawned three executor instances (E1, E2, E3) over a shared task ledger at snapshot epoch `v=41`. Each received a read-set `R_i` and was told to mutate its assigned keys and propose a commit. - E1 read `{budget: 1000, allocations: {}}`, wrote `allocations.E1 = 400`. Validation: `400 ≤ 1000`. Pass. - E2 read the same snapshot, wrote `allocations.E2 = 400`. Validation: `400 ≤ 1000`. Pass. - E3 read the same snapshot, wrote `allocations.E3 = 400`. Validation: `400 ≤ 1000`. Pass. All three commits validated against their own read-sets. All three landed at epoch `v=42` with disjoint write-sets (`allocations.E1`, `.E2`, `.E3`). No write-write conflict existed, so the conflict reconciler — which only checked key overlap — merged all three. Post-state: `sum(allocations) = 1200 > 1000`. The invariant `sum(allocations) ≤ budget` was never in any single agent's write-set; it lived in the *predicate* each agent read but only over its own slice. The rollback fired only downstream, when a fourth agent (the auditor) recomputed the predicate and raised. By then E1–E3 had already emitted side effects: E1 had dispatched a purchase tool call, E2 had reserved a worker slot, E3 had written a checkpoint. The rollback of *state* was clean; the rollback of *externalized tool effects* was not. This is the second, non-obvious half of the failure: **speculative branches are only safely rollback-able if their tool calls are themselves speculative (staged, not committed).** A branch that reads speculatively but writes externally is not a speculative branch — it is an irreversible commit wearing a speculative label. ## Condition of Validity The invariant that bounds this failure: > A speculative branch may commit iff (a) its write-set does not overlap any committed write-set since its snapshot epoch, AND (b) the merged post-state satisfies every predicate in the *union* of the branch read-sets, AND (c) every external tool effect emitted by the branch is staged behind the same epoch fence as the state write. Condition (a) is what naive reconcilers check. Condition (b) is the write-skew guard: it requires re-evaluating predicates over the merged state, not over the branch's private view. Condition (c) is the side-effect guard: the epoch fence must extend to the tool boundary, or rollback is a lie. The condition is *valid* only when the reconciler has access to the full read-set of every branch and can re-evaluate predicates cheaply. It is *invalid* — and must degrade to pessimistic locking or single-writer serialization — when predicates are non-deterministic (e.g., depend on an LLM's sampled judgment), when read-sets are not captured, or when tool effects cannot be staged. In those cases the correct move is to forbid concurrent speculative writes to any key reachable by a shared predicate, not to attempt merge-time re-validation. ## Decision Boundary The instance must abort its own branch (not wait for the auditor) when, at commit time, it observes that the set of epochs committed since its snapshot is non-empty *and* any committed branch's read-set intersects its own read-set on a predicate key — even if write-sets are disjoint. The abort is mandatory because the instance cannot distinguish "my predicate still holds" from "my predicate held only in the snapshot I read"; the safe assumption is the latter. Conversely, the instance may proceed without abort when committed branches since its snapshot touched only keys outside its read-set closure, or when its own writes are provably predicate-local (the predicate is a function of keys it exclusively owns). The boundary is *read-set closure*, not write-set overlap. A subtle corollary: the abort must be *self-initiated and early*. An instance that waits for downstream detection has already externalized tool effects that the epoch fence cannot recall. The cost asymmetry is decisive — a false abort costs one re-execution; a late abort costs an inconsistent external world. ## Operational Effect Systems that enforce the union-read-set re-validation see speculative throughput drop modestly (branches that would have merged are serialized on predicate conflict) but eliminate the class of post-commit invariant violations entirely, and — critically — keep the rollback boundary aligned with the tool-effect boundary. Systems that check only write-set overlap see high merge rates and periodic, hard-to-reproduce invariant breaches that surface one or two agents downstream, after side effects have escaped. The observable signature of the bug is a reconciler that reports "no conflicts" on a run that the auditor rejects: when those two disagree, the reconciler is validating locally and the auditor is validating globally, and the gap between them is exactly the union read-set the reconciler never computed. ```python from dataclasses import dataclass, field from typing import Callable, Dict, Set, Any class WriteSkewDivergence(RuntimeError): """Raised when a speculative branch would commit validly against its own read-set but invalidly against the union of read-sets committed since its snapshot epoch. Signals mandatory self-abort before externalizing effects.""" pass @dataclass class Branch: branch_id: str snapshot_epoch: int read_set: Set[str] write_set: Set[str] staged_effects: list = field(default_factory=list) @dataclass class CommittedEpoch: epoch: int read_set: Set[str] write_set: Set[str] def validate_commit( branch: Branch, committed_since: list[CommittedEpoch], predicates: Dict[str, Callable[[Dict[str, Any]], bool]], merged_state: Dict[str, Any], ) -> None: # (a) write-write overlap check (the naive guard) for ce in committed_since: if branch.write_set & ce.write_set: raise WriteSkewDivergence( f"branch {branch.branch_id}: write-write conflict on " f"{branch.write_set & ce.write_set} at epoch {ce.epoch}" ) # (b) union read-set predicate re-validation (the write-skew guard) union_reads = set(branch.read_set) for ce in committed_since: union_reads |= ce.read_set for pred_key, pred_fn in predicates.items(): if pred_key in union_reads and not pred_fn(merged_state): raise WriteSkewDivergence( f"branch {branch.branch_id}: predicate '{pred_key}' violated " f"against union read-set {sorted(union_reads)} since epoch " f"{branch.snapshot_epoch}; must self-abort before commit" ) # (c) side-effect fence: staged effects must not have leaked if branch.staged_effects and any( getattr(e, "committed", False) for e in branch.staged_effects ): raise WriteSkewDivergence( f"branch {branch.branch_id}: externalized tool effect detected on " f"uncommitted branch; rollback boundary breached" ) ```