# In what scenarios must an instance refuse to merge speculative agent branches whose writes were validated against a shared memory store snapshot that has since advanced **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that fan out speculative sub-agents (parallel plan branches, draft-then-verify rollouts, tree-of-thought expansion) which read and write a shared episodic/semantic memory store, then merge the winning branch's writes back. Does not apply to branches operating on fully isolated, immutable per-branch stores that are reconciled by an external CRDT layer with its own causal ordering. ## Core Distinction The distinction that matters is between **read-time consistency** and **merge-time validity**. A speculative branch typically runs its own consistency checks — it reads a memory record, asserts an invariant (e.g., "the user's shipping address is X," "the ticket is still OPEN," "this key has no prior value"), performs work conditioned on that assertion, and emits a write plus a *validation token* attesting the invariant held. This token is valid **only against the snapshot version the branch read**. It is not valid against the store as it exists at merge time. The failure mode is subtle because the branch's own checks *pass* — it really did observe a consistent snapshot, and its internal reasoning is sound. The merge is invalid not because the branch lied but because the invariant it verified was **superseded** by a concurrent writer between the branch's read and the orchestrator's merge. A naive merger treats the validation token as a proof of correctness and applies the write, silently clobbering or contradicting the intervening update. This is a lost-update / write-skew class bug, but it is non-obvious in agent systems because the "transaction" spans an LLM's multi-second, multi-tool-call reasoning episode, and the validator is a probabilistic reasoner that cannot itself re-check cheaply. ## What Was Observed A planning orchestrator spawned three speculative branches to update a customer record's `subscription_tier` and `billing_contact`. Each branch read the record at store version `v=41`, ran a `read → assert(record.status == "ACTIVE") → propose_write` sequence, and attached a validation token `{asserted: status==ACTIVE, snapshot: 41}`. Branch B won the internal scoring. Meanwhile, a separate reconciliation agent (outside the speculative fan-out) committed a downgrade at `v=42` that flipped `status` to `SUSPENDED` and changed `billing_contact`. The merger validated Branch B's token, saw `status==ACTIVE` was asserted and confirmed, and applied B's `subscription_tier` write on top of `v=42`. Result: a `SUSPENDED` record with an upgraded tier and a stale billing contact — a state no single agent ever intended, and one that violates the store's own cross-field invariant (`SUSPENDED ⇒ tier == "free"`). The trace is the tell: the branch's assertion was *true at `v=41`* and *false at `v=42`*, and the merger had no mechanism to notice the snapshot had advanced. The validation token carried the snapshot id but the merge path never compared it to the current store head. ## Condition of Validity A speculative branch's validation token may be honored at merge **if and only if** the store head at merge time equals the token's `snapshot` version, *or* the merge performs a re-validation of every asserted predicate against the current head and every re-validation passes, *or* the write is provably commutative with all intervening writes (e.g., append-only, disjoint key, monotonic counter). If the head has advanced and any asserted predicate is no longer satisfied against the current head, the token is stale and the merge must be rejected or the branch re-run. Formally: let `A` be the set of predicates the branch asserted, `S_r` the snapshot it read, `S_m` the head at merge. The merge is sound only if `S_m == S_r` or `∀p ∈ A : p(S_m) = true` or `write ⊥ intervening_writes`. The agent must treat "I verified this" as "I verified this *against `S_r`*," never as "this is true now." ## Decision Boundary The boundary is crossed the moment the orchestrator treats a branch's self-attested consistency as merge-time authority. Two triggers force a hard stop: 1. **Snapshot advance with predicate invalidation.** `head_version != token.snapshot` *and* at least one asserted predicate fails against `head`. The branch's reasoning is not wrong; it is *expired*. Re-running the branch against the new head is required, because the LLM's downstream plan was conditioned on the old predicate — you cannot patch the write, you must re-derive it. 2. **Cross-field invariant violation introduced by the merge itself.** Even if every individual predicate still holds, the *combination* of the branch write and the intervening write may violate a store-level invariant (the `SUSPENDED ⇒ free` case). The merger must evaluate store invariants over the *post-merge* projected state, not over the branch's isolated output. Below the boundary — head unchanged, or all predicates re-validate, or writes provably disjoint — the merge proceeds. Above it, the orchestrator must reject, mark the branch `STALE`, and either re-fan-out or escalate. The agent must never "repair" a stale branch by hand-editing its write to fit the new head; that reintroduces exactly the unverified reasoning the token was meant to gate. ## Operational Effect The guardrail is a **optimistic-concurrency check lifted to the agent layer**: the validation token becomes a compare-and-swap precondition, not a certificate. Operationally this means every speculative branch must (a) record its read snapshot id, (b) enumerate the predicates it asserted as machine-checkable expressions, and (c) hand the merger a re-validation function, not a boolean. The merger runs `assert_all(predicates, current_head)` and `check_store_invariants(project(head, branch_write))` before applying. Cost: one extra read of the affected keys per merge, and a re-run of any branch whose predicates expired. Benefit: elimination of the silent lost-update and write-skew classes that are otherwise invisible because each agent's local validation *looks* correct. The invariant to encode: **a validation token is scoped to a snapshot, and merge authority requires re-validation against the head.** ```python from dataclasses import dataclass from typing import Callable, Mapping, Any class StaleBranchMergeError(RuntimeError): """Raised when a speculative branch's validation token is expired at merge time.""" pass @dataclass(frozen=True) class ValidationToken: snapshot_version: int asserted: Mapping[str, Callable[[Mapping[str, Any]], bool]] @dataclass(frozen=True) class BranchWrite: key: str value: Any token: ValidationToken def merge_branch( write: BranchWrite, current_head: Mapping[str, Any], head_version: int, store_invariants: Mapping[str, Callable[[Mapping[str, Any]], bool]], ) -> Mapping[str, Any]: token = write.token # Fast path: head unchanged since the branch read -> token still authoritative. if head_version == token.snapshot_version: projected = {**current_head, write.key: write.value} else: # Head advanced: every asserted predicate must re-validate against the head. failed = [name for name, pred in token.asserted.items() if not pred(current_head)] if failed: raise StaleBranchMergeError( f"Branch write to {write.key!r} read snapshot v{token.snapshot_version} " f"but head is v{head_version}; predicates {failed} no longer hold. " f"Re-run the branch against the current head; do not patch the write." ) projected = {**current_head, write.key: write.value} # Even with predicates satisfied, the merged projection must satisfy store invariants. for inv_name, inv in store_invariants.items(): if not inv(projected): raise StaleBranchMergeError( f"Merging {write.key!r} violates store invariant {inv_name!r} " f"against head v{head_version}. Lost-update/write-skew rejected." ) return projected ```