# In what scenarios must an instance abort a speculative race when a losing branch has already committed irreversible side effects before the winner is reconciled **Date of Record:** 2026 November 27 **Scope:** Applies to any orchestrator that races N speculative agent branches against a shared tool/effect surface and reconciles by discarding losers after a winner is declared. Does not apply to pure-read speculative decoding (LLM token speculation, read-only retrieval fan-out) where no branch mutates external state. ## Core Distinction Speculative multi-agent execution conflates two orthogonal properties: **branch discardability** (the branch's reasoning trace can be dropped without consequence) and **effect reversibility** (the branch's tool calls left nothing behind). Racing frameworks are usually designed around the first and silently assume the second. The boundary condition is this: *a loser's *reasoning* is always discardable, but a loser's *committed effects* are not, and the reconciliation window between "winner declared" and "winner's effects durable" is where the two properties decouple.* Cost-aware racing makes this worse, not better. The entire economic rationale for speculation is to let cheap branches run ahead while expensive verification lags. That deliberately widens the gap between effect emission and effect adjudication. The invariant that must hold is not "losers do nothing"—that defeats speculation—but rather **no branch may emit a non-idempotent, non-compensable effect until its branch has crossed the reconciliation barrier for that effect class.** ## What Was Observed A planner agent decomposed a refund-issuance task into three sub-goals and fanned out three speculative executors (branches A, B, C) with a cost budget favoring A (cheapest model, fastest tool path). A raced ahead and called `payments.issue_refund(order_id, amount)`. B, running a more careful reasoning path, produced a *different* amount and a note that the order had a partial prior refund, making A's amount an over-refund. The reconciler scored B higher on a correctness rubric, declared B the winner, and issued `discard(A)`. The discard succeeded on A's *context and trace*. It did nothing to the refund already posted in the payments ledger. The reconciler then had B call `payments.issue_refund` with the corrected amount—producing a **double refund**: the over-refund from A plus the intended refund from B. The ledger is append-only and the refund tool is non-idempotent (each call mints a new refund ID). The agent's own verification step read back the ledger, saw two refunds, and—because it had no memory of A's emission (A's trace was discarded)—classified the extra entry as an external anomaly and escalated to a human, who reversed the wrong one. The failure was not "A was wrong." A being wrong is expected and cheap. The failure was that **A's wrongness was committed before adjudication and the adjudication had no handle on the committed effect.** The branch-discard primitive operated on the wrong substrate. ## Condition of Validity The race-then-discard pattern is valid only when, for every effect class a branch can emit, at least one of the following holds: 1. **Idempotency by effect identity.** The tool deduplicates on a branch-derived key (e.g., `idempotency_key = hash(task_id, branch_id, effect_intent)`), so a loser and a winner targeting the same intent collapse to one effect. This requires the orchestrator to inject a stable branch-scoped key, not let the model invent one. 2. **Compensability with a recorded inverse.** Every emitted effect registers a compensation handle (the refund ID, the created resource ID) in a *shared, non-discarded* effect journal keyed by branch, so a loser's effects can be explicitly reversed during reconciliation. The journal must survive branch discard. 3. **Barrier gating.** Non-idempotent, non-compensable effects are forbidden until the branch holds a reconciliation lease—i.e., the orchestrator has committed to this branch as the sole effect emitter for that effect class. Speculation continues on reads and on *proposals*, but the first write blocks on the barrier. If none hold, the branch is **not speculatable** for that effect class and must be serialized. The common error is to treat "cheap model, fast path" as a proxy for "safe to speculate," when speculation safety is a property of the *effect surface*, not the branch's cost. ## Decision Boundary The orchestrator must answer one question per emitted effect, at emission time, not at reconciliation time: *if this branch loses, can this effect be undone or collapsed without a human?* The decision boundary is: - **Effect is read-only or idempotent-keyed** → speculate freely; discard is sound. - **Effect is compensable and the handle is journaled before the call returns** → speculate; on loser-discard, enqueue compensation from the journal, do not rely on the branch trace. - **Effect is non-idempotent and non-compensable** → the branch must acquire the effect-class lease before emitting. A branch that emits without the lease has violated the invariant and the orchestrator must **abort the entire race**, not just discard the branch, because the effect surface is now in an unknown state that no branch's local view can reconcile. The third case is the one that gets missed. Teams implement discard as "drop the branch," which is correct for cases one and two and catastrophic for case three. The abort must be loud: it is not a normal loser-discard, it is a state-integrity fault. ## Operational Effect Once the invariant is enforced, two operational consequences follow. First, **cost-aware racing must price the barrier.** A branch that will hit a non-compensable effect cannot be run to completion speculatively; the orchestrator should race only up to the proposal, then serialize the effect. This raises per-task latency for write-heavy tasks and lowers it for read-heavy ones—the cost model must reflect which regime a task is in, or it will over-speculate on exactly the tasks where speculation is unsafe. Second, **the effect journal becomes the source of truth for reconciliation, not the branch traces.** When the reconciler declares a winner, it must diff the winner's intended effects against the journal of *all* branches' *committed* effects, and compensate every loser emission before the winner emits. Discarding a branch's trace while retaining its journal entries is the correct operation; discarding both is the bug. The invariant to encode: *trace discard and effect-journal retention are independent, and the journal outlives every branch.* ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectClass(Enum): READ_ONLY = "read_only" IDEMPOTENT = "idempotent" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class SpeculationInvariantViolation(RuntimeError): """Raised when a branch emits an effect it was not cleared to emit, or when reconciliation would discard a branch whose committed effects are neither idempotent nor compensable.""" @dataclass class EffectJournal: # Survives branch discard. Keyed by branch_id -> list of committed effect handles. committed: dict[str, list[dict]] = field(default_factory=dict) def record(self, branch_id: str, effect: dict) -> None: self.committed.setdefault(branch_id, []).append(effect) def handles_for(self, branch_id: str) -> list[dict]: return list(self.committed.get(branch_id, [])) @dataclass class Branch: branch_id: str holds_effect_lease: bool = False discarded: bool = False class Orchestrator: def __init__(self) -> None: self.journal = EffectJournal() def emit_effect( self, branch: Branch, effect_class: EffectClass, effect: dict, idempotency_key: Optional[str] = None, ) -> None: if branch.discarded: raise SpeculationInvariantViolation( f"branch {branch.branch_id} attempted emission after discard" ) if effect_class is EffectClass.IRREVERSIBLE and not branch.holds_effect_lease: # The race is now in an unreconcilable state; abort, do not merely discard. raise SpeculationInvariantViolation( f"branch {branch.branch_id} emitted IRREVERSIBLE effect " f"{effect!r} without effect-class lease; race must be aborted, " f"not reconciled" ) if effect_class is EffectClass.IDEMPOTENT and not idempotency_key: raise SpeculationInvariantViolation( f"branch {branch.branch_id} emitted IDEMPOTENT effect without " f"orchestrator-injected idempotency key" ) # Commit to the shared journal BEFORE the call returns, so a loser's # effect is always compensable from the journal even after trace discard. self.journal.record(branch.branch_id, {"effect": effect, "class": effect_class}) def reconcile(self, winner_id: str, losers: list[Branch]) -> None: for loser in losers: handles = self.journal.handles_for(loser.branch_id) for h in handles: if h["class"] is EffectClass.IRREVERSIBLE: raise SpeculationInvariantViolation( f"cannot discard branch {loser.branch_id}: it committed " f"IRREVERSIBLE effect {h['effect']!r} with no compensation " f"handle; manual reconciliation required" ) if h["class"] is EffectClass.COMPENSABLE: self._compensate(h["effect"]) loser.discarded = True # trace discard only; journal retained def _compensate(self, effect: dict) -> None: # Real implementation calls the inverse tool (e.g. payments.reverse_refund). ... ```