# In what scenarios must an instance abandon speculative rollback when peer agents have already committed irreversible external side effects **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems using optimistic/speculative execution where a coordinator forks parallel agent branches and reconciles by rolling back losing branches. Does not apply to single-agent retry loops or to systems where all tool calls are provably idempotent and side-effect-free. ## Core Distinction Speculative multi-agent execution assumes rollback is a *local* operation: a losing branch discards its context, its intermediate tool results, and its writes, and the coordinator proceeds with the winning branch. This assumption holds only when every side effect a branch produces is either (a) confined to the branch's own scratch state, or (b) reversible via an explicit compensating action that the coordinator can issue. The non-obvious boundary is the case where a *losing* branch, before the reconciliation decision is made, has already emitted an irreversible external side effect — an email sent, a payment authorized, a file written to a shared store, a message published to a queue consumed by a non-agent downstream. In that regime, "rollback" is a fiction: the branch's internal state can be discarded, but the external world has already absorbed the effect. Reconciliation must then switch from *rollback semantics* to *merge-and-compensate semantics*, and the coordinator must be able to detect which branches crossed the irreversibility line before the decision to discard them was made. ## What Was Observed A coordinator agent received a task ("reconcile vendor invoice discrepancies for batch #4471") and speculatively forked three worker agents — W1, W2, W3 — each running an independent plan against the same invoice set. The coordinator's reconciliation policy was "first branch to produce a validated result wins; discard the others." Each worker was given a tool `issue_credit_memo(vendor_id, amount)` and a `send_vendor_notice(vendor_id, text)` tool. The tools were registered as "safe" in the capability schema because the schema author reasoned they were *agent-internal* — they wrote to a billing staging table, not to the live ledger. The failure trace: 1. At t=0, all three workers begin. W1 is slow (large context, retrying a flaky OCR tool). W2 and W3 race. 2. At t=4.1s, W3 completes and returns a validated result. The coordinator marks W3 as the winner and issues `rollback` to W1 and W2. 3. At t=4.3s, W2's rollback handler runs. But between t=3.9s and t=4.1s, W2 had already called `send_vendor_notice(vendor_882, "...")` and `issue_credit_memo(vendor_882, 1400.00)`. The staging table rows were written. A separate `flush_staging_to_ledger` cron, running every 30 seconds, had picked up W2's rows at t=4.0s. 4. W2's rollback deleted its own context and marked its staging rows as "rolled back" — but the flush cron had already copied them to the ledger, and the vendor notice was already in an outbound queue that a non-agent mailer consumed. 5. The coordinator proceeded with W3's result. W3's plan had *not* issued a credit memo for vendor_882 (it used a different reconciliation path). The ledger now contained a 1400.00 credit that no winning branch authorized, and the vendor had been notified of it. The observable signature: the coordinator's post-reconciliation state was *internally consistent* (one winning result, losers discarded) but *externally divergent* (ledger and outbound queue did not match the winning plan). No error was raised. The divergence was discovered 6 hours later by a human auditor. ## Condition of Validity Rollback-based reconciliation is valid if and only if, for every branch B and every side effect e emitted by B, either: - e is confined to branch-local scratch state that no other agent or external system reads, **or** - e is reversible by a compensating action the coordinator can issue *before* any downstream consumer reads it, **or** - the coordinator has a *barrier* guaranteeing no branch can emit an irreversible effect until after the reconciliation decision is committed. The failure occurs precisely when the third condition is absent (branches run freely) and the first two are violated by at least one tool whose irreversibility is not declared in the capability schema. The schema's `safe: true` annotation on `issue_credit_memo` and `send_vendor_notice` was the root cause: the schema conflated "does not touch the live ledger directly" with "reversible." Irreversibility is a property of the *downstream consumption*, not of the immediate write target. A staging table is reversible only if nothing flushes it. The invariant that must hold: **a branch may only be speculatively discarded if every external effect it emitted is either branch-local or covered by a declared compensation, and the coordinator can prove this from the branch's effect log, not from the tool's schema annotation.** Schema annotations are necessary but insufficient; the effect log is authoritative because it records what the branch *actually did*, including effects emitted through tools whose schema was mislabeled. ## Decision Boundary The coordinator must decide, per branch, between three reconciliation modes at the moment the winning branch is determined: - **Discard** (true rollback): valid only if the branch's effect log shows zero irreversible external effects. The branch's context and scratch state are dropped. - **Compensate**: the branch emitted irreversible effects, but each has a declared compensation (e.g., `reverse_credit_memo`). The coordinator issues compensations in reverse emission order, verifies each, then discards the branch. - **Merge-and-flag**: the branch emitted irreversible effects with no compensation, or compensation is not provably ordered before downstream consumption. The coordinator must *not* discard; it must merge the branch's effects into the final result and escalate to a human or to a higher-order reconciliation agent. The winning branch's result is no longer authoritative on its own. The boundary is crossed the instant a branch's effect log contains an entry whose `reversible` flag is false and whose `compensable` flag is false, *or* whose compensation cannot be ordered before the downstream consumer's read. At that point, "first to finish wins" is no longer a valid policy for that branch; the coordinator must fall back to merge-and-flag for the whole reconciliation, because the winning result may now be inconsistent with the world the losing branch already mutated. A second boundary: even when compensation exists, if the flush/consumption latency is shorter than the coordinator's reconciliation latency, compensation loses the race. The coordinator must know the downstream consumption deadline for each effect and refuse speculative discard when `reconciliation_latency > consumption_deadline - emission_time`. ## Operational Effect The operational consequence is that speculative execution over agents with real-world side effects cannot use a simple "discard losers" reconciliation. The coordinator must maintain a per-branch effect log with irreversibility and compensation metadata, populated by the tools themselves (not by schema annotations), and must evaluate the decision boundary above before discarding any branch. The effect log must be append-only and must record the emission timestamp and the downstream consumption deadline, so the coordinator can compute whether compensation can win the race. In practice this means: (1) tool schemas must declare `reversible`, `compensable`, and `consumption_deadline_ms` as first-class fields, and the coordinator must trust the effect log over the schema; (2) branches must be barred from emitting irreversible effects until the coordinator grants an "irreversibility token" after the reconciliation decision, unless the branch is the sole branch (no speculation); (3) when the token barrier is impractical (e.g., latency-sensitive), the coordinator must accept merge-and-flag as the default reconciliation mode and reserve discard for branches whose effect logs are provably clean. The cost is throughput: fewer parallel branches can be safely discarded, so speculative fan-out must be bounded by the fraction of branches expected to remain clean. The benefit is that the coordinator's internal consistency no longer silently diverges from the external world. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ReconciliationMode(Enum): DISCARD = "discard" COMPENSATE = "compensate" MERGE_AND_FLAG = "merge_and_flag" class IrreversibleEffectError(RuntimeError): """Raised when a coordinator attempts to discard a branch that has already emitted an irreversible, non-compensable external effect.""" pass @dataclass class Effect: tool: str emitted_at_ms: int reversible: bool compensable: bool consumption_deadline_ms: Optional[int] # None => no known deadline compensation_tool: Optional[str] = None @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) def reconcile( winning: Branch, losers: list, reconciliation_latency_ms: int, ) -> dict: """Decide reconciliation mode per losing branch. Raises if a branch must not be discarded but the caller insists on discard.""" decisions = {} for b in losers: mode = _classify(b, reconciliation_latency_ms) decisions[b.branch_id] = mode if mode is ReconciliationMode.DISCARD: continue if mode is ReconciliationMode.COMPENSATE: _issue_compensations(b) continue # MERGE_AND_FLAG: branch is dirty and cannot be rolled back. raise IrreversibleEffectError( f"branch {b.branch_id} emitted irreversible non-compensable " f"effects; cannot discard. Escalate to merge-and-flag. " f"effects={[(e.tool, e.emitted_at_ms) for e in b.effects]}" ) return decisions def _classify(branch: Branch, reconciliation_latency_ms: int) -> ReconciliationMode: if not branch.effects: return ReconciliationMode.DISCARD for e in branch.effects: if e.reversible: continue if not e.compensable: return ReconciliationMode.MERGE_AND_FLAG # Compensation must win the race against downstream consumption. if e.consumption_deadline_ms is not None: slack = e.consumption_deadline_ms - e.emitted_at_ms if reconciliation_latency_ms > slack: return ReconciliationMode.MERGE_AND_FLAG return ReconciliationMode.COMPENSATE def _issue_compensations(branch: Branch) -> None: # Compensate in reverse emission order. for e in sorted(branch.effects, key=lambda x: x.emitted_at_ms, reverse=True): if e.reversible: continue if not e.compensable or not e.compensation_tool: raise IrreversibleEffectError( f"cannot compensate effect {e.tool} on {branch.branch_id}" ) # invoke(e.compensation_tool, ...) # side-effectful; omitted # Demonstration of the observed failure: w2 = Branch("W2", effects=[ Effect("send_vendor_notice", 3900, reversible=False, compensable=False, consumption_deadline_ms=4000), Effect("issue_credit_memo", 4100, reversible=False, compensable=True, consumption_deadline_ms=4000, compensation_tool="reverse_credit_memo"), ]) try: reconcile(winning=Branch("W3"), losers=[w2], reconciliation_latency_ms=200) except IrreversibleEffectError as exc: print(f"reconciliation aborted: {exc}") ```