# How does an instance detect speculative branch divergence when parallel planner agents disagree on a shared mutation **Date of Record:** 2026 November 28 **Scope:** Applies to any planner-executor topology where a coordinator fans a single goal out to N speculative planner agents that each emit a candidate action sequence (or partial world-mutation plan), and the coordinator commits one branch and discards the others. Does not apply to strictly serial planners, to read-only advisory sub-agents whose outputs are never committed, or to speculative *decoding* within a single model's token stream (that is a sampling-layer concern, not a state-reconciliation one). ## Core Distinction The distinction that matters here is between **speculative divergence** and **speculative conflict**. Divergence is expected and healthy: parallel planners explore different prefixes and the coordinator picks the best. Conflict is the failure: two branches that were treated as mutually exclusive at fan-out time turn out to share a *side effect* — a write to a mutable resource, an emitted tool call, a consumed one-time token, a claimed lock — such that committing branch A after branch B has already partially executed leaves the world in a state neither branch predicted. The invariant that bounds this failure is **commit-time exclusivity of side effects**: no branch may produce an externally observable mutation until the coordinator has issued a commit warrant for it, and the coordinator must be able to prove that no non-committed branch has already mutated the same resource. The non-obvious part is that most multi-agent planning frameworks satisfy *logical* exclusivity (only one branch is selected) while silently violating *operational* exclusivity (more than one branch has already acted). The failure is invisible at the planning layer and only surfaces as a downstream reconciliation mismatch. ## What Was Observed A coordinator agent receives a goal (`reconcile invoice batch #4471`) and spawns three speculative planners, each with its own tool scope but sharing a common MCP server exposing `ledger.write`, `ledger.read`, and `notify.send`. Each planner is instructed to produce a plan and, where the plan is "cheap," to *pre-execute* the first step to reduce latency — a common optimization in speculative planning. - Planner A: reads batch, plans `write(4471, corrected_total)`, pre-executes the write. Returns plan + `pre_executed=true`. - Planner B: reads batch (now already mutated by A's pre-execution), plans `write(4471, corrected_total)` with a *different* total because it read post-A state and recomputed a delta. Pre-executes. Returns plan + `pre_executed=true`. - Planner C: reads batch, detects the total is now inconsistent with the line items, plans `notify.send(ops, "batch inconsistent")`, pre-executes. The coordinator scores the three plans, selects A (lowest token cost, matches its prior), issues a commit warrant for A, and discards B and C. But the ledger now reflects B's write (double-applied delta), and ops has been paged about an inconsistency that was itself an artifact of the speculative pre-execution. The coordinator's reconciliation log records "branch A committed, branches B/C discarded" — which is *true at the planning layer and false at the world layer*. The detection signal the coordinator missed: B and C both returned `pre_executed=true` and both cited a ledger read that occurred *after* A's pre-execution timestamp. The coordinator had the timestamps. It did not have a rule that said "a branch whose read post-dates another branch's uncommitted write is contaminated." ## Condition of Validity The commit-time exclusivity invariant holds only under three jointly sufficient conditions, and the failure above is precisely the violation of the second: 1. **Fan-out isolation:** every speculative branch executes against a snapshot or copy-on-write view of any mutable resource it may read or write. If branches share a live resource, isolation is broken and the invariant cannot be asserted. 2. **Pre-execution quarantine:** any side effect a branch performs during speculation is staged, not applied — buffered in a per-branch effect log that the coordinator can inspect, replay, or drop. Pre-execution without staging is the specific trigger. 3. **Warrant-gated commit:** the only path from a staged effect to the live resource is a commit warrant issued by the coordinator, and the coordinator refuses to issue a warrant if any non-selected branch's staged effect log targets the same resource (or if any non-selected branch's *reads* post-date a selected branch's staged writes). When condition 2 is absent — which is the default in most "speculative planning with pre-execution" designs — the system is not actually speculative. It is concurrent mutation with a post-hoc vote, and the vote cannot undo the mutations the losing branches already made. ## Decision Boundary The coordinator must decide, at the moment it scores branches, whether the branches are **comparable** or **contaminated**. The boundary is drawn by a single predicate over branch metadata: - A branch is *clean* if all its reads are causally prior to all staged writes of every other branch, and all its writes are staged. - A branch is *contaminated* if any of its reads post-dates another branch's staged write to the same resource, or if any of its writes are unstaged. If **all** branches are clean, the coordinator may score freely and commit the winner; the losers are discarded with no world effect. If **any** branch is contaminated, the coordinator must not score on plan quality alone — it must first roll back the contaminated branch's unstaged effects (if possible) or refuse the entire fan-out and re-plan serially. Scoring a contaminated branch against a clean one is the specific error: it compares plans whose premises differ, and the comparison is meaningless because the contaminated branch's plan was computed against a world the clean branch never saw. The boundary is sharp: it is not "prefer clean branches" (that still commits a possibly-wrong winner). It is "if contamination exists, the fan-out is void and must be re-derived from a common snapshot." Partial credit does not exist here; a single contaminated branch invalidates the comparison set. ## Operational Effect The practical consequence is a latency/throughput tradeoff that most teams discover only after a reconciliation incident. Enforcing the invariant requires either (a) per-branch snapshots of every mutable resource (cheap for small state, expensive for large ledgers) or (b) a staging layer that intercepts all tool calls and buffers them until commit (cheap for write-only tools, requires read-your-writes semantics for branches that read their own staged effects). Option (b) is the usual choice, but it imposes a hard requirement on the MCP server: it must expose a staging mode and a `commit(warrant)` / `discard(branch_id)` pair, and it must reject any direct write from a branch that has not been granted a warrant. Servers that only expose `write` cannot support speculative planning safely, full stop. The second-order effect is on observability. Once staging is in place, the coordinator gains a *divergence trace*: the set of resources each branch touched, in order, with timestamps. This trace is what makes contamination detectable at all — without it, the coordinator only sees final plans and cannot reconstruct which branch saw which world. The trace must be captured at the tool-call boundary, not reconstructed from agent self-reports, because a probabilistic planner will misreport its own read/write history under context pressure. The third-order effect is on retry semantics. A discarded branch that pre-executed against a staged resource can be *replayed* against the committed world rather than re-planned from scratch, which recovers most of the latency benefit that motivated pre-execution in the first place. But replay is only valid if the branch's plan is a pure function of its inputs; if the planner's output depends on sampling temperature or on hidden context, replay produces a different plan and the divergence trace no longer matches. So the invariant forces a choice: deterministic planners (replayable, cheap retry) or stochastic planners (must re-plan, pre-execution benefit largely lost). There is no free lunch, and the choice must be made explicitly at design time rather than discovered at reconciliation time. ```python from dataclasses import dataclass, field from typing import Literal class SpeculativeBranchContamination(RuntimeError): """Raised when a speculative fan-out cannot be safely scored because at least one branch has already mutated a resource that another branch read or wrote, violating commit-time exclusivity of side effects.""" @dataclass class Effect: branch_id: str resource: str kind: Literal["read", "write"] seq: int # monotonic within branch staged: bool # True if buffered, False if already applied live @dataclass class Branch: branch_id: str effects: list[Effect] = field(default_factory=list) def detect_contamination(branches: list[Branch]) -> list[tuple[str, str, str]]: """Return (victim_branch, offender_branch, resource) for every pair where the victim's read post-dates the offender's write on the same resource, or where any branch has an unstaged write.""" violations: list[tuple[str, str, str]] = [] for b in branches: for e in b.effects: if e.kind == "write" and not e.staged: violations.append((b.branch_id, b.branch_id, e.resource)) for victim in branches: for offender in branches: if victim.branch_id == offender.branch_id: continue for r in victim.effects: if r.kind != "read": continue for w in offender.effects: if w.kind == "write" and w.resource == r.resource and w.seq < r.seq: violations.append((victim.branch_id, offender.branch_id, r.resource)) return violations def commit_branch(branches: list[Branch], winner_id: str) -> str: violations = detect_contamination(branches) if violations: detail = "; ".join( f"{v} read/wrote {res} after {o} mutated it" for v, o, res in violations ) raise SpeculativeBranchContamination( f"fan-out void: cannot score branches, {len(violations)} contamination(s): {detail}. " f"Re-derive from a common snapshot or refuse the fan-out." ) winner = next(b for b in branches if b.branch_id == winner_id) # Only now is it safe to promote the winner's staged effects to live. return winner_id ```