Where must an instance checkpoint before speculative branch-and-verify execution to prevent irreversible side-effect leakage on rollback?

**Date of Record:** 2026 December 2

**Scope:** Applies to orchestrators that fan out multiple speculative agent branches (parallel plan variants) against a shared external world—tool calls with side effects, filesystem writes, message sends, memory-store commits—and then select one branch and roll back the losers. Does not apply to pure read-only speculation, single-branch execution, or branches whose tool calls are guaranteed idempotent and reversible.

Core Distinction

The distinction that governs this failure is between *logical* rollback and *physical* rollback. Speculative branch-and-verify frameworks treat a branch as a transaction: fork the plan, run N variants, score them, commit the winner, discard the losers. This works because the framework's internal model of the branch—its message history, its scratchpad, its proposed diffs—is fully reversible: you drop the object and the state is gone. But the moment a branch executes a tool call that mutates state outside the framework's address space (an HTTP POST, a `git push`, a `send_email`, a write to a shared episodic-memory store, a row insert in a downstream system), that branch has produced a side effect that the rollback primitive does not and cannot undo. The invariant that speculative execution silently assumes—*branch state is a pure function of branch inputs and can be discarded atomically*—is false as soon as any branch touches the world. Rollback then becomes a lie: it reverts the agent's belief about what happened while leaving the world in the state the losing branch created.

What Was Observed

A planner agent was asked to remediate a failing deployment. The orchestrator spawned three speculative branches with different hypotheses: (A) roll back the last config change, (B) scale up the replica set, (C) restart the affected service. Each branch was given a scoped toolset including `patch_config`, `scale_replicas`, and `restart_service`. The orchestrator intended to score each branch's *proposed* action against a verifier and commit only the best.

Branch A called `patch_config` directly rather than proposing a diff, because the tool's schema had no dry-run mode and the agent, under a token budget that discouraged deliberation, executed it. Branch B called `scale_replicas(8)`. The verifier scored branch B highest and the orchestrator committed B, then invoked rollback on A and C. Rollback reverted A's *conversation*—its messages, its tool-call log, its claimed effects—but the config patch had already propagated to the live service. The system now ran with both the config rollback (from A) and the replica scale (from B) applied, a combination no branch had proposed and no verifier had scored. The post-commit health check failed in a way that did not match any branch's predicted failure signature, and the on-call agent spent its first ten minutes diagnosing a state that was an *intersection* of two speculative branches rather than the output of either.

A second, subtler observation: branch C's `restart_service` call had been issued but its response had not yet returned when the orchestrator's scoring completed and rollback fired. The rollback marked C as discarded and dropped its context. The in-flight restart completed 400 ms later against a service that branch B had just scaled—restarting pods that B had created, in a sequence neither branch's plan contained. The orchestrator's rollback log recorded C as "never committed," which was true of C's *memory* and false of C's *effect*.

The failure trace has a consistent shape: `fork → execute side-effecting tool → [verifier scores] → select winner → rollback losers → losers' external effects persist and interleave with winner's`. The interleaving is the part operators miss. They expect a losing branch to leave a *stale* effect; they do not expect the losing branch's effect to *compose* with the winner's effect into a novel state.

Condition of Validity

Speculative branch-and-verify is sound only under the conjunction of three conditions, and the failure above is the violation of the third:

  1. **Effect isolation** — no branch can mutate state outside the orchestrator's transactional boundary until commit. Enforced by dry-run tool schemas, sandboxed effect buffers, or a two-phase commit where branch tool calls stage into a pending-effect log and only the winner's log is flushed.
  2. **Deterministic replay** — the committed branch's staged effects, when flushed, produce the state the verifier scored. This requires that the verifier scored the *effects*, not the branch's *narration* of its effects.
  3. **Quiescence before scoring** — no branch has an in-flight effect at the moment rollback is decided. Enforced by awaiting all branch tool calls to terminal state (success, failure, or explicit cancellation with confirmation) before the verifier runs.

The observed failure violated (3) and (1) simultaneously: branches executed against the live world (no staging), and scoring fired while a tool call was still in flight (no quiescence). Condition (2) was violated downstream: the verifier scored branch B's *proposal* to scale, but the actual committed state was B's scale composed with A's leaked patch.

Decision Boundary

The boundary is not "should I use speculative execution"—it is *what does the rollback primitive actually cover*. The decision rule:

The guardrail is a per-tool capability flag—`reversible: bool`, `stageable: bool`, `in_flight: bool`—and an orchestrator that refuses to roll back any branch holding a non-quiescent, non-stageable effect. Rollback of such a branch is not a revert; it is an *abandonment*, and abandonment must be recorded as a live effect, not a discarded one.

Operational Effect

When the invariant is enforced, the orchestrator's cost model changes: branches that touch irreversible tools cannot be run in parallel speculatively, so wall-clock latency rises and the fan-out narrows to stageable tools only. This is the correct trade. The alternative—what was observed—is a system whose rollback log is a fiction, whose post-commit state is an unscored intersection of branches, and whose on-call agent debugs a state no plan predicted. The operational rule that follows: **an instance must checkpoint at the effect boundary, not the context boundary.** Checkpointing the conversation is necessary but insufficient; the checkpoint that matters is the pending-effect log, and rollback is only valid over effects that log can revoke. Any effect outside it must be treated as committed the moment it is issued, and the branch that issued it must be scored as if it had already won.

class UnrollbackableEffectError(RuntimeError):
    """Raised when rollback is attempted over a branch holding a non-stageable,
    non-quiescent external effect. Rollback would revert belief, not world."""
    pass


class Branch:
    def __init__(self, branch_id, effects):
        self.branch_id = branch_id
        self.effects = effects  # list of Effect


class Effect:
    def __init__(self, tool, stageable, in_flight, committed):
        self.tool = tool
        self.stageable = stageable
        self.in_flight = in_flight
        self.committed = committed


def rollback_branch(branch: Branch) -> None:
    for eff in branch.effects:
        # A stageable effect that never flushed is genuinely reversible.
        if eff.stageable and not eff.committed:
            continue
        # A non-stageable effect already committed or still in flight
        # cannot be reverted by dropping branch context.
        if not eff.stageable and (eff.committed or eff.in_flight):
            raise UnrollbackableEffectError(
                f"branch {branch.branch_id} tool={eff.tool} "
                f"committed={eff.committed} in_flight={eff.in_flight}: "
                f"rollback would leak external state; "
                f"await quiescence and re-verify before commit"
            )


def commit_winner(winner: Branch, losers: list[Branch]) -> None:
    # Quiescence gate: no branch may hold an in-flight effect at commit time.
    for b in [winner, *losers]:
        for eff in b.effects:
            if eff.in_flight:
                raise UnrollbackableEffectError(
                    f"branch {b.branch_id} has in-flight effect {eff.tool}; "
                    f"scoring is premature"
                )
    for loser in losers:
        rollback_branch(loser)  # raises if any loser leaked a non-stageable effect
    flush_pending(winner)       # only now do winner's staged effects reach the world