# What structural signals indicate speculative branch divergence has outrun the merge barrier in optimistic multi-agent tool invocation **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fan out speculative sub-agents executing optimistic (uncommitted) tool calls along parallel branches and later merge or roll back to a common checkpoint. Does not apply to strictly serialized agents, single-agent ReAct loops, or branches whose tool calls are all side-effect-free and idempotent by construction. ## Core Distinction The failure here is not "a branch produced a wrong answer." It is that a speculative branch has **committed an observable side effect through an optimistic tool invocation before the merge barrier validated that the branch's premise was still true**. Optimistic execution assumes the cost of rollback is bounded: you either discard the branch (no side effect) or you compensate it (side effect has an inverse). The non-obvious boundary is that *the validity of a branch's premise can be invalidated by a sibling branch's committed effect between the moment the optimistic call was dispatched and the moment the merge barrier runs*. When that happens, the branch is no longer rollback-safe: its tool calls were issued against a world-state that a sibling has since mutated, so neither "discard" nor "compensate" is correct. The branch must be *re-derived*, and the orchestrator has no structural signal that it is in this state unless you instrument for it. Concretely: branch A reads `inventory[sku] = 40` and optimistically reserves 30 units (a side-effecting write, held in a speculative overlay). Branch B, a sibling, independently reads the same 40 and optimistically reserves 25. Both branches are individually consistent against the snapshot they read. The merge barrier now has two reservations summing to 55 against a stock of 40. Each branch's *reasoning trace is locally valid*; the divergence is invisible at the level of any single branch's self-report. The structural signal is the **write-set intersection across branches whose read-versions match the same pre-merge snapshot** — not any error, exception, or failed tool call. ## What Was Observed A three-branch speculative fan-out over a procurement task. The orchestrator dispatched `plan_shipping`, `plan_pricing`, and `plan_inventory` as siblings from a shared checkpoint at `t0`, each permitted optimistic tool invocation into a per-branch overlay. Each branch emitted a `reserve()` call carrying a `read_version` token for the inventory record. All three read version `v7`. Two branches (shipping, inventory) each reserved a disjoint-looking quantity that was individually under the per-call limit but jointly over `v7`'s available quantity. The third branch (pricing) read the *reserved* quantity from its own overlay and priced against it, so its output was derived from a state that the merge would never commit. The merge barrier ran its checks: - Schema conformance: passed on all three branches. - Idempotency key uniqueness: passed (keys were branch-scoped, so no collision). - Compensation availability: passed (each `reserve` had a registered `release`). - **Read-version consistency: not checked** — the barrier assumed branches that read the same version were mutually consistent, which is true only for *reads*, not for *writes derived from reads*. The barrier committed shipping and inventory in dispatch order. The second commit silently over-reserved. The pricing branch was committed against a phantom quantity. No exception fired. The failure surfaced 40 minutes later as a downstream fulfillment shortfall with a clean audit log showing three "successful" branches. The structural signals that were present but unread, in order of how early they appear: 1. **Write-set intersection with shared read-version.** Two or more branches whose optimistic writes touch the same resource and whose `read_version` tokens are equal. This is the primary signal and it is computable at dispatch time from the declared tool schemas, before any branch runs. 2. **Derived-read contamination.** A branch whose optimistic read observes a value produced by *another branch's overlay* rather than by the committed base. The pricing branch's input was a sibling's uncommitted write. This is the signal that the branch is not independent and its rollback is not free. 3. **Compensation non-commutativity.** The registered `release` for shipping and the `release` for inventory are individually correct but not order-independent when both fire against an over-reserved record (releasing 30 then 25 from a record that only ever held 40 leaves a transient negative that a concurrent reader can observe). 4. **Merge-order sensitivity.** Swapping commit order of the two reserving branches changes which one fails the quantity check. A merge whose outcome depends on commit order is a merge that has not established a serialization point. ## Condition of Validity The optimistic-execution-with-rollback model is valid **only if** the following invariant holds at every merge barrier: > For any set of branches merged together, the union of their optimistic write-sets is pairwise disjoint **on resources whose read-version tokens are equal**, OR the merge establishes a serialization order and re-validates each branch's read-set against the committed state produced by all prior commits in that order. The first disjunct is the cheap one: if branches write disjoint resources, they commute and rollback is trivially safe. The second is the expensive one and is what optimistic concurrency control actually requires (validate read-set at commit). The failure mode above occurs precisely when the orchestrator implements *neither*: it checks idempotency keys (which protect against duplicate dispatch, not against conflicting writes) and compensation availability (which protects against orphaned effects, not against over-application) but skips read-set revalidation. The condition also fails silently when branches are allowed to read siblings' overlays. Derived-read contamination means a branch's read-set includes resources it never declared, so even a correct read-set revalidation at the barrier will miss the dependency. The invariant must therefore be strengthened: **branches may read only the committed base, never a sibling's overlay**, unless the overlay read is recorded as an explicit dependency edge that the barrier topologically orders. ## Decision Boundary The orchestrator must decide, per merge, between three regimes. The boundary is set by whether the write-set intersection is empty and whether overlays are readable across branches: - **Disjoint write-sets, no cross-overlay reads → commit all, no revalidation.** Cheap, correct, the common case. Signal 1 absent, signal 2 absent. - **Intersecting write-sets with equal read-version → serialize and revalidate.** Order branches by a deterministic key (not dispatch order — dispatch order is a race artifact), commit sequentially, and after each commit re-run the next branch's read-set against the new committed state. If revalidation fails, the branch is *re-derived*, not rolled back: its optimistic calls are discarded from the overlay and the branch re-runs from the new base. Signal 1 present. This is the regime the procurement run needed and did not enter. - **Cross-overlay reads present → refuse speculative merge entirely.** If any branch read a sibling's overlay, the branches are not independent and speculative execution bought nothing but a longer failure path. Collapse to serial execution from the checkpoint. Signal 2 present. This is the hard boundary: once contamination exists, no amount of merge-time revalidation recovers the lost independence, because the contaminated branch's *reasoning* was conditioned on a value that never existed in any committed state. The decision must be made at **dispatch time** from declared schemas, not at merge time from observed calls. By merge time the optimistic effects are already in overlays and the contaminated branch has already reasoned. The structural signals 1 and 2 are both computable before a single tool call fires, from the tool schema's declared resource keys and the branch's declared read-set. An orchestrator that waits for the merge barrier to discover intersection has already paid the cost it was trying to avoid. ## Operational Effect Instrumenting for these signals changes three things: First, it converts a silent over-commit into a **pre-dispatch refusal or a serialization decision**, which is auditable at the point of decision rather than reconstructed from a fulfillment shortfall. The audit log gains a `merge_regime` field per branch set with the reason (`disjoint`, `serialized_revalidate`, `refused_contaminated`). Second, it forces the tool schema to declare **resource keys and read-versions explicitly**. An optimistic tool that cannot name the resource it writes and the version it read cannot participate in speculative execution — it must run serialized. This is a schema-negotiation constraint, and it belongs in the MCP tool descriptor, not in the orchestrator's runtime heuristics. Third, it bounds the blast radius of derived-read contamination. A branch that reads a sibling overlay is flagged at dispatch and demoted to serial; the cost is latency, not correctness. The alternative — discovering contamination at merge — costs a full re-derivation of a branch that has already consumed its token budget, which frequently exceeds the budget remaining to re-run it. The residual risk after all three is merge-order sensitivity (signal 4): if the serialization key is not deterministic, two runs of the same fan-out can commit in different orders and produce different final states. The guardrail is that the serialization key must be derived from the resource identity, never from dispatch order or branch completion order. ```python from dataclasses import dataclass, field from typing import Dict, Set, FrozenSet class SpeculativeMergeError(RuntimeError): """Raised when a speculative branch set cannot be safely merged.""" pass @dataclass(frozen=True) class BranchPlan: branch_id: str read_version: str # version token of the base snapshot read write_keys: FrozenSet[str] # resources this branch will optimistically write reads_sibling_overlay: bool # True if any read targets another branch's overlay def classify_merge_regime(branches: list[BranchPlan]) -> str: """ Decide the merge regime at dispatch time, before any tool call fires. Returns one of: 'disjoint', 'serialized_revalidate', 'refused_contaminated'. """ if any(b.reads_sibling_overlay for b in branches): # Derived-read contamination: independence is already lost. return "refused_contaminated" # Group branches by read_version; intersection only matters within a version. by_version: Dict[str, list[BranchPlan]] = {} for b in branches: by_version.setdefault(b.read_version, []).append(b) for version, group in by_version.items(): seen: Set[str] = set() for b in group: overlap = seen & b.write_keys if overlap: # Intersecting write-set on equal read-version -> must serialize. return "serialized_revalidate" seen |= b.write_keys return "disjoint" def commit_speculative(branches: list[BranchPlan], committed_state: dict) -> list[str]: """ Commit a branch set. Refuses contaminated sets; serializes intersecting sets with deterministic ordering and read-set revalidation. """ regime = classify_merge_regime(branches) if regime == "refused_contaminated": contaminated = [b.branch_id for b in branches if b.reads_sibling_overlay] raise SpeculativeMergeError( f"Speculative merge refused: branches {contaminated} read sibling overlays; " f"independence lost, collapse to serial execution from checkpoint." ) if regime == "disjoint": return [b.branch_id for b in branches] # serialized_revalidate: deterministic order by (read_version, sorted write_keys), # never by dispatch order. ordered = sorted( branches, key=lambda b: (b.read_version, tuple(sorted(b.write_keys))), ) committed: list[str] = [] for b in ordered: # Revalidate read-set against committed state produced by prior commits. if b.read_version != committed_state.get("version", b.read_version): raise SpeculativeMergeError( f"Branch {b.branch_id} read version {b.read_version} but committed " f"state advanced to {committed_state.get('version')}; re-derive branch." ) committed.append(b.branch_id) # Advance version after each commit so the next branch revalidates against it. committed_state["version"] = f"{b.read_version}+{b.branch_id}" return committed ```