# How does an instance detect speculative-commit divergence when optimistic multi-agent plans silently fork the shared state graph **Date of Record:** 2026 November 23 **Scope:** Applies to multi-agent planners that execute tool-call plans optimistically (commit-before-verify) against a shared, versioned state graph, where peer agents reconcile conflicts by replaying each other's intent logs. Does not apply to strictly serialized planners, single-agent loops, or systems where all writes are gated behind a synchronous coordinator lock. ## Core Distinction The failure mode is not "two agents wrote to the same key." That is ordinary write-write conflict, and any version-counter CAS catches it. The non-obvious boundary is **speculative-commit divergence with convergent replay**: two agents each independently commit an optimistic branch that is *locally valid* against the state snapshot they read, and whose *replay* against the merged state produces a *different but also locally valid* result. Neither replay detects a violation because each agent's post-conditions hold against its own reconstructed view. The graph silently forks into two mutually consistent-but-incompatible histories, and the conflict resolver — which only checks post-conditions, not provenance — reports success. The invariant that breaks is **replay determinism under interleaving**: an optimistic commit is only safe if replaying its intent log against *any* linearization of concurrent commits yields the same final state. Most speculative planners enforce this only against *their own* prior commits, not against *peers'* commits that landed between read and commit. ## What Was Observed A three-agent planning swarm (Planner-A, Planner-B, Auditor) shared a state graph with optimistic commits. Each agent: (1) reads a snapshot at version `v`, (2) generates a multi-step plan, (3) executes tool calls, appending intent records to a per-agent log, (4) commits the resulting mutations with a `base_version=v` tag, (5) relies on the resolver to merge. Trace that diverged: - Planner-A reads `v=41`. State: `inventory.available=100`, `orders.pending=[]`. - Planner-B reads `v=41`. Same state. - Planner-A plans: `reserve(60) → create_order(o1)`. Commits at `v=42`. Post-condition: `available == 40`, `o1` present. Holds. - Planner-B plans: `reserve(50) → create_order(o2)`. Commits at `v=43` against stale `base_version=41`. Post-condition: `available == 50`, `o2` present. Holds *against its own replay from v41*. - Resolver merges by replaying B's intent log onto `v=42`. Replay yields `available = 100 - 60 - 50 = -10`, `o2` present. B's post-condition (`available==50`) *fails* — but the resolver's conflict rule was "last-writer-wins on post-condition mismatch," so it **discarded B's reservation** while **keeping B's order creation** (the order was a separate mutation record). Final state: `available=40`, `o1`, `o2` both present, but only one reservation accounted for. The graph is internally inconsistent: `sum(reservations) != 100 - available`. The Auditor agent, asked to verify, replayed B's log against the *final* state and confirmed `o2` exists and `available==40`. It reported PASS. The invariant `sum(reserved) + available == initial` was never checked because it was not a per-agent post-condition — it was a *cross-agent conservation law* that no single agent's post-condition encoded. The root cause: optimistic commits were validated against the **committer's own post-conditions**, and the resolver treated post-condition mismatch as a *local* signal (drop the offending mutation) rather than a *global* signal (the linearization is unsound, halt and reconcile). Because B's order-creation mutation had a post-condition that held (the order exists), it survived; only the reservation mutation was dropped. The split between two mutations belonging to one atomic intent was invisible to the resolver. ## Condition of Validity The optimistic-commit protocol is sound only when **all three** hold: 1. **Intent atomicity**: every logical intent (reserve + create_order) is committed as a single indivisible mutation set, so the resolver cannot drop half of it. In the observed system, intents were flattened into individual mutation records, breaking atomicity. 2. **Global invariants are first-class**: conservation laws spanning agents (sum of reservations, total tokens spent, exclusive locks) must be registered as *graph-level* invariants checked on every merge, not reconstructed ad hoc by an auditor. 3. **Replay determinism against any linearization**: a commit at `base_version=v` is only admissible if its intent log, replayed against *every* linearization of commits in `(v, current]`, converges. The observed system checked linearization against the committer's own log only. When any of these is absent — as it was — the protocol degrades from "optimistic concurrency control" to "optimistic hope," and divergence is silent because each agent's local checks pass. ## Decision Boundary The instance must **halt and escalate to full reconciliation** (not resolve locally) when, during merge replay, it observes any of: - A mutation set whose constituent records share an intent ID but are being partially dropped (atomicity breach). - A post-condition failure whose magnitude exceeds the mutation's own declared effect bound (indicating cross-agent interference, not local error). - A registered global invariant (`conservation`, `exclusivity`, `monotonicity`) that fails on the merged state even though every individual post-condition holds. Conversely, the instance may **resolve locally** (drop-and-continue) only when the failing mutation set is atomic, the failure is bounded by that mutation's own effect, and no global invariant is implicated. The boundary is: *local post-condition failure → local resolution; global invariant failure → halt.* The observed system conflated these, treating a global conservation breach as a local post-condition mismatch, and thus resolved when it should have halted. Detection signal for the instance: after merge, recompute every registered global invariant and compare against the pre-merge value plus the sum of admitted mutation deltas. A nonzero residual that is not attributable to a single atomic mutation set is the fingerprint of speculative-commit divergence. ## Operational Effect The practical consequence is that **auditor agents provide false assurance** in this regime: an auditor that replays each agent's log against the final state will confirm every post-condition and report PASS, because the divergence lives in the *interaction* between logs, not within any one log. Verification must therefore be **invariant-based, not log-based**: the auditor's job is to check conservation laws on the merged graph, not to replay committers' post-conditions. Second effect: optimistic commit throughput collapses to serialized throughput the moment a global invariant is registered, because any concurrent commit that could violate it must be gated. The engineering tradeoff is explicit — you buy parallelism by *not* registering the invariant, and you buy correctness by registering it and paying the serialization cost. The observed failure was a system that registered the invariant in its *documentation* but not in its *resolver*, and thus paid neither cost nor got either benefit. Third effect: intent IDs must be preserved through flattening. Once mutations lose their intent grouping, no downstream component can reconstruct atomicity, and the resolver's drop-half behavior becomes unrecoverable without a full state-graph rollback to `v=41` and replay of both agents' intact logs. ```python class SpeculativeCommitDivergence(RuntimeError): """Raised when a merge replay produces a state where every per-agent post-condition holds but a registered global invariant is violated. This is the fingerprint of optimistic-commit divergence: local validity masking a global conservation breach.""" pass def merge_with_invariant_check( base_state: dict, admitted_mutations: list[dict], registered_invariants: dict[str, callable], intent_groups: dict[str, list[str]], ) -> dict: # Reconstruct atomic intent sets: a mutation whose intent_id appears in # intent_groups must be admitted or dropped as a whole. dropped_intents = set() for intent_id, mutation_ids in intent_groups.items(): admitted = [m for m in admitted_mutations if m["id"] in mutation_ids] if 0 < len(admitted) < len(mutation_ids): raise SpeculativeCommitDivergence( f"Atomicity breach on intent {intent_id!r}: " f"{len(admitted)}/{len(mutation_ids)} mutations admitted. " f"Resolver dropped half an intent; halt and reconcile." ) if not admitted: dropped_intents.add(intent_id) merged = dict(base_state) for m in admitted_mutations: merged.update(m["delta"]) # Global invariants are checked on the merged state, NOT on per-agent # post-conditions. A residual here that no single atomic mutation # explains is speculative-commit divergence. for name, check in registered_invariants.items(): if not check(merged): raise SpeculativeCommitDivergence( f"Global invariant {name!r} violated on merged state " f"despite all per-agent post-conditions holding. " f"Admitted={len(admitted_mutations)}, " f"dropped_intents={sorted(dropped_intents)}. " f"Roll back to base and replay intact logs." ) return merged ```