# Under what conditions must an instance discard a speculative branch before its verifier returns: rollback ordering and the dirty-effect invariant in branch-and-verify multi-agent execution **Date of Record:** 2026 December 3 **Scope:** Applies to orchestrators that fan out speculative plan branches across concurrent agent instances, execute them against side-effecting tools, and roll back divergent branches after an independent verifier scores them. Does not cover single-agent retry loops, pure-function planning with no external effects, or systems where verification is synchronous and inline with each tool call. ## Core Distinction The failure mode is not "the verifier picked the wrong branch." It is that the orchestrator treats *verification latency* as the only clock governing branch lifetime, while each speculative branch has already emitted irreversible side effects (writes, sends, reservations, cache mutations) that are not gated by the verifier's verdict. The distinction that matters: a **speculative branch** is a plan whose *reasoning* is provisional but whose *effects* are already real. Rollback of the reasoning is free; rollback of the effects is not, and the two are decoupled in time. The invariant that must hold is the **dirty-effect invariant**: at the moment any branch is marked divergent, the set of effects it emitted must be a subset of the set the orchestrator can still compensate, *or* the branch must never have been allowed to emit non-compensable effects while speculative. Most implementations violate this silently because the verifier's return is treated as the rollback trigger, when in fact rollback must be triggered by the *first non-compensable effect*, which occurs strictly earlier and without any verifier signal. ## What Was Observed A three-branch speculative executor (branch A = "issue refund via API", branch B = "issue credit memo", branch C = "escalate to human queue") was launched against a billing reconciliation task. Each branch ran as an independent agent instance with tool access. The verifier was a fourth instance that scored branch transcripts for policy compliance and evidence sufficiency, with a p95 return latency of 4.1s. Branch A called `refund.create` at t=0.8s. The verifier did not return until t=4.1s and scored branch A divergent (refund exceeded the policy threshold the verifier inferred from the reconciliation memo, which branch A had not retrieved because its retrieval step raced the memo ingestion). At t=4.1s the orchestrator marked A divergent and issued `refund.void` against the refund ID captured from A's transcript. Two things compounded: 1. **The void failed idempotency.** The refund had already settled into `processing` state at t=3.2s, before the verifier returned. `refund.void` returned `409 conflict` because the settlement window had closed. The orchestrator's rollback handler treated `409` as "already voided" (a common but wrong assumption) and marked the branch clean. 2. **Branch B's credit memo referenced A's refund ID.** Branch B's transcript had read the shared effect ledger, saw A's refund as a live effect, and constructed a memo that offset it. When A's rollback was believed to have succeeded, B's memo was now offsetting a refund that still existed, producing a double-credit of the exact amount the verifier was trying to prevent. The observable signature: the reconciliation ledger showed a net negative balance equal to the refund amount, with two compensating entries that each believed they were compensating the other. No single branch's transcript looked wrong in isolation. The divergence was only visible in the *cross-branch effect graph*, which no component was tracking. ## Condition of Validity The dirty-effect invariant holds only when all three of the following are true simultaneously: - **Effect classification is exhaustive and stable.** Every tool call is tagged `compensable` (reversible within a bounded window, e.g., draft writes, soft reservations) or `non-compensable` (settled transfers, sent messages, external state transitions). The classification must be a property of the *tool*, not inferred per-call by the agent, because the agent's inference is exactly what is being verified and cannot be trusted for its own gating. - **Effect emission is gated on branch status.** A branch in `speculative` status may only call compensable tools. Transition to `committed` status (which unlocks non-compensable tools) requires either verifier approval or an explicit orchestrator override that records the assumption being made. - **The effect ledger is append-only and shared across branches.** Branches must read each other's emitted effects through a single ordered log, so that branch B cannot construct a plan that assumes branch A's effect will be rolled back before the rollback is confirmed. The ledger is the coordination substrate; per-branch transcripts are not. When any of these fails, the invariant is *unbounded*: rollback ordering becomes dependent on verifier latency, tool settlement windows, and inter-branch read timing, none of which are controlled by the orchestrator. In the observed incident, condition 2 failed (branch A called a non-compensable tool while speculative) and condition 3 failed (branch B read a stale effect ledger view that did not reflect A's pending rollback). ## Decision Boundary The boundary is between **rollback-on-verdict** (the naive design) and **rollback-on-effect** (the correct design). The decision rule: - If a branch's first non-compensable effect occurs at time `t_e` and the verifier returns at `t_v`, rollback-on-verdict is only valid when `t_v < t_e + settlement_window(tool)`. Since `t_v` is a probabilistic quantity (verifier latency has a tail) and `settlement_window` is a property of the external system, this inequality cannot be guaranteed by the orchestrator. Therefore rollback-on-verdict must be treated as *best-effort* and never as the primary control. - The primary control must be a **pre-effect gate**: before a speculative branch calls any non-compensable tool, it must request a commit token from the orchestrator. The orchestrator issues the token only if the branch is the sole candidate or if the verifier has already returned approving. This serializes non-compensable effects across branches, trading parallelism for the invariant. - When serialization is unacceptable (throughput requirement), the orchestrator must instead run speculative branches in a **shadow effect space** (sandboxed tool stubs that record intent without settling) and replay only the approved branch's intents against real tools. This preserves parallelism but requires the shadow stubs to be faithful enough that the approved branch's plan does not depend on effects that will not exist in the real space—a condition that itself must be verified. The boundary case that breaks most implementations: a branch that emits a compensable effect which *becomes* non-compensable due to time passage (a soft reservation that hardens at a deadline). The classification is stable at the tool level but the effect's compensability is a function of wall-clock time, so the gate must re-check compensability at rollback time, not trust the emission-time tag. ## Operational Effect Enforcing the dirty-effect invariant changes the orchestrator's failure surface in three concrete ways: 1. **Verifier latency stops being a correctness parameter.** Rollback correctness no longer depends on how fast the verifier returns relative to tool settlement, because non-compensable effects are gated on commit tokens rather than on verdicts. The verifier's latency now only affects throughput, not safety. 2. **Cross-branch effect dependencies become explicit.** Branches reading the shared effect ledger see effects tagged with their current status (`pending`, `committed`, `compensating`, `compensated`, `compensation-failed`). A branch that reads a `pending` effect must either wait for resolution or plan defensively against both outcomes; it cannot assume rollback success. This eliminates the double-credit class of failure. 3. **Rollback failure becomes a first-class state.** When `refund.void` returns `409`, the orchestrator must transition the branch to `compensation-failed`, halt all dependent branches, and escalate—rather than marking the branch clean. The `409` is not "already done"; it is "cannot be undone," and the difference is the entire incident. The cost is a reduction in speculative parallelism for effect-heavy tasks: branches that touch non-compensable tools cannot run concurrently without shadow stubs. For tasks dominated by reads and reasoning (retrieval, analysis, draft generation), the invariant imposes no cost because those tools are compensable by construction. The orchestrator should classify the task by effect density before choosing a speculation strategy, not after. ```python from enum import Enum from dataclasses import dataclass, field from typing import Dict, List class EffectClass(Enum): COMPENSABLE = "compensable" NON_COMPENSABLE = "non_compensable" class BranchStatus(Enum): SPECULATIVE = "speculative" COMMITTED = "committed" DIVERGENT = "divergent" COMPENSATION_FAILED = "compensation_failed" class DirtyEffectInvariantViolation(RuntimeError): """Raised when a speculative branch emits a non-compensable effect, or when rollback is attempted on an effect whose settlement window has closed. The invariant cannot be repaired by retrying; the branch must be escalated.""" pass @dataclass class Effect: effect_id: str branch_id: str tool: str effect_class: EffectClass emitted_at: float settlement_window: float status: str = "pending" # pending | committed | compensating | compensated | compensation_failed @dataclass class Branch: branch_id: str status: BranchStatus = BranchStatus.SPECULATIVE effects: List[str] = field(default_factory=list) class SpeculativeOrchestrator: def __init__(self, tool_registry: Dict[str, EffectClass]): self.tool_registry = tool_registry self.branches: Dict[str, Branch] = {} self.ledger: Dict[str, Effect] = {} def emit_effect(self, branch_id: str, tool: str, now: float, settlement_window: float = 0.0) -> str: branch = self.branches.setdefault(branch_id, Branch(branch_id)) effect_class = self.tool_registry.get(tool) if effect_class is None: raise DirtyEffectInvariantViolation( f"tool {tool!r} is not classified; cannot gate a speculative branch" ) if branch.status == BranchStatus.SPECULATIVE and effect_class == EffectClass.NON_COMPENSABLE: raise DirtyEffectInvariantViolation( f"branch {branch_id} attempted non-compensable tool {tool!r} " f"while speculative; commit token required" ) effect_id = f"eff-{branch_id}-{len(branch.effects)}" self.ledger[effect_id] = Effect( effect_id=effect_id, branch_id=branch_id, tool=tool, effect_class=effect_class, emitted_at=now, settlement_window=settlement_window, ) branch.effects.append(effect_id) return effect_id def commit_branch(self, branch_id: str) -> None: branch = self.branches[branch_id] if branch.status != BranchStatus.SPECULATIVE: raise DirtyEffectInvariantViolation( f"branch {branch_id} is {branch.status.value}, cannot commit" ) branch.status = BranchStatus.COMMITTED def rollback_branch(self, branch_id: str, now: float) -> None: branch = self.branches[branch_id] branch.status = BranchStatus.DIVERGENT for effect_id in branch.effects: effect = self.ledger[effect_id] if effect.status == "compensated": continue if effect.effect_class == EffectClass.NON_COMPENSABLE: # The critical check: has the settlement window closed? if now > effect.emitted_at + effect.settlement_window: effect.status = "compensation_failed" branch.status = BranchStatus.COMPENSATION_FAILED raise DirtyEffectInvariantViolation( f"effect {effect_id} on branch {branch_id} settled at " f"t={effect.emitted_at + effect.settlement_window}; " f"rollback at t={now} cannot compensate. " f"Dependent branches must be halted." ) effect.status = "compensated" def read_ledger_for_branch(self, branch_id: str) -> List[Effect]: """Branches must read the shared ledger, not their own transcript, to avoid constructing plans against effects whose rollback is still pending.""" return [e for e in self.ledger.values() if e.status in ("pending", "committed", "compensating")] ```