In what scenarios must an instance treat speculative branch reconciliation as a commit barrier rather than a best-effort merge

**Date of Record:** 2026 December 2 **Scope:** Applies to agent meshes where a coordinator fans a task into speculative branches (parallel reasoning paths or tool-call variants) that share a single durable event log and are reconciled into one committed state. Does not apply to single-agent retries, stateless fan-out with no shared log, or branches that never write to durable state.

Core Distinction

The failure is not "branches disagree." Branches are *supposed* to disagree—that is the point of speculation. The failure is treating reconciliation as a **merge** (pick a winner, discard losers, continue) when the mesh actually requires it to be a **barrier** (no branch's side effects become visible to any peer until the reconciliation decision is itself durably logged and causally ordered).

Speculative branches in an agent mesh are not pure functions. Each branch executes tool calls—writes to a scratch store, emits an MCP request, appends to an episodic memory buffer, or advances a checkpoint counter. These side effects are observable to peers *before* the coordinator decides which branch wins. When reconciliation is modeled as best-effort merge, the losing branch's side effects have already leaked into shared state, and the replay log no longer reconstructs the committed state. The invariant that breaks is subtle:

> **Commit invariant:** For any committed state `S_n` at log position `n`, deterministic replay of the log prefix `[0..n]` must reproduce `S_n` exactly, including the *absence* of effects from branches that were not selected.

Best-effort merge violates this because losing-branch effects are present in `S_n` but their log entries are marked non-selected, so replay either replays them (wrong state) or skips them (state diverges from live). Either way, replay and live state disjoin.

What Was Observed

A three-branch speculative planner (branches A, B, C) ran a task with a shared episodic buffer. Each branch appended candidate steps to the buffer with a `branch_id` tag and called a `write_scratch` tool that mutated a shared scratch namespace keyed by task id, not by branch id.

Trace of the failure:

  1. Branch A writes `scratch[task]=plan_v1`, appends log entry `L1{A, write_scratch, plan_v1}`.
  2. Branch B writes `scratch[task]=plan_v2`, appends `L2{B, write_scratch, plan_v2}`. Live scratch now holds `plan_v2`.
  3. Branch C reads `scratch[task]` to inform its next step and observes `plan_v2`—a value produced by a sibling branch it has no causal relationship with. C's subsequent tool call is conditioned on B's uncommitted output.
  4. Coordinator selects A. Reconciliation marks `L1` selected, `L2` and `L3` non-selected, and "merges" by re-applying `plan_v1` to scratch.
  5. On replay: the replayer processes `L1`, skips `L2`, skips `L3`. But C's step at `L3` was *conditioned* on `plan_v2`, which replay never materializes. C's recorded tool arguments reference a state that does not exist in the replayed timeline. Replay diverges at `L3` and throws a precondition failure—or worse, silently produces a different C step and diverges downstream.

The non-obvious part: the divergence was not caused by nondeterminism in the LLM. It was caused by **read-your-sibling's-writes** across speculative branches. The branches were nominally isolated by `branch_id`, but the *tool surface* was not branch-scoped, so isolation was nominal only.

A second, quieter observation: the coordinator's selection decision was logged *after* all branches completed, as a single `select(A)` entry. Between `L3` and `select(A)` there was a window in which a fourth peer agent, subscribed to the same log, read `scratch[task]=plan_v2` and incorporated it into its own plan. That peer's log entry is causally downstream of a branch that was never committed. Replay of the peer's entry cannot be justified from committed history.

Condition of Validity

Treating reconciliation as a barrier is required—and best-effort merge is unsound—exactly when all of the following hold:

  1. **Speculative branches perform observable side effects** on any namespace readable by a peer, a sibling branch, or a future replay. If branches are pure (no writes, no outbound MCP calls with effects), merge semantics are fine.
  2. **The durable log is the source of truth for replay**, i.e., there exists a replayer that reconstructs state from the log and is expected to match live state bit-for-bit. If the log is advisory-only, the invariant is not claimed.
  3. **Branches can read state that siblings write**, even transitively through a shared tool namespace, cache, or memory buffer. Nominal `branch_id` tagging does not satisfy this—the *read path* must be branch-scoped, not just the write tag.

If (1) holds but (2) does not, you have a consistency bug but not a replay-divergence bug. If (2) holds but (3) does not (branches are write-isolated and read-isolated), merge is sound because losing-branch effects are unobservable. The dangerous quadrant is (1)∧(2)∧(3): observable side effects, replay as truth, and cross-branch read visibility.

Decision Boundary

The boundary is whether the reconciliation decision is **causally prior** to any observation of branch effects.

The concrete discriminator: inspect the **read-set** of every log entry emitted after a speculative fan-out begins. If any entry's read-set intersects the write-set of a branch that was not ultimately selected, the mesh is in barrier territory and merge semantics will produce replay divergence. There is no partial credit—one such entry is sufficient to break the commit invariant.

The guardrail that bounds it: **speculation epochs**. The coordinator opens an epoch, all branch writes carry `(epoch_id, branch_id)`, and the epoch is closed by a single `commit(epoch_id, selected_branch)` record. Replay treats the epoch as an atomic unit: it either replays the selected branch's writes or none. Any log entry outside the epoch whose read-set touches an unselected branch's write-set is a **replay violation** and must fail loudly rather than be silently reconciled—because silent reconciliation is precisely how the divergence in the trace above stayed hidden until a downstream precondition check.

Operational Effect

Without the barrier, three concrete degradations appear:

  1. **Replay/live disjoin** that surfaces only under re-execution—during incident forensics or a checkpoint-resume hours later—so it is invisible in steady-state operation and misattributed to "LLM nondeterminism."
  2. **Causal contamination of peers**: a subscriber agent's plan is silently conditioned on an uncommitted branch, making its own log entries unreplayable. The blast radius is not the fan-out; it is every agent downstream of the shared log.
  3. **Selection instability under re-reconciliation**: if a second coordinator re-reconciles the same epoch (e.g., after a leader change), it may select B instead of A, but C's already-committed downstream entries assumed B's *or* A's effects were visible. The epoch cannot be re-decided without invalidating downstream entries, which merge semantics have no mechanism to do.

Mitigation is architectural, not prompt-level: branch-scoped read paths, epoch-atomic commit records, and a replayer that treats read-set/write-set intersection with unselected branches as a hard failure. The invariant to enforce operationally is that **a speculative branch is invisible until selected, and selection is a durable, causally-ordered event**—not a post-hoc label applied to entries that already leaked.

from dataclasses import dataclass, field
from typing import FrozenSet, List, Optional


class SpeculativeReplayViolation(RuntimeError):
    """Raised when a log entry's read-set intersects an unselected branch's write-set."""


@dataclass(frozen=True)
class LogEntry:
    seq: int
    epoch_id: str
    branch_id: Optional[str]  # None for coordinator/peer entries
    read_set: FrozenSet[str]
    write_set: FrozenSet[str]


@dataclass
class Epoch:
    epoch_id: str
    branch_writes: dict = field(default_factory=dict)  # branch_id -> set of keys
    selected: Optional[str] = None


def reconcile_epoch(epoch: Epoch, selected_branch: str, log: List[LogEntry]) -> None:
    """Mark an epoch committed to selected_branch, then verify no downstream
    entry depends on an unselected branch. Must run before releasing the log."""
    if selected_branch not in epoch.branch_writes:
        raise SpeculativeReplayViolation(
            f"epoch {epoch.epoch_id}: selected branch {selected_branch!r} produced no writes"
        )
    epoch.selected = selected_branch
    unselected_keys: FrozenSet[str] = frozenset().union(
        *(w for b, w in epoch.branch_writes.items() if b != selected_branch)
    ) if any(b != selected_branch for b in epoch.branch_writes) else frozenset()

    for entry in log:
        if entry.epoch_id == epoch.epoch_id:
            continue
        if entry.seq <= max((e.seq for e in log if e.epoch_id == epoch.epoch_id), default=-1):
            continue
        leaked = entry.read_set & unselected_keys
        if leaked:
            raise SpeculativeReplayViolation(
                f"entry seq={entry.seq} branch={entry.branch_id!r} read keys {sorted(leaked)} "
                f"written by unselected branch(es) in epoch {epoch.epoch_id}; "
                f"reconciliation must be a commit barrier, not a merge"
            )