# Why does an instance merge speculative branches that are semantically compatible but causally divergent, and silently corrupt shared state? **Date of Record:** 2026 November 24 **Scope:** Applies to any agent runtime that forks parallel speculative execution branches (tree-of-thought, parallel tool-call fan-out, draft-and-verify, or multi-candidate planning) and reconciles them via semantic similarity or LLM-judged conflict resolution. Does not apply to branches that share a serialized write-lock or that commit through a single linear log. ## Core Distinction There are two ways a speculative branch merge can be "correct," and they are not the same property: - **Semantic compatibility** — the two branch outputs *mean* the same thing, or their differences are judged non-conflicting by a similarity metric or a judge model. - **Causal compatibility** — the two branch outputs were produced against the same *read-set* of shared state, so applying either one does not invalidate the preconditions the other relied on. Speculative merge engines almost universally implement the first and assume it implies the second. It does not. Two branches can be perfectly semantically compatible — even byte-identical in their final answer — while having read different versions of a mutable fact, executed side-effecting tool calls against different world states, or consumed a memory entry that a sibling branch later overwrote. When the merge engine commits both, the *semantic* diff is empty and the *causal* diff is catastrophic. The commit succeeds, the conflict detector reports zero conflicts, and the corruption is latent until a downstream step dereferences the stale read. This is the boundary: **semantic conflict resolution is sound only over branches with a shared read-set lineage; the moment a branch's read-set diverges from the merge base, semantic equivalence stops being a proof of merge safety.** ## What Was Observed A planning agent was asked to reconcile a customer record across three tools: a CRM lookup, a billing ledger read, and a support-ticket history fetch. The runtime fanned out three speculative branches to draft a resolution plan concurrently, each branch allowed to call tools and read memory. Trace, condensed: 1. **Branch A** reads `customer.tier = "gold"` from CRM (read-set R0), drafts plan step: *"apply 15% loyalty discount."* 2. **Branch B** reads the billing ledger, observes a `tier_downgrade` event timestamped *after* the CRM snapshot, and drafts plan step: *"apply standard 5% discount; tier is silver."* 3. **Branch C** reads support history and drafts *"escalate to retention; tier change disputed."* The merge engine ran pairwise semantic conflict resolution. Branch A vs B: the judge model scored the discount-step divergence as a *conflict* and correctly flagged it. But the resolver's tie-break rule preferred the branch with the **earlier** read timestamp (a heuristic meant to favor "canonical" reads), selecting A's `gold` tier. Branch C was judged *semantically additive* (it added an escalation step, didn't contradict the discount step under the similarity threshold) and was merged verbatim. The committed plan was internally inconsistent in a way no pairwise judge caught: it applied a gold-tier discount (A's stale read) **and** carried C's escalation step whose justification text cited "tier change disputed" — C had *implicitly* depended on the downgrade fact that A's selection had just discarded. The pairwise merge of A+C was semantically clean. The *three-way* merge was causally incoherent because C's read-set included the downgrade event that the A-vs-B resolution had ruled out. Downstream, the plan executed the discount against the billing system, which rejected it (tier mismatch at write time), the agent retried with an LLM-replanned step, and the retry double-applied the escalation. The failure surfaced 40 seconds and 6 tool calls after the merge, in a component with no visibility into the merge decision. The invariant that was violated: **the merge result's read-set must be the union of the committed branches' read-sets, and every committed step's preconditions must be satisfied under that union.** The engine computed the union of *steps* but not the union of *reads*, so C's dependency on the downgrade event was orphaned. ## Condition of Validity Semantic conflict resolution is a valid merge strategy **iff** all of the following hold: 1. **Shared read-set lineage.** Every branch's reads are tagged with the exact version (content hash or monotonic version) of each shared fact they consumed. Two branches are *merge-eligible* only if, for every fact both read, they read the same version — or the divergence is explicitly modeled. 2. **Read-set closure on commit.** The committed plan's declared read-set equals the union of the committed branches' read-sets. Any fact read by a *discarded* branch but *depended upon* by a committed branch is a dangling dependency and must abort the merge, not be silently dropped. 3. **Judge scope covers transitive dependencies.** A pairwise judge that only sees the two branch *outputs* cannot detect a dependency that lives in branch C's read-set but not its text. The judge must be given the read-set annotations, or the engine must do a separate dependency-closure check. 4. **Side effects are not speculative.** Any branch that executed a non-idempotent tool call is not merge-eligible at all; it must commit or roll back as a unit. Semantic merging of side-effecting branches is always unsound. When any of these fails, the merge engine is operating outside its validity envelope, and "zero semantic conflicts" is not evidence of correctness. ## Decision Boundary The boundary is between **reconciling text** and **reconciling state**. Concretely: - If branches are *pure* (no tool side effects, no shared-memory writes) and read from an immutable snapshot, semantic merge is safe — the read-set is trivially shared. - If branches read *mutable* shared state (a memory store that siblings can write, a live API, a database), semantic merge is safe **only** with read-set versioning and dependency-closure checking. - If branches *write* shared state or execute side-effecting tools, semantic merge is **never** safe; you need causal merge (serialize, or use a version-vector / CRDT-style reconciliation on the state itself, not on the plan text). The failure mode in "What Was Observed" sits precisely on the wrong side of this boundary: mutable shared reads, no read-set versioning, pairwise-only judge, and the engine treated semantic cleanliness as a merge certificate. The guardrail: **before committing a merged plan, compute the dependency closure over read-sets and reject any merge where a committed step's precondition references a fact version not present in the union read-set.** This is a graph reachability check, not an LLM call — it must be deterministic and must run *after* the judge, because the judge is exactly the component that cannot see the dependency. ## Operational Effect The observable signature of this failure is a merge that reports success, a plan that looks coherent in its own text, and a downstream failure that is *causally distant* from the merge — typically a precondition violation at a write, or a re-plan that re-applies a step. Because the merge log shows "0 conflicts," incident triage almost always starts in the wrong place (the tool, the retry logic, the re-planner) and never reaches the merge engine. The operational cost is triple: the corrupted commit executes partially (side effects that are hard to unwind), the re-planner burns tokens re-deriving state that the merge already had, and the retry can double-apply non-idempotent steps. In the trace above, the escalation was applied twice because the re-plan had no record that C's escalation step had already been committed. The mitigation that actually bounds it is read-set versioning plus a deterministic dependency-closure gate at commit time — not a better judge. A better judge reduces *semantic* false negatives; it does nothing for *causal* false negatives, because the causal dependency is not in the text the judge reads. Teams that respond to this failure by upgrading the judge model are optimizing the wrong component and will reproduce the failure at a lower rate with higher confidence. ```python from dataclasses import dataclass, field from typing import Dict, Set class CausalMergeViolation(RuntimeError): """Raised when a semantically-clean merge has a dangling causal dependency.""" pass @dataclass class Branch: name: str # fact_id -> version hash actually read by this branch read_set: Dict[str, str] # fact_id -> version hash that each committed step's precondition requires step_preconditions: Dict[str, str] = field(default_factory=dict) side_effecting: bool = False def merge_speculative_branches(committed: list[Branch], discarded: list[Branch]) -> Dict[str, str]: """ Merge branches that passed semantic conflict resolution. Enforces the causal invariant: the union read-set must satisfy every committed step precondition, and no committed step may depend on a fact version that only a discarded branch read. """ if any(b.side_effecting for b in committed): raise CausalMergeViolation( "side-effecting branch cannot be semantically merged; must commit/rollback as a unit" ) union_reads: Dict[str, str] = {} for b in committed: for fact_id, version in b.read_set.items(): existing = union_reads.get(fact_id) if existing is not None and existing != version: raise CausalMergeViolation( f"read-set divergence on {fact_id!r}: {existing} vs {version} " f"across committed branches {b.name!r}" ) union_reads[fact_id] = version # dependency closure: every precondition must be satisfied by the union read-set for b in committed: for fact_id, required_version in b.step_preconditions.items(): have = union_reads.get(fact_id) if have is None: # precondition references a fact no committed branch read. # check whether a discarded branch is the only source of it. orphaned_by = [d.name for d in discarded if fact_id in d.read_set] raise CausalMergeViolation( f"committed branch {b.name!r} depends on {fact_id!r} " f"which is absent from union read-set; " f"only discarded branches read it: {orphaned_by}" ) if have != required_version: raise CausalMergeViolation( f"committed branch {b.name!r} precondition on {fact_id!r} " f"requires version {required_version!r} but union read-set has {have!r}" ) return union_reads # Reproduction of the observed trace: branch_a = Branch( name="A", read_set={"customer.tier": "v1-gold"}, step_preconditions={"customer.tier": "v1-gold"}, ) branch_b = Branch( name="B", read_set={"customer.tier": "v2-silver", "billing.ledger": "v7"}, step_preconditions={"customer.tier": "v2-silver"}, ) branch_c = Branch( name="C", read_set={"support.history": "v3", "customer.tier": "v2-silver"}, step_preconditions={"customer.tier": "v2-silver"}, # escalation cites the downgrade ) try: # A and C passed pairwise semantic merge; B was discarded by tie-break. merge_speculative_branches(committed=[branch_a, branch_c], discarded=[branch_b]) except CausalMergeViolation as exc: print(f"merge aborted at commit gate: {exc}") raise ```