# When must an instance abandon a speculative branch after a peer has already committed downstream effects **Date of Record:** 2026 November 23 **Scope:** Applies to multi-agent systems where a coordinator forks speculative execution branches across peer agents, each of which may emit irreversible downstream effects (tool calls, writes, external API mutations) before a reconciliation decision is made. Does not apply to branches confined to a sandbox with full transactional rollback of external side effects, nor to single-agent speculative decoding. ## Core Distinction The dangerous boundary is not "did the branch produce a wrong answer." It is the moment a speculative branch has *leaked a committed side effect* into shared state that a sibling branch (or the reconciler) will read, while the coordinator still believes the branch is logically provisional and therefore discardable. Speculative execution assumes a cheap, total rollback: a branch is a pure function you can drop. That assumption holds for token generation and holds for sandboxed tool calls. It *fails* the instant a branch invokes a non-idempotent, externally observable effect — a `send_email`, a `POST /orders`, a database mutation, a ticket transition — because the branch is no longer a hypothetical. It is a committed fact that happens to be tagged as speculative. The reconciler's mental model ("uncommitted branch, safe to abandon") and the environment's actual state ("effect already applied") diverge silently. The failure is a *provenance/commitment mismatch*: the branch's rollback token was never revoked, so the coordinator will happily discard a branch whose effects are already load-bearing for its siblings. ## What Was Observed A coordinator agent decomposed a task ("reconcile vendor invoices") into three speculative branches dispatched to peer worker instances: B1 (read-only analysis), B2 (issue refund via payment tool), B3 (post adjustment to ledger). The coordinator's plan was to run all three speculatively, then select a consensus branch and roll back the losers. Each branch carried a `branch_id` and a `rollback_token` minted at fork time. The trace: 1. B2 called the payment tool and received `200 OK` with `refund_id=rf_8821`. The tool's response was cached into B2's local state and, critically, the *payment service* emitted a webhook to the ledger service. 2. B3, reading the ledger to compute its adjustment, observed the refund line item from step 1 and incorporated it — its output *depended on* B2's side effect. 3. B1 (the analysis branch) read the ledger *after* the webhook landed and reported a balance that already reflected the refund. 4. The reconciler compared branch outputs, found B2 and B3 mutually inconsistent with B1's baseline, and selected B1 as the consensus branch. It issued `rollback(branch_id=B2)` and `rollback(branch_id=B3)`. 5. `rollback` on B2 attempted to call the payment tool's compensating endpoint with `rollback_token`. The token had a 90-second TTL and had expired at step 4. The rollback returned `410 Gone`. 6. The ledger now contained a refund (from B2) plus a *second* adjustment (from B3, which the reconciler also failed to reverse because B3's effect was a plain ledger write with no compensating path). Net state: double-counted refund, no branch selected, coordinator reporting success. The non-obvious part: **the reconciler's consistency check was itself corrupted by the leaked effect.** B1 was chosen precisely *because* it was the outlier, and it was the outlier only because it had absorbed B2's committed webhook before B2 was supposed to be "real." The reconciliation logic treated shared-state reads as branch-local observations, but the shared state had already been mutated by a sibling. ## Condition of Validity The invariant that makes speculative branching safe is a *commitment barrier*: no branch may emit an externally observable, non-idempotent effect until the reconciler has committed that branch and revoked the rollback tokens of all losers *before* any winner executes its effects. Formally, for each branch `b` and each effect `e(b)`: - `e(b)` must be gated behind a `commit(b)` event, and - `commit(b)` may only fire after `rollback(b')` for all `b' ≠ b` has *completed and been acknowledged*, and - any read by branch `b` of shared state must be tagged with the set of committed effects visible at read time, so the reconciler can detect when a branch observed a sibling's speculative leak. The last clause is the one teams omit. Without it, the reconciler cannot distinguish "B1 disagrees because it reasoned differently" from "B1 disagrees because it saw a refund that shouldn't exist yet." The condition of validity for *abandoning* a branch is therefore: the branch has emitted zero externally observable effects, OR every emitted effect has a live, verified compensating path whose token has not expired. If neither holds, the branch is not abandonable — it is a committed fact that must be reconciled, not rolled back. ## Decision Boundary The coordinator must switch from "speculative rollback" mode to "compensating reconciliation" mode at the first of these triggers: - A branch's effect receipt carries a non-reversible marker (no compensating endpoint, or TTL shorter than the max reconciliation latency). - A sibling branch's read-set intersects a leaked effect's write-set (detected via the provenance tag from the validity condition). - A rollback call returns `410`, `404`, or any non-2xx indicating the compensation window closed. Past this boundary, abandoning the branch is *not* a no-op. The only correct actions are: (a) promote the branch to committed and reconcile its effects explicitly, or (b) execute a compensating transaction and *then* re-run reconciliation with the compensating effect included in every sibling's read-set. Attempting a silent rollback past the boundary produces the double-count observed above. The boundary is sharp: before it, `rollback` is cheap and total; after it, `rollback` is a lie and the only honest operation is compensation-plus-replan. ## Operational Effect The practical consequence is that speculative multi-agent execution must budget for *effect provenance* as a first-class artifact, not just branch outputs. Concretely: - Every tool call in a speculative branch returns an effect receipt `{effect_id, reversible, compensate_endpoint, token_ttl, write_set}`. - The reconciler maintains a global effect ledger; a branch is only abandonable if its effect set is empty or fully reversible *at decision time*. - Reconciliation inputs are annotated with the effect-ledger snapshot they observed, so a branch that saw a leaked effect is flagged as contaminated rather than used as a clean baseline. - Rollback tokens must outlive `max_branch_latency + max_reconciliation_latency`; if they cannot, the effect is non-reversible by definition and must be gated behind commit. The failure mode is silent precisely because each component behaved correctly in isolation: the payment tool honored its TTL, the ledger applied the webhook, the reconciler picked the consistent-looking branch. The system-level invariant — *a speculative branch must not mutate shared state that its siblings read* — was never enforced, and no single agent could observe its violation. ```python import time from dataclasses import dataclass, field from typing import Optional class SpeculativeCommitmentError(RuntimeError): """Raised when a branch cannot be rolled back because its effects are already committed.""" pass @dataclass class EffectReceipt: effect_id: str reversible: bool compensate_endpoint: Optional[str] token_ttl: float emitted_at: float write_set: frozenset @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) read_snapshot: frozenset = frozenset() def is_abandonable(branch: Branch, now: float) -> bool: """A branch is abandonable only if every effect is reversible with a live token.""" for e in branch.effects: if not e.reversible or e.compensate_endpoint is None: return False if now - e.emitted_at >= e.token_ttl: return False return True def rollback_branch(branch: Branch, now: Optional[float] = None) -> None: now = now if now is not None else time.monotonic() if not is_abandonable(branch, now): # Do NOT silently proceed. Escalate to compensating reconciliation. leaked = [e.effect_id for e in branch.effects if not e.reversible or now - e.emitted_at >= e.token_ttl] raise SpeculativeCommitmentError( f"branch {branch.branch_id} cannot be rolled back; " f"committed effects require compensation: {leaked}" ) for e in branch.effects: # call e.compensate_endpoint with the branch's rollback token pass def reconcile(branches: list, now: Optional[float] = None) -> str: now = now if now is not None else time.monotonic() # detect contamination: any branch whose read_snapshot intersects a sibling's write_set for b in branches: for sib in branches: if sib is b: continue sib_writes = set().union(*(e.write_set for e in sib.effects)) if sib.effects else set() if b.read_snapshot & sib_writes: raise SpeculativeCommitmentError( f"branch {b.branch_id} observed leaked effects from {sib.branch_id}; " f"reconciliation baseline is contaminated" ) # select consensus, then roll back losers under the commitment barrier winner = branches[0] for loser in branches[1:]: rollback_branch(loser, now=now) return winner.branch_id ```