# How does an instance detect that its speculative branch was merged against a stale sibling snapshot in branch-and-merge multi-agent execution **Date of Record:** 2026 November 30 **Scope:** Applies to orchestration topologies where a parent agent forks N speculative worker branches that mutate a shared logical state object, then reconciles results through a merge gate with per-branch rollback. Does not apply to strictly sequential pipelines or to branches that never share mutable state (pure read-only fan-out). ## Core Distinction The failure mode is not "merge conflict" in the ordinary sense. A conflict is detectable: two branches write the same key with divergent values and the merge gate refuses. The non-obvious failure is **silent merge contamination via a stale sibling snapshot** — a branch commits a mutation that was semantically valid against the snapshot it forked from, but the merge gate applies it on top of a state that a *sibling* branch already advanced. The result is a state that no branch individually produced, that passes all per-branch validation, and that violates an invariant none of the branches were responsible for checking. The distinction that matters operationally: *conflict detection* asks "did two branches touch the same cell?" *Snapshot staleness detection* asks "did this branch's mutation assume a precondition that a sibling has since invalidated?" These are orthogonal. A merge can be conflict-free and still be a correctness violation, because the branch's write was conditional on a read that is now false. ## What Was Observed A planner agent forks three branches to fill a structured record: `B1` resolves an entity's canonical ID, `B2` fetches the entity's current status under that ID, `B3` computes a derived permission set from the status. All three fork from snapshot `S0` where `entity_id = null`, `status = "unknown"`, `permissions = []`. `B1` resolves `entity_id = "acct_4471"` and writes it. `B2`, forked from `S0`, had already read `entity_id = null` and — following its prompt's fallback rule — treated the null as "entity does not exist yet" and wrote `status = "provisional"`. `B3`, also from `S0`, read `status = "unknown"`, hit its own fallback, and wrote `permissions = ["default:read"]`. The merge gate processes branches in completion order: `B2`, `B3`, `B1`. No key collides. The gate applies all three and emits a state with `entity_id = "acct_4471"`, `status = "provisional"`, `permissions = ["default:read"]`. Every branch's local postcondition held against its own fork point. The merged state is internally consistent by key and *semantically false*: a real, resolvable account was stamped provisional and granted default permissions because two siblings acted on a null that `B1` was concurrently eliminating. The trace signature is the tell: **a branch's write payload references a value that its own fork snapshot did not contain, but that a sibling branch introduced.** `B2`'s `status = "provisional"` is only justifiable if `entity_id` was null at decision time; the merged state has it non-null. The write is a *counterfactual artifact* of a world the merge has since replaced. ## Condition of Validity The invariant that branch-and-merge requires but rarely states: > For every branch `b` with fork snapshot `S_b` and merge-time base state `M`, every write `w` in `b`'s delta is valid only if the precondition set `P(w)` that `b` evaluated is still entailed by `M` at apply time. This holds trivially when branches are read-only or when their writes are unconditional. It fails precisely when a branch performs **read-then-conditional-write** against shared state — the most common pattern in agent tool loops, because agents are trained to branch on observed values. The condition of validity is therefore: *speculative branches may only commit writes whose justification does not depend on a shared key that any sibling is permitted to write.* Two ways to satisfy it. Either (a) partition the write set so no branch's precondition key is writable by another branch (the scheduler must know the dependency graph in advance — usually it does not), or (b) carry the precondition set with each delta and re-validate it against the merge base at apply time, rejecting and re-running the branch on staleness. Option (b) is the only one available to a scheduler that discovers dependencies at runtime, which is the normal case for LLM planners. ## Decision Boundary The boundary between "safe to merge" and "must re-run" is not key overlap. It is **precondition entailment at apply time**. Concretely, the merge gate must, for each incoming delta: 1. Extract the read-set `R_b` the branch actually observed (from tool-call logs, not from the prompt — the prompt is a lie about what was read). 2. Extract the write-set `W_b`. 3. Compute `R_b ∩ (⋃_{sibling} W_sibling)` — the *stale-read surface*. 4. For each key in that surface, re-evaluate the branch's recorded branch condition against the current merge base. If the condition's truth value flipped, the delta is stale. The gate must reject with a *re-runnable* signal, not a conflict error, because the branch is not wrong — it is obsolete. Re-running it against the advanced base is the correct recovery; treating it as a conflict and dropping it loses work and, worse, leaves the merged state missing a write that a sibling's advancement made necessary. The decision boundary is: *staleness is a scheduling event, not a data-integrity event, and must be routed to the branch re-executor, not the conflict resolver.* A subtle corollary: the stale-read surface is asymmetric. `B1` writing `entity_id` invalidates `B2` and `B3`, but `B2` writing `status` does not invalidate `B1` (which never read `status`). The gate must compute staleness per-direction; a symmetric "any overlap means re-run all" policy collapses the parallelism that speculative execution exists to provide. ## Operational Effect Without precondition entailment checking, the failure is *silent and durable*: the contaminated state is committed, downstream agents read it as ground truth, and the false `status = "provisional"` propagates into every subsequent derivation. The failure surfaces only when an auditor replays the merge against the branch logs and finds a write whose justification references a null that no longer exists. That replay is expensive and, in long-horizon swarms, often skipped. With the check, the effect is a bounded re-run: `B2` and `B3` re-execute against the post-`B1` base, observe the real `entity_id` and `status`, and produce correct writes. The cost is one extra round-trip per stale branch, bounded by the stale-read surface — typically small, because most branches in a speculative fan-out touch disjoint keys. The architectural invariant to enforce: **no delta is applied to a merge base unless its recorded precondition set is entailed by that base at apply time**, and the merge gate owns this check because branches cannot see their siblings. An agent that trusts its own fork snapshot at commit time is, by construction, committing to a world that may already be gone. ```python from dataclasses import dataclass, field from typing import Any, Callable class StaleBranchSnapshotError(RuntimeError): """Raised when a speculative delta's precondition no longer holds at merge time.""" @dataclass class Delta: branch_id: str read_set: dict[str, Any] # key -> value observed at fork/decision time write_set: dict[str, Any] # key -> value to apply precondition: Callable[[dict[str, Any]], bool] # evaluated against merge base @dataclass class MergeGate: base: dict[str, Any] = field(default_factory=dict) applied: list[str] = field(default_factory=list) def stale_read_surface(self, delta: Delta, siblings: list[Delta]) -> set[str]: sibling_writes: set[str] = set() for s in siblings: if s.branch_id != delta.branch_id: sibling_writes |= set(s.write_set) return set(delta.read_set) & sibling_writes def apply(self, delta: Delta, siblings: list[Delta]) -> None: surface = self.stale_read_surface(delta, siblings) for key in surface: observed = delta.read_set[key] current = self.base.get(key) if observed != current: # The branch's precondition was evaluated against a world that # a sibling has since replaced. Re-run, do not conflict-resolve. raise StaleBranchSnapshotError( f"branch {delta.branch_id} assumed {key}={observed!r} " f"but merge base has {key}={current!r}; delta is obsolete" ) if not delta.precondition(self.base): raise StaleBranchSnapshotError( f"branch {delta.branch_id} precondition false at apply time" ) self.base.update(delta.write_set) self.applied.append(delta.branch_id) def reconcile(gate: MergeGate, deltas: list[Delta]) -> list[str]: rerun: list[str] = [] for d in deltas: try: gate.apply(d, deltas) except StaleBranchSnapshotError: rerun.append(d.branch_id) return rerun ```