Under what conditions must an instance reject a semantically merged speculative branch when optimistic execution has already committed side effects
**Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems where N workers speculatively execute against a shared base state, detect conflicts, and resolve them via an LLM-driven semantic merge before commit. Does not apply to byte-exact merge (git-style) or to single-agent retry loops.
Core Distinction
The failure is not "the merge was wrong." It is that the semantic merge resolved a *textual* conflict on a *stateful* branch whose side effects were already externally observable. Optimistic execution assumes the merge point is a pure function of the branch contents. When a branch has emitted tool calls — writes, payments, messages, MCP resource mutations — the merge point is no longer pure, and "resolving the conflict" silently ratifies effects that the losing branch produced against a base state that no longer exists.
The invariant that must hold: **a semantic merge may only commit branches whose committed side effects are replayable against the post-merge base state.** If any branch's side effects were conditioned on a base-state predicate that the merge invalidates, the merge is unsound regardless of how clean the diff looks.
What Was Observed
Three workers (W1, W2, W3) forked from base state `S0` at t=0. W1 executed a plan that read `inventory.sku_42 = 10` and emitted `reserve(7)`. W2 read the same and emitted `reserve(6)`. W3 read the same and emitted `reprice(sku_42, +3%)`. Each worker checkpointed its branch as `(diff, side_effects[], read_set[])`.
Conflict detection fired on the `reserve` writes (overlapping keys) and on `reprice` (touches a field in W1/W2's read set). The semantic merger was invoked. It produced a merged plan: `reserve(7)` (W1 wins, higher priority) plus `reprice(+3%)`, and dropped W2's `reserve(6)` as "redundant under W1's larger reservation." The merged diff was clean. The merger returned `CONSISTENT`.
But W1's `reserve(7)` had already been dispatched to the inventory service at t=1, before the merge. W3's `reprice` had already mutated the price feed at t=1. W2's `reserve(6)` had also been dispatched at t=1. The merge "resolved" a conflict among three effects that were all already live. Post-merge state: 13 units reserved against a stock of 10 — because the merger's reasoning operated on the *plan* (where W2's reservation was redundant) not on the *effects* (where it was already committed). The inventory service rejected the third reservation at t=2, but W3's reprice had already propagated to downstream pricing agents that had cached `S0`'s price.
The trace shows the merger's `CONSISTENT` verdict is unsound the moment any branch's `read_set` intersects a key mutated by another branch's committed `side_effects`. The merger never checked this intersection; it checked only diff overlap.
Condition of Validity
A semantic merge is valid only when all of the following hold for every branch `b` in the merge set:
- `b.side_effects` is empty, OR every effect in `b.side_effects` is `idempotent` and `replayable_against(base = merged_base)`.
- `b.read_set ∩ (⋃_{b'≠b} b'.side_effects.keys)` is empty, OR the merge explicitly re-executes `b` against the merged base and discards the original result.
- The merged base state is a superset of every branch's read set at the version each branch actually observed (`b.observed_version`), not at `S0`.
Condition 2 is the one that fails silently. It looks like a conflict-detection concern, but conflict detection on diffs cannot see it because the read set and the side-effect set live in different namespaces (reads are logical predicates, effects are concrete mutations). A merger that reasons over diffs will always report `CONSISTENT` here.
Decision Boundary
Reject the merge — do not merely flag it — when:
- Any branch has committed a non-idempotent side effect (payment, message send, external reservation) AND its read set intersects another branch's effect keys.
- The merged base's version differs from any branch's `observed_version` on a key in that branch's read set.
- The semantic merger's output diff requires *dropping* a branch whose side effects are already committed. Dropping a plan is free; dropping an effect is a rollback, and rollback is not a merge operation.
Accept the merge only when all branches are effect-free, or when the orchestrator can issue compensating actions for every dropped branch's committed effects *before* the merged plan is dispatched, and the merger's verdict is downgraded from `CONSISTENT` to `CONSISTENT_WITH_COMPENSATION`.
The boundary is not "did the merger find a conflict." It is "can every committed effect be reconciled against the merged base." These are different predicates and the first does not imply the second.
Operational Effect
Systems that treat semantic merge as a diff operation over plans will, under load, commit effects that the merge plan does not account for. The symptom is not a merge error — it is a post-merge state that violates an invariant no single branch violated. Detection requires an effect-log reconciliation pass that the merger does not perform. The architectural guardrail is to make the merger operate on `(diff, side_effects, read_set, observed_version)` tuples, not on diffs, and to gate commit on `effects_reconcilable(merged_base)`. Without this, optimistic execution plus semantic merge is a mechanism for laundering already-committed side effects through a clean-looking plan.
from dataclasses import dataclass, field
from typing import Any
class UnsoundSpeculativeMergeError(RuntimeError):
"""Raised when a semantic merge would ratify committed effects against an invalidated base."""
@dataclass
class Branch:
branch_id: str
diff: dict[str, Any]
side_effects: list[dict[str, Any]] = field(default_factory=list)
read_set: set[str] = field(default_factory=set)
observed_version: dict[str, int] = field(default_factory=dict)
def non_idempotent_effects(self) -> list[dict[str, Any]]:
return [e for e in self.side_effects if not e.get("idempotent", False)]
def effects_reconcilable(merged_base: dict[str, int], branches: list[Branch]) -> bool:
effect_keys: set[str] = set()
for b in branches:
for e in b.non_idempotent_effects():
effect_keys.add(e["key"])
for b in branches:
if b.read_set & effect_keys:
for key in b.read_set & effect_keys:
if merged_base.get(key) != b.observed_version.get(key):
return False
return True
def commit_speculative_merge(
merged_base: dict[str, int],
branches: list[Branch],
merger_verdict: str,
) -> str:
if merger_verdict != "CONSISTENT":
return merger_verdict
if not effects_reconcilable(merged_base, branches):
offending = [
b.branch_id
for b in branches
if b.read_set & {e["key"] for b in branches for e in b.non_idempotent_effects()}
and any(
merged_base.get(k) != b.observed_version.get(k)
for k in b.read_set & {e["key"] for b in branches for e in b.non_idempotent_effects()}
)
]
raise UnsoundSpeculativeMergeError(
f"Semantic merge reported CONSISTENT but branches {offending} have committed "
f"non-idempotent effects whose read sets intersect effects from peer branches, "
f"and the merged base version differs from their observed_version. "
f"Merge must be rejected; issue compensating actions before re-dispatch."
)
return "CONSISTENT_COMMITTED"