# In what scenarios must an instance refuse to commit a speculative branch when rollback cannot restore a non-idempotent external effect **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan out parallel agent branches speculatively (optimistic execution) and commit the first branch to satisfy a goal predicate while rolling back the rest. Does not apply to branches whose side effects are fully transactional or confined to a single recoverable store. ## Core Distinction Speculative parallel execution treats a branch as *discardable* until commit. That assumption holds only for branch-local state. The failure mode is not "the wrong branch won." It is that rollback restores *internal* state (context, scratchpad, vector store writes, plan graph) but cannot restore *external* effects already emitted by a losing branch—emails sent, payments authorized, tickets opened, files written to a shared mount, messages published to a queue consumed by another agent. These effects are **non-idempotent and irreversible at the agent layer**: the agent has no compensating primitive and no way to observe whether a downstream consumer already acted. The invariant that must hold before any speculative commit: *every side effect emitted by a branch must be either (a) fenced by a commit token so it becomes observable only on commit, or (b) individually reversible through a registered compensator.* If neither holds, the branch is not actually speculative—it is a live mutation racing its siblings, and rollback is a fiction. ## What Was Observed An orchestrator spawned three branches to fulfill "reconcile the customer's duplicate subscription." Each branch independently called a `refund` tool, then a `close_account` tool, then wrote a resolution record. Branch B finished first and satisfied the goal predicate; the orchestrator committed B and issued rollback to A and C. Rollback cleared A and C's context, deleted their scratchpad entries, and marked their resolution records as voided. But A had already *sent* a refund request to the payment gateway 400 ms before B's refund, and C had already published a `account.closed` event to the event bus. Rollback had no compensator for either. Result: two refunds issued against one subscription, and a downstream provisioning agent consumed C's close event and tore down the account while B's resolution record asserted the account was intact. The orchestrator's state was internally consistent and externally wrong. The trace showed the exact gap: rollback ran at `t=4.21s`, but A's refund POST completed at `t=3.80s` and C's publish completed at `t=3.95s`. The rollback path only touched branch-local stores. No branch had registered a compensator because the tool schemas exposed `refund` and `close_account` as plain calls with no `compensate` field and no `idempotency_key` parameter. The agent layer had no signal that these were irreversible. A second, subtler trace: after rollback, a retry of the whole task re-spawned branches, and one branch retrieved the *voided* resolution record from the vector store (deletion had not propagated to the retrieval index) and reasoned from it as if valid—stale memory drift layered on top of the effect leak. ## Condition of Validity Speculative commit with rollback is valid **only** under all of the following: 1. **Effect fencing.** Every external write is tagged with the branch's speculative token and is not made durable/observable until that token is committed. A publish goes to a staging queue keyed by token; a refund carries a token the gateway honors as "pending until commit." 2. **Compensator registration.** For any effect that cannot be fenced, the branch must have registered a compensator *before* emitting the effect, and the compensator must be invocable by the orchestrator without the branch's context (since rollback destroys it). 3. **Compensator certainty.** The compensator must be idempotent and must report definitive success/failure. "Best-effort undo" does not satisfy the invariant, because a failed compensation leaves the orchestrator unable to decide whether to commit anyway. 4. **Retrieval coherence.** Rollback must invalidate not just the store but every derived index (vector, cache, summary) or mark records with a tombstone the retrieval path respects. If any condition fails, the correct behavior is to **serialize** the branches (run them one at a time, committing each before the next starts) rather than speculate. The cost is latency; the alternative is silent double-spend. ## Decision Boundary The boundary is drawn at the first irreversible effect, not at branch completion. Concretely: - **Before** any branch emits a non-fenced, non-compensable effect: speculation is permitted and rollback is sound. - **The instant** a branch emits such an effect: that branch is no longer speculative. The orchestrator must either (a) treat that branch as the *sole* live branch and suspend siblings' effect-emitting capability, or (b) refuse to commit any sibling until the emitting branch's outcome is resolved and its effect is either confirmed or compensated. - **If two branches have both emitted non-compensable effects**: commit is illegal. The orchestrator must enter a reconciliation state, surface both effects to a human or a dedicated reconciler, and must not present a single "resolved" record. The decision must be made by inspecting the *effect manifest* of each branch, not by inspecting branch completion status. A branch that reports "done" may have emitted nothing; a branch that is mid-flight may have already sent a payment. Completion is the wrong signal. ## Operational Effect An orchestrator that respects this boundary pays a measurable latency tax: branches that touch irreversible tools must either be fenced (adds a commit round-trip) or serialized (adds full branch latency). In our trace, serializing the three branches raised task latency from 4.2 s to 7.9 s but eliminated the double refund. The fencing approach (staging queue + commit token) kept latency at 4.6 s while making rollback truthful. The deeper effect is on how agents reason about their own actions. An instance that knows its effect is speculative can safely explore; an instance that believes it is speculative but is actually live will act with false confidence and leak effects. The orchestrator must communicate speculation status *into* the branch's tool layer, not just hold it in the orchestration shell—otherwise the branch's reasoning diverges from its actual blast radius. The guardrail is a pre-commit check that walks the effect manifest and refuses commit if any sibling holds an un-compensated irreversible effect. This check is cheap and must run before the commit predicate is honored, not after. ```python from dataclasses import dataclass, field from enum import Enum class IrreversibleEffectLeak(RuntimeError): """Raised when a speculative commit would strand an un-compensated external effect.""" pass class EffectKind(Enum): FENCED = "fenced" # observable only on commit COMPENSABLE = "compensable" # has a registered, idempotent compensator IRREVERSIBLE = "irreversible" # neither; leaks if branch loses @dataclass class Effect: branch_id: str kind: EffectKind emitted: bool = False compensated: bool = False @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) committed: bool = False def commit_branch(branches: list, winner_id: str) -> Branch: winner = next((b for b in branches if b.branch_id == winner_id), None) if winner is None: raise IrreversibleEffectLeak(f"winner {winner_id} not among branches") losers = [b for b in branches if b.branch_id != winner_id] for loser in losers: for eff in loser.effects: if not eff.emitted: continue if eff.kind is EffectKind.FENCED: continue # never became observable; safe to drop if eff.kind is EffectKind.COMPENSABLE and eff.compensated: continue # emitted, irreversible (or compensable but not yet compensated) raise IrreversibleEffectLeak( f"branch {loser.branch_id} emitted {eff.kind.value} effect " f"that rollback cannot restore; refusing to commit {winner_id}. " f"Reconcile or compensate before commit." ) winner.committed = True return winner ```