Which invariants prevent speculative branch rollback from resurrecting committed effects in multi-agent fork-join orchestration

**Date of Record:** 2026 December 1 **Scope:** Applies to fork-join agent orchestrators that speculatively fan out sibling branches (each an LLM agent with its own context and tool access) and roll back losers after a join predicate selects a winner. Does not apply to strictly sequential single-agent execution, nor to branches whose tool calls are all pure/idempotent reads with no external side effects.

Core Distinction

Speculative multi-agent execution conflates two different notions of "undo." The orchestrator's mental model is *transactional rollback*: a losing branch is discarded, its context dropped, its writes reverted. But an LLM branch is not a database transaction. Its "writes" are (a) mutations to external systems via tool calls, and (b) mutations to shared agent state (blackboards, memory stores, message buses) that other live branches may have already *read*. The boundary failure is this: **rollback of a losing branch is only sound for effects that are (i) reversible AND (ii) not observable by any branch that survives the join.** The non-obvious part is (ii). A losing branch whose tool call wrote to a shared memory store, and whose sibling then *retrieved that memory during its own speculative run*, has propagated its effects into the winner's reasoning trace. Rolling back the loser does not roll back the winner, which already conditioned on poisoned state. The commit survives the rollback.

The invariant that must hold is a *causally consistent speculation frontier*: no effect of an uncommitted branch may become a read-dependency of any branch that can still commit. This is the agent-layer analogue of snapshot isolation, but it is violated far more easily because LLM branches do not declare their read/write sets — their retrieval and tool use are emergent, probabilistic, and discovered mid-execution.

What Was Observed

A fork-join orchestrator spawned three speculative branches (A, B, C) to answer a planning query. Each branch had tool access to a shared vector memory store (write via `memory_upsert`, read via `memory_search`) and a shared task blackboard. The join predicate scored branches on a rubric and committed the highest-scoring one, discarding the rest.

Trigger sequence:

  1. Branch A, exploring an approach, called `memory_upsert(key="vendor_policy", value="net-60 terms apply")`. This was a *speculative* write — A had not yet been selected.
  2. Branch B, running concurrently, issued `memory_search("payment terms")` and retrieved A's just-written record. B's plan then conditioned on "net-60 terms apply," adjusting its downstream reasoning and its own tool calls (it drafted a schedule assuming net-60).
  3. The join predicate scored B highest (B's plan was more detailed — partly *because* it had absorbed A's write). B was committed; A and C were rolled back.
  4. Rollback of A reverted the `memory_upsert` (the orchestrator's compensating action deleted the record). But B — the *winner* — had already committed a plan that depended on a fact that no longer exists and was never independently verified.

The observed failure trace: the committed output referenced "net-60 terms" while the memory store, post-rollback, contained no such record and the authoritative policy source said net-30. The winner was internally consistent but externally wrong, and the rollback machinery reported a clean, successful revert. The orchestrator logged `branch A rolled_back: ok` — technically true for A's own writes, catastrophically false for the system's causal state.

A second, subtler instance: two branches both wrote the *same* memory key with different values. Rollback of the loser deleted the key entirely (last-writer-delete semantics), erasing the winner's committed value. The winner's subsequent reads returned empty, and it silently degraded to a default rather than erroring.

Condition of Validity

Rollback of a speculative branch is sound **only if all three hold**:

When any of these is absent, "rollback" is a fiction: it reverts the loser's bookkeeping while leaving its epistemic footprint in the winner.

Decision Boundary

The orchestrator must decide, at fork time, between two regimes:

The boundary: **do not cross into shared speculation unless you can afford to re-execute the winners.** If the join predicate can select a branch that read an uncommitted sibling effect, and you cannot invalidate-and-rerun that branch, you are in the unsound regime. The failure is not that rollback is incomplete — it is that the *winner's validity was never independently established*. A committed branch that depended on speculative state is, epistemically, still speculative; committing it launders unverified state into the durable record.

The guardrail: a committed branch must carry a *provenance receipt* listing the committed snapshot version of every fact it read. If any read resolves to an uncommitted overlay entry, the commit is rejected and the branch demoted to re-execution. Provenance, not scoring, gates commit.

Operational Effect

The practical consequence is a shift in what "the join" means. In a transactional system, join = select and commit; losers vanish cleanly. In speculative multi-agent execution, join = select, then *prove the winner's read-set is causally closed under committed state*, then commit. The proof is the expensive part, and it is the part naive orchestrators omit.

Concretely:

The invariant, stated once: **an effect may be reverted only if no committable branch has observed it.** Everything above is machinery to enforce or detect violations of that line. When the line is crossed undetected, rollback becomes a laundering operation — it removes the evidence of speculation while preserving its conclusions.

from dataclasses import dataclass, field
from typing import Dict, Set, Tuple


class SpeculationRollbackViolation(RuntimeError):
    """Raised when a rollback would revert an effect a surviving branch observed."""
    pass


@dataclass
class Effect:
    key: str
    value: str
    version: int
    branch_id: str


@dataclass
class Branch:
    branch_id: str
    committed: bool = False
    # (key, version) pairs this branch read during its speculative run
    read_set: Set[Tuple[str, int]] = field(default_factory=set)


class SpeculationLedger:
    """Tracks uncommitted effects and read-dependencies to gate rollback soundness."""

    def __init__(self) -> None:
        self._effects: Dict[Tuple[str, int], Effect] = {}
        self._branches: Dict[str, Branch] = {}

    def register(self, branch_id: str) -> None:
        self._branches[branch_id] = Branch(branch_id)

    def speculative_write(self, branch_id: str, key: str, value: str, version: int) -> None:
        self._effects[(key, version)] = Effect(key, value, version, branch_id)

    def speculative_read(self, branch_id: str, key: str, version: int) -> None:
        # Reading an uncommitted effect creates a dependency edge.
        if (key, version) in self._effects:
            self._branches[branch_id].read_set.add((key, version))

    def commit(self, branch_id: str, committed_versions: Dict[str, int]) -> None:
        """A branch may only commit if every uncommitted effect it read has been
        committed by its owner, or the read is against committed state."""
        branch = self._branches[branch_id]
        for (key, version) in branch.read_set:
            eff = self._effects.get((key, version))
            if eff is None:
                continue  # already committed or reverted; resolve against snapshot
            owner = self._branches.get(eff.branch_id)
            if owner is None or not owner.committed:
                raise SpeculationRollbackViolation(
                    f"branch {branch_id} cannot commit: it read uncommitted "
                    f"effect {key}@v{version} owned by un-committed branch "
                    f"{eff.branch_id}; causal closure violated"
                )
        branch.committed = True

    def rollback(self, branch_id: str) -> None:
        """Revert a losing branch's effects, but refuse if any committable branch
        observed them. Blind revert is the failure mode this guards against."""
        reverted = {k for k, e in self._effects.items() if e.branch_id == branch_id}
        for other_id, other in self._branches.items():
            if other_id == branch_id:
                continue
            overlap = other.read_set & reverted
            if overlap and not other.committed:
                raise SpeculationRollbackViolation(
                    f"rollback of {branch_id} would revert {overlap}, which "
                    f"surviving branch {other_id} has read; must invalidate and "
                    f"re-execute {other_id} before reverting"
                )
            if overlap and other.committed:
                raise SpeculationRollbackViolation(
                    f"rollback of {branch_id} would revert {overlap}, already "
                    f"observed by COMMITTED branch {other_id}; rollback is unsound "
                    f"and the committed output must be quarantined"
                )
        for k in reverted:
            del self._effects[k]
        self._branches[branch_id].committed = False