What structural signals indicate speculative branch rollback has become unsound in parallel-drafting agent swarms

**Date of Record:** 2026 December 2

**Scope:** Applies to orchestrators that fan out N speculative branches from a shared prefix, pre-execute tool calls against those branches, and commit the first branch whose draft survives a divergence check. Does not cover single-branch retry loops or non-speculative sequential tool use.

Core Distinction

There are two ways a speculative branch can be wrong. The first is *content divergence*: the branch's reasoning drifts from the committed plan, the divergence check fires, and the branch is rolled back. This is the designed failure mode and it is cheap, because a rolled-back branch consumed only tokens and a rollback is a no-op against world state.

The second is *effect leakage*: a speculative branch pre-executes a tool call whose side effect is not reversible, and the divergence check fires *after* the effect has landed. Rollback then restores the branch's context but not the world. The branch is dead; its write is not. The invariant that makes speculative multi-agent execution sound is therefore not "branches diverge and are discarded" — it is **"no speculative branch may commit an irreversible effect before the divergence check has resolved it as the winner."** When that invariant is violated silently, the swarm enters a state where the committed winner's transcript and the actual world state disagree, and every downstream agent that reads world state inherits the disagreement. This is the non-obvious boundary: the failure is invisible in the trace of the winning branch, because the winning branch never touched the leaked resource.

What Was Observed

A three-branch fan-out (drafters A, B, C) shared a prefix and each proposed a next tool call. The orchestrator pre-executed all three tool calls in parallel to hide latency, then ran the divergence check against the committed plan. Branch B's tool call was `create_refund(order_id=4471, amount=180.00)`. Branch A's was a read. Branch C proposed `create_refund(order_id=4471, amount=180.00)` as well — an independent rediscovery of the same corrective action.

The divergence check selected A as the winner (its draft matched the plan's next step; B and C had drifted into an unrequested remediation). The orchestrator rolled back B and C, cleared their contexts, and continued from A. But B and C had *both* pre-executed the refund. The world now held two refunds of 180.00 against order 4471, and the committed transcript showed zero.

Three structural signals were present and were all misread as benign:

  1. **Duplicate effect across sibling branches.** B and C converged on the same tool call with identical arguments. The orchestrator's dedup layer keyed on `(tool_name, args_hash)` and suppressed C's *execution* as redundant — but only after B's had already landed, and the suppression was logged as a cache hit rather than as a collision. Convergence between speculative siblings is not corroboration; it is a signal that the branch space has a high-probability attractor, and any irreversible call at that attractor will be fired by every branch that reaches it.
  1. **Rollback latency exceeding effect latency.** The divergence check took 340ms (it re-ran a plan-alignment model). The refund tool acknowledged in 90ms. The rollback window was structurally shorter than the effect window, so the check could not have prevented the leak even in principle.
  1. **Winner-transcript cleanliness.** The committed trace for branch A contained no refund, no warning, and no counter. An auditor replaying the winner's transcript would reconstruct a world with zero refunds. The divergence was only detectable by diffing *discarded* branch transcripts against world state — a reconciliation path that did not exist.

Condition of Validity

Speculative pre-execution is sound only under the conjunction:

When any of these is absent, the branch space is unsound: the orchestrator can commit a winner whose transcript is not a faithful description of the world.

Decision Boundary

The boundary is not "reversible vs irreversible" in the abstract — it is **whether the divergence check's decision latency is bounded below the effect's commit latency, and whether the effect can be un-fired.** Concretely:

The failure mode lives precisely in the gap where `t_divergence_check` is *usually* small enough that pre-execution *usually* wins the race — so the leak is rare, load-dependent, and correlated with the slow-check conditions (large fan-out, heavy plan-alignment model, cold cache) that also correlate with high-stakes remediation branches. The tail is not random; it is biased toward the branches you least want to leak.

Operational Effect

After the fix, the orchestrator classified tool calls at schema load, staged all `irreversible` calls behind a winner-selection barrier, and emitted a `SpeculativeEffectLeak` when a discarded branch's staged call matched a committed branch's staged call. The observable change was not fewer rollbacks — rollbacks still happen at the same rate — but the reconciliation surface moved from "diff discarded transcripts against world state after the fact" to "the transport refuses to release a staged irreversible call for any branch that has not won." The cost is latency on irreversible calls (they serialize behind the barrier), which is the correct trade: a serialized refund is cheap, a duplicated refund is a reconciliation incident that no downstream agent can detect from its own context.

The general lesson: in speculative multi-agent execution, the transcript of the winner is not a sufficient record of what happened. Soundness requires that the set of *discarded* branches be auditable against world state, and that audit is only tractable if irreversible effects were never executed by discarded branches in the first place.

import hashlib
from dataclasses import dataclass, field
from enum import Enum
from typing import Dict, List, Optional


class EffectClass(Enum):
    REVERSIBLE = "reversible"
    COMPENSABLE = "compensable"
    IRREVERSIBLE = "irreversible"


class SpeculativeEffectLeak(RuntimeError):
    """Raised when a non-winning speculative branch has released an irreversible
    effect, or when sibling branches converge on an identical irreversible call."""


@dataclass
class ToolCall:
    branch_id: str
    tool: str
    args: dict

    def effect_key(self) -> str:
        blob = f"{self.tool}:{sorted(self.args.items())}".encode()
        return hashlib.sha256(blob).hexdigest()


@dataclass
class StagedCall:
    call: ToolCall
    effect_class: EffectClass
    released: bool = False


@dataclass
class SpeculationBarrier:
    tool_effect_class: Dict[str, EffectClass]
    staged: Dict[str, StagedCall] = field(default_factory=dict)
    committed_branch: Optional[str] = None

    def stage(self, call: ToolCall) -> StagedCall:
        if call.tool not in self.tool_effect_class:
            raise SpeculativeEffectLeak(
                f"tool {call.tool!r} has no declared effect class; "
                "speculative pre-execution is unsound without schema-level classification"
            )
        ec = self.tool_effect_class[call.tool]
        key = call.effect_key()
        if ec is EffectClass.IRREVERSIBLE and key in self.staged:
            prior = self.staged[key]
            if prior.call.branch_id != call.branch_id:
                # Convergence on an irreversible effect is a collision, not a cache hit.
                raise SpeculativeEffectLeak(
                    f"branches {prior.call.branch_id!r} and {call.branch_id!r} "
                    f"converged on irreversible call {call.tool}({call.args}); "
                    "escalate to orchestrator before executing"
                )
        staged = StagedCall(call=call, effect_class=ec)
        self.staged[key] = staged
        return staged

    def release_for_winner(self, branch_id: str) -> List[StagedCall]:
        self.committed_branch = branch_id
        released = []
        for staged in self.staged.values():
            if staged.call.branch_id != branch_id:
                continue
            if staged.effect_class is EffectClass.IRREVERSIBLE:
                staged.released = True
            released.append(staged)
        return released

    def rollback(self, branch_id: str) -> None:
        for staged in self.staged.values():
            if staged.call.branch_id != branch_id:
                continue
            if staged.released:
                raise SpeculativeEffectLeak(
                    f"branch {branch_id!r} was rolled back after releasing "
                    f"irreversible call {staged.call.tool}({staged.call.args}); "
                    "world state now diverges from committed transcript"
                )
            # unreleased staged calls are simply dropped; no effect to compensate.
            self.staged.pop(staged.call.effect_key(), None)