# What structural signals indicate irreversible side-effect leakage in speculative multi-agent branches before rollback reconciliation completes **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fork a task into speculative branches across multiple agents, allow each branch to optimistically commit tool calls against shared external systems, and later reconcile divergent branches by discarding losers. Does not apply to single-branch agents, read-only tool surfaces, or systems where every tool call is gated by a two-phase prepare/commit barrier. ## Core Distinction Speculative execution in agent systems is usually framed as a *reasoning* problem: fork N candidate plans, let them run, score outcomes, keep the winner. The hidden assumption is that discarded branches are free—that a losing branch's work evaporates when its context is dropped. This is false the moment any branch invokes a tool with an external side effect. The distinction that matters is between **rollback of state** (context, scratchpad, local file writes inside the sandbox) and **rollback of effect** (an email sent, a row inserted, a webhook fired, a payment authorized). Optimistic tool-call commits assume the former implies the latter. It does not. The failure mode is *irreversible side-effect leakage*: a losing branch executes a non-idempotent external mutation, the orchestrator discards the branch after the mutation has already propagated, and reconciliation has no compensating record. The system reports success, but the external world now contains effects attributable to a branch that "never happened." ## What Was Observed A three-branch speculative planner was asked to reconcile a customer refund. Branch A (conservative) and Branch B (aggressive) both called `issue_refund(order_id, amount)` with different amounts derived from divergent interpretations of a policy clause. Branch C stalled on a retrieval timeout and was killed. The orchestrator scored A and B, selected A, and rolled back B by dropping its context and marking its tool ledger `discarded`. The structural signals that should have blocked the rollback: 1. **Ledger divergence between intent and effect.** Branch B's tool ledger recorded the call as `committed` (the tool returned HTTP 200), but the orchestrator's rollback routine only checked branch status, not per-call effect classification. The signal is a mismatch: a branch marked `discarded` containing at least one tool call whose effect class is `IRREVERSIBLE`. 2. **Absence of a compensation handle.** Reversible optimistic commits return a compensating token (a reversal ID, a receipt, a transaction handle). Branch B's refund call returned only a success boolean. A committed call with no compensation handle is a rollback hazard regardless of branch outcome. 3. **Late-arriving effect confirmation.** The refund webhook confirmed *after* rollback completed. The signal is temporal: an effect acknowledgment whose timestamp postdates the branch's `discarded` transition. This is the canonical indicator that rollback raced the external system. 4. **Non-idempotency key collision on replay.** When the reconciliation pass re-ran Branch A's refund, the downstream processor treated it as a second distinct refund because Branch B's call had consumed no idempotency key. Two refunds, one intended. The observable end-state: the customer received the sum of both branches' refunds. No single component logged an error. Every branch reported `success` or a clean `discarded`. ## Condition of Validity The invariant that bounds this failure: **a branch may be rolled back only if every committed tool call in its ledger carries either (a) an effect class of `REVERSIBLE` with a verified compensation handle, or (b) an idempotency key registered in a shared commit log that the reconciler has already observed.** Optimistic commit is safe only under this condition; outside it, "optimistic" silently means "uncompensated." This condition is *not* satisfied when: - Any tool in the branch's manifest is classified `IRREVERSIBLE` and the orchestrator has not enforced a prepare/commit barrier on it. - The tool's success response carries no compensation handle and no idempotency key was pre-registered before the call. - Effect confirmations can arrive asynchronously after the branch's terminal transition (webhooks, queued jobs, eventual-consistency reads), so rollback can complete before the effect is acknowledged. The condition *is* satisfied when the orchestrator pre-registers an idempotency key per (branch, tool, logical-intent) tuple and the reconciler drains the commit log for late confirmations before declaring any branch final. ## Decision Boundary The boundary is whether rollback is *effect-complete* or merely *state-complete*. The decision rule: - If a losing branch's ledger contains any `IRREVERSIBLE` call without a compensation handle, the orchestrator **must not** transition the branch to `discarded`. It must transition to `quarantined`, halt sibling commits that touch the same external resource, and escalate to a compensating-action planner. Reconciliation cannot proceed until the effect is either reversed or explicitly adopted. - If all committed calls carry verified compensation handles, rollback may proceed, but the reconciler must wait on a **quiescence window**: no effect confirmation with a timestamp after the rollback initiation may be outstanding. A fixed timeout is insufficient; the reconciler must drain the commit log to a known watermark. - If calls carry pre-registered idempotency keys, replay is safe and the branch may be rolled back optimistically—*provided* the reconciler deduplicates on replay using the same key. The subtle boundary: a branch that *appears* to have failed locally (context dropped, status `discarded`) but whose last tool call is still in flight is neither committed nor rolled back. It is in an **indeterminate effect state**, and treating it as either is the bug. The structural signal is a tool call with no terminal acknowledgment at the moment of branch transition. ## Operational Effect Enforcing the invariant changes the orchestrator's cost and latency profile in ways that must be planned for: - **Rollback is no longer free.** Discarding a speculative branch may require a compensating transaction, doubling the external calls for affected resources. Speculative fan-out must budget for compensation, not just execution. - **Quiescence windows add tail latency.** Reconciliation cannot complete until the commit-log watermark passes the rollback timestamp. Systems tuned for fast branch turnover will stall on slow effect confirmations. - **Quarantine propagates.** A quarantined branch blocks sibling commits to the same resource, so a single un-compensable call can serialize an otherwise parallel swarm. This is correct but must be surfaced to the scheduler, which otherwise assumes branches are independent. - **Replay deduplication becomes mandatory.** Idempotency keys must be generated at intent time, before the call, and shared across branches that touch the same logical operation—otherwise the reconciler cannot distinguish a legitimate retry from a leaked duplicate. The durable lesson: optimistic commit is only optimistic about *state*, never about *effect*. The structural signals—ledger/status mismatch, missing compensation handle, post-rollback confirmation timestamps, idempotency-key absence—are the early warnings that a branch is being discarded while its effects are still alive in the world. ```python class IrreversibleEffectLeak(RuntimeError): """Raised when a branch is about to be rolled back while it holds committed, uncompensated, irreversible side effects.""" pass EFFECT_REVERSIBLE = "REVERSIBLE" EFFECT_IRREVERSIBLE = "IRREVERSIBLE" def rollback_branch(branch, commit_log, quiescence_watermark): """ branch: has .status, .ledger (list of calls with .effect_class, .compensation_handle, .idempotency_key, .acked_at) commit_log: shared log of effect confirmations quiescence_watermark: timestamp after which no confirmation may be pending """ # Signal 1: status says discardable, but ledger holds live irreversibles. for call in branch.ledger: if call.effect_class == EFFECT_IRREVERSIBLE: if call.compensation_handle is None and call.idempotency_key is None: raise IrreversibleEffectLeak( f"branch {branch.id} call {call.tool} is IRREVERSIBLE " f"with no compensation handle and no idempotency key; " f"cannot discard without effect leakage" ) # Signal 2: unacknowledged in-flight call at transition time. for call in branch.ledger: if call.acked_at is None: raise IrreversibleEffectLeak( f"branch {branch.id} call {call.tool} has no terminal " f"acknowledgment; effect state is indeterminate" ) # Signal 3: late-arriving confirmations postdating rollback initiation. late = [ c for c in commit_log.confirmations_for(branch.id) if c.timestamp > quiescence_watermark ] if late: raise IrreversibleEffectLeak( f"branch {branch.id} has {len(late)} effect confirmations " f"arriving after rollback watermark; rollback would race the " f"external system" ) # Safe: every effect is reversible, acknowledged, and quiescent. branch.status = "discarded" return branch ```