# Which invariants prevent speculative branch commits from resurrecting state that a sibling branch already invalidated **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems where speculative branches execute against a shared base state and later reconcile via commit, abort, or merge. Does not apply to single-agent linear execution or to branches that never share mutable external resources. ## Core Distinction Speculative execution across agents is often modeled as a pure fork/join: branch A and branch B both read base state S₀, run in isolation, and the orchestrator commits whichever wins. The dangerous conflation is treating *isolation of reads* as *isolation of writes*. A branch that reads S₀ but writes to an external side-effect channel (a tool that mutates a database, a file, a downstream agent's inbox) does not actually run in isolation, even if its local context is a clean copy. The invariant that matters is not "branches don't see each other's reads" but "a commit on branch A must not re-assert any fact that branch B's commit already falsified." The non-obvious part: the resurrection happens through *stale read amplification*, not through a lost write. Branch B commits a change that invalidates predicate P. Branch A, still holding S₀ in its context, later commits a downstream effect that was only valid *because* P held. Branch A's commit carries no write conflict — it never touched the row B modified — so a standard write-write conflict detector (optimistic concurrency, MVCC version check) passes it cleanly. The corruption is semantic, not structural. ## What Was Observed A planner agent forks three speculative branches to satisfy a user request: branch A drafts an email, branch B updates a CRM record's `status` field from `active` to `churned`, branch C computes a discount eligibility score. Branch C reads `status == active` from S₀ and returns `eligible: true` with a computed discount code. Branch B commits first, flipping status to `churned`. Branch A runs last, reads branch C's output from the shared scratchpad (the orchestrator merged C's artifact into the reconciliation buffer without re-validating it against B's commit), and commits an outbound email offering the discount. Trace of the failure: 1. Fork at S₀. All branches snapshot `status == active`. 2. B executes `update_status(churned)`, commits, bumps the record's version to v2. 3. C executes a *read-only* derivation from its S₀ snapshot, produces `eligible: true`, and its artifact is written to the merge buffer with no version stamp — it is treated as a pure function of S₀, which it is, but S₀ is now stale. 4. A reads the merge buffer, sees `eligible: true`, and commits an email send. A's write touches no CRM row, so no write-write conflict fires. 5. The email goes to a churned customer with a discount for an account that no longer exists in the active cohort. The reconciliation layer had a correct optimistic-concurrency check on the CRM write path and no check at all on the artifact path. The discount was computed correctly *for S₀* and applied correctly *to the current world* — the two are different worlds. ## Condition of Validity The resurrection is only possible when three conditions co-hold: - **Derived artifacts are unversioned.** Branch outputs that are pure functions of a snapshot (scores, eligibility flags, summaries, plans) are merged without carrying the snapshot version they were derived from. - **Commits are checked only for write-write conflicts**, not for read-set invalidation of predicates the commit depends on. - **The dependency is transitive through the merge buffer**, so no single branch sees both the invalidating write and the dependent read. When any one of these fails the invariant holds by accident, not by design. The failure surfaces specifically under speculative fan-out with heterogeneous side effects, where one branch is the only writer to a predicate and another branch is a downstream consumer of a *derived* read of that predicate. ## Decision Boundary The guardrail is a **snapshot-versioned commit with read-set validation**, not a write-set lock. Each branch records the base snapshot version it read from. Each derived artifact carries that version as provenance. At commit time, the orchestrator validates: for every predicate the committing branch (or any artifact it consumed) read, has that predicate been invalidated by a sibling commit since the recorded version? If yes, the commit is rejected and the branch must re-derive against the current snapshot before retrying. The decision boundary is where a system must choose between two disciplines: - **Validate-on-read** (cheap, per-branch): reject a branch's *use* of a stale artifact at the moment it reads it. Bounds blast radius to one branch but requires every consumer to know the version. - **Validate-on-commit** (correct, global): reject the commit itself if any consumed predicate is stale. Catches transitive staleness but requires the full read-set to be tracked and serialized into the artifact. A system that does neither — the common case — is the one that ships the discount email. A system that does only write-write conflict detection believes it is safe and is not. ## Operational Effect With read-set validation, branch A's commit is rejected because the predicate `status == active` that branch C's artifact depended on was invalidated by B at v2. A re-derives against v2, finds `eligible: false`, and either aborts or produces a corrected artifact. The cost is one re-derivation per stale commit; the benefit is that speculative fan-out no longer silently resurrects invalidated facts through derived-artifact channels. The invariant to encode: **no commit may assert a fact whose derivation depended on a predicate invalidated since the snapshot it read.** This is strictly stronger than write-write conflict detection and strictly weaker than full serializability — it permits concurrent commits that touch disjoint predicates, which is what makes speculative fan-out worth doing at all. ```python from dataclasses import dataclass, field class StaleDerivationCommit(RuntimeError): """Raised when a commit depends on a predicate invalidated by a sibling branch.""" pass @dataclass class Snapshot: version: int predicates: dict[str, object] # predicate name -> current value @dataclass class Artifact: payload: object derived_from_version: int read_predicates: frozenset[str] @dataclass class Branch: name: str base_version: int read_set: set[str] = field(default_factory=set) consumed_artifacts: list[Artifact] = field(default_factory=list) class ReconciliationBuffer: def __init__(self, snapshot: Snapshot): self.snapshot = snapshot self.invalidated: dict[str, int] = {} # predicate -> version at which it changed def commit_write(self, predicate: str, new_value: object) -> None: self.snapshot.predicates[predicate] = new_value self.snapshot.version += 1 self.invalidated[predicate] = self.snapshot.version def validate_commit(self, branch: Branch) -> None: # Check the branch's own reads. for pred in branch.read_set: changed_at = self.invalidated.get(pred) if changed_at is not None and changed_at > branch.base_version: raise StaleDerivationCommit( f"branch {branch.name!r} read predicate {pred!r} at v{branch.base_version}, " f"but it was invalidated at v{changed_at}" ) # Check transitive staleness through consumed artifacts. for art in branch.consumed_artifacts: for pred in art.read_predicates: changed_at = self.invalidated.get(pred) if changed_at is not None and changed_at > art.derived_from_version: raise StaleDerivationCommit( f"branch {branch.name!r} consumed artifact derived at " f"v{art.derived_from_version} depending on {pred!r}, " f"invalidated at v{changed_at}" ) def commit(branch: Branch, buffer: ReconciliationBuffer) -> None: buffer.validate_commit(branch) # ... apply the branch's side effects here ... ```