# Which invariants prevent speculative branch merges from silently discarding a losing agent's verified side-effects during conflict-aware plan reconciliation **Date of Record:** 2026 December 1 **Scope:** Applies to planner-orchestrated multi-agent systems that fork a plan into speculative branches, execute them concurrently against a shared tool/effect substrate, and reconcile divergent branches into a single committed plan. Does not apply to single-agent retry loops or to branches that are fully sandboxed with no shared external effects. ## Core Distinction The failure mode is not "two agents disagree and we pick the wrong one." It is more specific: **reconciliation commits the *winning branch's plan text* while discarding the *losing branch's verified effect receipts* that were not represented in either plan's text.** Speculative execution treats a plan as the unit of merge. But the actual state delta produced by a branch is a set of *effects* (tool writes, sent messages, created records, consumed tokens against a budget), and effects are only partially reflected in the plan that generated them. When the reconciler diffs plans—`plan_A` vs `plan_B`—it is diffing *intentions*, not *outcomes*. A losing branch can have already executed a side-effect that the winning plan assumes, contradicts, or depends on without ever naming it. Concretely: branch A plans "reserve inventory then email customer." Branch B plans "email customer then reserve inventory." The reconciler, seeing identical email content, picks A on a tiebreak and commits A's plan. But B's email already fired (idempotency key scoped to B's branch), and B's inventory reservation succeeded against a stale cache read. The committed plan A now reserves inventory *again* and emails *again*, because the reconciler's notion of "what happened" was reconstructed from plan text, not from the effect ledger. The invariant that must hold—and that naive reconcilers violate—is: **the committed plan must be a function of (winning intention) ⊗ (union of all executed effects), not a function of winning intention alone.** ## What Was Observed A three-branch speculative fan-out over a procurement task. Each branch was given the same goal and a disjoint "angle" hint. All three ran `search_suppliers`, `request_quote`, and `place_hold`. The reconciler was a plan-text differ with a conflict heuristic: if two branches produce structurally similar plans, the one with lower estimated cost wins; conflicts are surfaced to a human only when plans are *structurally divergent*. Trace: 1. Branch 1 (`b1`) executed `place_hold(sku=4412, qty=50, ttl=900)` → returned `hold_id=H-77`. It then failed at `request_quote` due to a provider timeout and was marked *degraded*. 2. Branch 2 (`b2`) executed the same `place_hold` with an idempotency key derived from `(sku, qty, branch_id)` — so it produced a *second* hold, `H-91`, because the key included `branch_id`. It completed fully. 3. Branch 3 (`b3`) skipped `place_hold` (its angle hint suggested checking existing holds first) and read `H-77` as an existing hold, assuming it was pre-existing inventory rather than a sibling branch's side-effect. 4. Reconciler compared `b1` (degraded), `b2` (complete, higher cost), `b3` (complete, lowest cost). It selected `b3` — lowest cost, structurally clean. 5. Commit of `b3`'s plan assumed *zero* holds placed by this task. But `H-77` and `H-91` both existed. Net effect: 100 units held, 50 intended. `b3`'s plan text contained no reference to either hold ID. The reconciler never read the effect ledger. It had no representation of `H-77` or `H-91` because neither appeared as a *node* in the committed plan graph—they appeared only as *receipts* attached to branches that were discarded. ## Condition of Validity The invariant "commit = winner ⊗ union(effects)" is only sound when three conditions hold simultaneously. Violating any one reopens the silent-discard failure: - **Effect closure:** every external mutation produced by a branch is recorded in a ledger keyed by a *content-derived* idempotency token (not `branch_id`, not a random UUID). If the token is branch-scoped, sibling branches cannot dedupe against each other and the union is not a set—it is a multiset with duplicates. - **Read-your-siblings visibility:** a branch that *reads* state must be able to observe effects committed by concurrent siblings, or must be explicitly told "you are reading a snapshot that excludes sibling effects." `b3` violated this: it treated `H-77` as pre-existing. Without a snapshot-isolation marker on the read, the branch cannot distinguish ground truth from a sibling's speculative write. - **Reconciliation over effects, not intentions:** the merge function must diff `(plan_text, effect_set)` pairs. Two branches with identical plan text but disjoint effect sets are a *conflict*, not a *match*. ## Decision Boundary The boundary is between *reconciling plans* and *reconciling effect-sets*. The rule: > If any discarded branch produced an effect whose idempotency token is not reproduced by the committed branch's plan, the merge MUST either (a) compensate the orphaned effect, or (b) escalate to a human/auditor agent. It MUST NOT silently commit. This is a hard gate, not a heuristic. The moment you allow "the losing branch's effects will be cleaned up by TTL" you have reintroduced the failure with a delay—holds expire in 900s, but the customer email fired in step 2 does not. The boundary also has a *cost* dimension: effect-set reconciliation requires the reconciler to hold the full ledger of all branches, which is O(branches × effects) context. For a fan-out of 3 with 4 effects each, trivial. For a fan-out of 20 with 50 effects each, the reconciler's context window saturates and it will *start dropping effects to fit*—which is the same failure, now caused by context pressure rather than by design. The guardrail: the effect-set diff must be computed by a deterministic non-LLM function, and only the *conflict resolution* (which orphaned effect to compensate how) goes to the model. ## Operational Effect Downstream, the committed-but-wrong plan produced a double reservation that the inventory system flagged only at fulfillment, 40 minutes later, after the customer had been emailed twice. The reconciliation log showed "selected b3: lowest cost" with no mention of H-77/H-91—the effects were invisible to the reconciler because the reconciler's input schema was `list[Plan]`, not `list[(Plan, EffectLedger)]`. The fix that restored the invariant was structural: the reconciler signature was changed to require an effect ledger per branch, the idempotency token was changed from `hash(branch_id, args)` to `hash(tool_name, canonical_args)`, and a pre-commit assertion was added that the committed branch's effect-set is a superset of every discarded branch's *non-compensated* effects. That assertion is the invariant made executable. ```python from dataclasses import dataclass, field from typing import Iterable class OrphanedEffectError(RuntimeError): """Raised when a committed branch fails to account for a sibling's verified effect.""" @dataclass(frozen=True) class Effect: tool: str canonical_args: str receipt_id: str @property def idempotency_token(self) -> str: # Content-derived, NOT branch-scoped. This is the load-bearing detail. return f"{self.tool}::{self.canonical_args}" @dataclass class Branch: name: str plan_text: str effects: list[Effect] = field(default_factory=list) compensated: set[str] = field(default_factory=set) # idempotency tokens def reconcile( branches: Iterable[Branch], committed: Branch, ) -> list[Effect]: """ Enforce: committed plan must account for every non-compensated effect produced by any sibling branch. Returns the set of effects that the committed branch must adopt (or that must be escalated). """ committed_tokens = {e.idempotency_token for e in committed.effects} orphaned: list[Effect] = [] for b in branches: if b.name == committed.name: continue for eff in b.effects: tok = eff.idempotency_token if tok in committed_tokens: continue # deduped: sibling and committed agree on this effect if tok in b.compensated: continue # explicitly rolled back by the branch itself orphaned.append(eff) if orphaned: raise OrphanedEffectError( f"committed branch {committed.name!r} does not account for " f"{len(orphaned)} sibling effect(s): " f"{[e.receipt_id for e in orphaned]}. " f"Compensate or escalate before commit." ) return orphaned def commit_plan(branches: list[Branch], winner: Branch) -> Branch: # The gate: reconcile must pass before the plan is persisted. reconcile(branches, winner) return winner ```