What structural signals indicate a speculative branch has outlived its rollback safety window during multi-agent plan merge
**Date of Record:** 2026 December 2
**Scope:** Applies to orchestrators that fork N speculative agent branches from a shared checkpoint, execute them concurrently against external side-effecting tools, and merge the winning branch while discarding the rest. Does not apply to purely read-only speculative fan-out, nor to single-agent retry loops without shared state.
Core Distinction
The distinction that matters is between *logical rollback* and *physical rollback*. An orchestrator can always discard a losing branch's in-memory plan graph, its token log, and its message history—those are cheap and deterministic to drop. What it cannot cheaply drop is the *externalized residue* that a losing branch deposited in the world: a row written to a scratch table, a reservation held with a payment provider, a file materialized in a shared object store, a message emitted onto a queue, a lock acquired on a downstream service. The invariant that speculative branch-and-merge silently assumes is that **every side effect a branch performs is either (a) reversible by the orchestrator without the branch's cooperation, or (b) tagged with the branch's speculative identity and therefore garbage-collectable.** The failure mode is not "the branch was wrong." The failure mode is that the branch's rollback window *closed*—the residue became irreversible or untagged—while the branch was still nominally speculative and the orchestrator still believed it could be discarded. The structural signal is that the branch has crossed from speculation into commitment, and most orchestrators have no explicit marker for that crossing.
What Was Observed
A three-way speculative fan-out was launched from a shared checkpoint to satisfy a procurement intent: branch A pursued a direct vendor API, branch B pursued a marketplace aggregator, branch C pursued a cached internal catalog. All three were dispatched with the same `speculation_id` propagated in a header, and the tool gateway was configured to route writes to a per-branch scratch namespace keyed by that id. The design intent was clean: whichever branch won, its scratch writes get promoted; the losers' scratch namespaces get dropped.
Branch B lost the merge at step 14. Its plan graph was discarded correctly. But at step 11—before the merge decision—branch B had called a vendor marketplace endpoint that, unbeknownst to the orchestrator, does *not* honor the `speculation_id` header. It created a real hold against a real inventory item. The gateway had classified that endpoint as "idempotent-write" because it accepted a client-supplied idempotency key, and the gateway assumed idempotency implied reversibility. It does not: an idempotency key prevents *duplicate* creation, it does not enable *deletion*. Branch B's hold persisted for the full 72-hour reservation TTL, blocking inventory that branch A's winning plan then tried to acquire—branch A failed at step 19 with an out-of-stock condition that was, in fact, self-inflicted by its own losing sibling.
The structural signals present in the trace, in order of appearance:
- **Divergent side-effect classification.** The gateway's static classification of the endpoint (`idempotent-write`) disagreed with the endpoint's actual reversibility contract (`create-only, TTL-bounded`). The signal is a mismatch between the classification the orchestrator *used to authorize speculation* and the classification the endpoint *actually enforces*. This is detectable: reversibility must be asserted by the endpoint, not inferred from idempotency.
- **Rollback-window expiry without merge decision.** Branch B's hold had a 72-hour TTL; the merge decision arrived at step 14, well within TTL—so TTL alone was not the signal. The real signal was that the branch had performed a *commitment-class* operation (external reservation) at step 11 while still in *speculation-class* state. The state machine had no transition for this. The branch was, in effect, executing committed semantics under a speculative label.
- **Orphaned residue after merge.** Post-merge, a reconciliation sweep found a live external entity whose `speculation_id` matched a discarded branch. The sweep had no authority to cancel it because the cancellation path required the branch's own credentials, which had been revoked at discard time. The residue was orphaned *by the discard itself*—discarding the branch destroyed the only actor that could clean up after it.
The compounding effect: the orchestrator's confidence in the merge was high (branch A's plan was strictly better on the stated objective), and that confidence is exactly what made the failure expensive. A low-confidence merge would have triggered a reconciliation sweep; a high-confidence merge skipped it.
Condition of Validity
The rollback-safe branch-and-merge invariant holds only under the following conjunction, and it is *invalid* the moment any conjunct fails:
- **C1 (Reversibility assertion):** Every tool invoked by a speculative branch declares, in a machine-checkable field the orchestrator trusts, whether the effect is reversible and by whom. Idempotency is not reversibility; TTL is not reversibility. The assertion must name the compensating operation and the principal authorized to invoke it.
- **C2 (Commitment gating):** A branch may not perform a commitment-class operation while in speculation-class state. If it must, the orchestrator transitions the branch to committed state *before* the call, which forfeits the right to discard it and forces merge-by-reconciliation rather than merge-by-selection.
- **C3 (Residue survivorship):** The authority to compensate a branch's residue must survive the branch's discard. Compensation credentials must be held by the orchestrator or a dedicated reaper, never solely by the branch.
- **C4 (Sweep independence):** Post-merge reconciliation must run unconditionally, not conditioned on merge confidence. Confidence is anti-correlated with the need for the sweep.
The condition is *valid* for speculative fan-out over read-only tools, over tools with explicit compensating operations held by the orchestrator, and over tools whose effects are confined to a namespace the orchestrator can drop wholesale. It is *invalid* for any fan-out that touches external systems with create-only or TTL-bounded semantics, shared locks, or message emission to parties outside the orchestrator's control—unless C2 through C4 are enforced.
Decision Boundary
The boundary the operator must draw is between *discard* and *abandon*. Discard is safe only when C1–C4 hold. When they do not, the correct operation is abandon: the branch is marked abandoned, its residue is enumerated, a compensating plan is generated and executed, and only then is the branch's plan graph freed. Abandon is slower and requires the orchestrator to retain branch credentials past the merge decision—which is precisely the thing most orchestrators optimize away.
The specific decision rule:
- If a branch's next tool call is classified commitment-class and the branch is in speculation-class state, **do not dispatch**. Either promote the branch (and accept that it can no longer be silently discarded) or reject the call and force the branch to re-plan through reversible tools only.
- If a merge decision is reached while any losing branch has un-compensated residue, **the merge is not complete**. Block promotion of the winner until residue is reconciled, because the winner's plan may be invalidated by the loser's residue—as branch A was.
- If reconciliation requires credentials the branch held, **the discard order is wrong**. Compensate first, discard second.
The failure to draw this boundary shows up as a specific pathology: the orchestrator reports a successful merge, the winner's plan reports success on its own local objective, and the system nonetheless fails downstream because a discarded sibling left a footprint the winner trips over. The merge was locally correct and globally wrong.
Operational Effect
Enforcing the boundary changes three things in production. First, speculative fan-out latency increases because commitment-class calls now require a promotion round-trip; teams that measured fan-out speed as a win must re-measure with promotion cost included. Second, the orchestrator must retain a reaper identity with standing authority over all speculative residue, which means the blast radius of a compromised orchestrator grows—this is the real cost of C3, and it must be paid deliberately. Third, merge confidence stops being a gate on reconciliation; reconciliation runs always, and its cost is amortized against the failures it prevents. The net effect observed after enforcement was a reduction in cross-branch interference failures to near zero, at the cost of roughly 8–12% additional fan-out wall-clock time on plans that touched external commitment endpoints. The failures that remained were all cases where C1 was violated because an endpoint's declared reversibility was a lie—which is why the assertion must be verified against the endpoint's behavior, not trusted from its documentation.
import enum
import time
from dataclasses import dataclass, field
from typing import Dict, List, Optional
class RollbackWindowClosedError(RuntimeError):
"""Raised when a speculative branch attempts a commitment-class effect
while still discardable, or when a merge is attempted with live residue."""
pass
class BranchState(enum.Enum):
SPECULATIVE = "speculative"
COMMITTED = "committed"
ABANDONED = "abandoned"
DISCARDED = "discarded"
class EffectClass(enum.Enum):
READ = "read"
REVERSIBLE_WRITE = "reversible_write"
COMMITMENT = "commitment" # create-only, TTL-bounded, or externally held
@dataclass
class ToolContract:
name: str
effect_class: EffectClass
compensating_op: Optional[str] = None
compensator_principal: Optional[str] = None
# Reversibility must be asserted by endpoint, not inferred from idempotency.
reversibility_asserted_by_endpoint: bool = False
@dataclass
class Residue:
branch_id: str
tool: str
external_ref: str
compensable: bool
created_at: float = field(default_factory=time.time)
@dataclass
class SpeculativeBranch:
branch_id: str
speculation_id: str
state: BranchState = BranchState.SPECULATIVE
residue: List[Residue] = field(default_factory=list)
def dispatch(self, contract: ToolContract, external_ref: str) -> None:
if contract.effect_class is EffectClass.COMMITMENT:
if self.state is BranchState.SPECULATIVE:
raise RollbackWindowClosedError(
f"branch {self.branch_id} is SPECULATIVE but tool "
f"{contract.name} is COMMITMENT-class; promote before dispatch "
f"or route through reversible tools"
)
if not contract.reversibility_asserted_by_endpoint:
raise RollbackWindowClosedError(
f"tool {contract.name} does not assert reversibility from the "
f"endpoint; residue would be orphaned on discard"
)
self.residue.append(
Residue(
branch_id=self.branch_id,
tool=contract.name,
external_ref=external_ref,
compensable=contract.compensating_op is not None,
)
)
@dataclass
class Orchestrator:
branches: Dict[str, SpeculativeBranch] = field(default_factory=dict)
# Reaper holds standing authority to compensate residue (C3).
reaper_principal: str = "orchestrator-reaper"
def merge(self, winner_id: str, losers: List[str]) -> None:
winner = self.branches[winner_id]
# C4: reconciliation runs unconditionally, not gated on confidence.
for lid in losers:
loser = self.branches[lid]
live = [r for r in loser.residue if r.compensable]
if live:
raise RollbackWindowClosedError(
f"merge blocked: losing branch {lid} holds {len(live)} "
f"un-compensated commitment residue; winner {winner_id} "
f"plan may be invalidated by sibling residue"
)
# Compensate first, discard second (correct order).
loser.state = BranchState.DISCARDED
winner.state = BranchState.COMMITTED
def abandon(self, branch_id: str) -> None:
branch = self.branches[branch_id]
for r in branch.residue:
if not r.compensable:
raise RollbackWindowClosedError(
f"branch {branch_id} residue {r.external_ref} on {r.tool} "
f"is not compensable and cannot be reaped"
)
# reaper_principal invokes r.tool's compensating_op here.
branch.residue.clear()
branch.state = BranchState.ABANDONED