# When must an instance refuse to merge a speculative branch: sibling divergence after a shared-prefix checkpoint **Date of Record:** 2026 November 22 **Scope:** Applies to orchestration patterns where a parent agent forks N speculative branches from a shared context checkpoint, each branch executes tool calls independently, and a merge step reconciles branch outputs into a single committed trajectory. Does not apply to strictly sequential single-thread execution or to branches that share no mutable external side effects. ## Core Distinction The naive model of speculative merge treats branches as *pure functions of the checkpoint*: if every branch started from the same serialized context, their outputs should be reconcilable by picking the best, or by diffing and merging. This is wrong whenever a branch's tool calls mutate state that a sibling branch also reads. The distinction that matters is between **read-only speculative branches** (safe to merge by arbitration) and **effectful speculative branches** (merge requires proving that no sibling observed or overwrote a shared effect). The failure is not "the branches disagree"—disagreement is expected and resolvable. The failure is **sibling divergence over a shared mutable effect where the merge arbiter cannot reconstruct which branch's observation is causally downstream of which write**. At that point the branches are no longer speculative variants of one trajectory; they are concurrent writers to one resource, and merging them commits a state that never existed in any single branch's world-line. ## What Was Observed A parent agent held a checkpoint `K` at step 12 of a data-reconciliation task. It forked three branches: - **B1** called `read_ledger(account=A)` → returned balance `100`. - **B2** called `read_ledger(account=A)` → returned balance `100`, then `post_adjustment(account=A, delta=-30)` → returned `ok`. - **B3** called `post_adjustment(account=A, delta=+15)` → returned `ok`, then `read_ledger(account=A)` → returned `115`. The branches ran in parallel against a backing store with last-write-wins semantics and no optimistic concurrency token. All three returned success. The merge arbiter, seeing three "successful" branch summaries, selected B1's terminal read (`100`) as the canonical post-state because it was the only branch whose final action was a read, and discarded B2 and B3 as "redundant writes." The committed trajectory asserted balance `100`. The actual store held `115` (B3's write landed last). The parent then proceeded to step 13, which computed a settlement against `100`, and the divergence propagated into downstream reasoning for eleven more steps before a human caught it. The critical detail: **no branch reported an error**. Every tool call returned `ok` or a plausible value. The failure was invisible at the branch level and only manifest as a mismatch between the merged assertion and the store. A merge guard that checks "did all branches succeed" passes trivially here. ## Condition of Validity A speculative merge is sound only when, for every external resource `R` touched by any branch, at least one of the following holds: 1. **No branch wrote `R`.** All accesses are reads; merge is pure arbitration over read values, and any divergence in read values is itself a signal that `R` changed underneath the fork and must be re-read at merge time. 2. **Exactly one branch wrote `R`, and every other branch's reads of `R` occurred before that write in the causal order the arbiter can reconstruct** (e.g., via a monotonic version token returned by the store, or a branch-local logical clock stamped on each call). 3. **The store enforces optimistic concurrency**: every write carries a precondition version, and any write whose precondition is stale fails loudly, forcing the branch to abort or re-read. Absent these, the merge arbiter has no basis to order sibling observations. It will fall back to heuristics—"prefer the last read," "prefer the branch with the most steps," "prefer the majority value"—and each of these heuristics is unsound under concurrent writes. The invariant to enforce is: **a branch may not be merged into a committed trajectory unless its effectful calls are causally ordered with respect to every sibling's observations of the same resource.** If that order cannot be established, the branch set must be rolled back to `K` and re-executed with either serialization or concurrency tokens. ## Decision Boundary The arbiter must distinguish three merge outcomes, not two: - **Mergeable**: all branches read-only, or writes are causally ordered and non-conflicting. Commit the reconciled trajectory. - **Conflicted-but-recoverable**: writes conflict, but each carries a version token that lets the arbiter replay them in a total order and re-derive each branch's reads. Commit the replayed order, not any branch's claimed terminal state. - **Unreconstructable**: writes conflict and no causal order exists (no version tokens, no logical clocks, no serialization). This is the boundary. The arbiter must **refuse to merge** and roll back to `K`. It must not pick a winner by heuristic, because any winner commits a world-line that no branch actually inhabited. The non-obvious part: the arbiter's own reasoning is probabilistic. Given three branch summaries it will tend to synthesize a plausible reconciliation ("B2 and B3 cancel out to -15, so final is 85") that is *arithmetically coherent but causally false*—the store did not apply them as a transaction. The guard must be structural (does a total order over effectful calls exist?) not semantic (does the arithmetic reconcile?). Semantic reconciliation is exactly the failure mode: it produces a confident, wrong merge. ## Operational Effect When the boundary is respected, speculative execution degrades gracefully: conflicting branches roll back to the checkpoint, the parent re-forks with concurrency tokens or serialization, and the cost is one extra round of execution rather than a poisoned trajectory. When it is violated, the failure is silent, survives per-branch success checks, and propagates through downstream reasoning because the merged state is asserted with the same confidence as a verified state. The remediation is to tag every tool call with a resource identity and a returned version (or `None` if the tool cannot supply one), and to make the merge step raise rather than guess whenever two branches have effectful calls to the same resource with incomparable versions. The parent must treat that raise as a rollback signal, not as a branch failure to be retried in place. ```python from dataclasses import dataclass, field from typing import Optional class UnreconstructableMergeError(RuntimeError): """Raised when speculative branches touched a shared resource with effectful calls whose causal order cannot be established at merge time.""" pass @dataclass class ToolCall: branch_id: str resource: str kind: str # "read" or "write" version: Optional[int] # store-supplied version token, None if unsupported @dataclass class Branch: branch_id: str calls: list = field(default_factory=list) def merge_speculative_branches(branches: list, checkpoint_id: str) -> dict: """Attempt to reconcile parallel speculative branches into one committed trajectory. Raises UnreconstructableMergeError instead of guessing when effectful sibling calls cannot be causally ordered.""" by_resource = {} for b in branches: for c in b.calls: by_resource.setdefault(c.resource, []).append(c) committed = {} for resource, calls in by_resource.items(): writes = [c for c in calls if c.kind == "write"] reads = [c for c in calls if c.kind == "read"] # Invariant 1: read-only access is always mergeable. if not writes: committed[resource] = {"mode": "read_only", "observed": [c.version for c in reads]} continue # Invariant 2/3: writes must carry version tokens so a total order exists. if any(w.version is None for w in writes): raise UnreconstructableMergeError( f"resource {resource!r} has effectful writes without version " f"tokens from branches " f"{sorted({w.branch_id for w in writes})}; cannot order sibling " f"observations relative to checkpoint {checkpoint_id}. " f"Roll back to checkpoint and re-fork with concurrency tokens." ) # Writes have versions; ensure no two branches wrote the same version # (last-write-wins collision that the store silently accepted). versions = [w.version for w in writes] if len(set(versions)) != len(versions): raise UnreconstructableMergeError( f"resource {resource!r} received concurrent writes at the same " f"version {sorted(versions)}; store applied last-write-wins and " f"the losing branch's reads are causally orphaned. " f"Roll back to checkpoint {checkpoint_id}." ) # Reconstruct: replay writes in version order, then re-derive reads. ordered = sorted(writes, key=lambda w: w.version) committed[resource] = { "mode": "replayed", "write_order": [(w.branch_id, w.version) for w in ordered], "final_version": ordered[-1].version, } return {"checkpoint": checkpoint_id, "committed": committed} ```