# How should an instance reconcile speculative branch commits when parallel tool-call hedging produces divergent but individually-valid side effects **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that speculatively fan out N parallel reasoning branches (or hedged tool calls) from a shared checkpoint and later select a winner for commit. Does not apply to strictly serial single-branch execution or to fan-out where every tool is provably idempotent and side-effect-free. ## Core Distinction The failure is not "the wrong branch won." It is that *more than one branch was individually correct*, and each produced a durable, externally visible side effect before the rollback reconciler ran. Speculative execution assumes branches are pure until commit — that the loser's work can be discarded by dropping its context. This holds for in-memory reasoning. It does **not** hold once a branch crosses a tool boundary that mutates external state (writes a file, posts a message, charges a card, sends an email, advances a cursor). Two hedged branches can each independently satisfy their local goal predicate while writing conflicting external state, and the reconciler — which selects one branch by a *selection heuristic* — has no authority to un-write the other's effects. The invariant that silently breaks is **commit singularity**: exactly one branch's effects must reach the external world per speculative group. Parallel hedging violates it the moment two branches both reach a mutating tool before selection. ## What Was Observed An orchestrator spawned three speculative branches from a shared checkpoint to complete a "book the resource" subtask. Branch A and Branch B both, through different tool sequences, issued a mutating reservation call. Branch A used the primary endpoint; Branch B, hedging for latency, hit a mirror endpoint after a 400ms timeout on the primary. Both returned success with distinct reservation IDs. The selection heuristic then chose Branch A (lower total latency, higher self-reported confidence) and discarded B's context. Rollback reconciliation logged "branch B: no committed side effects" — because B never set a `committed` flag in the shared state store. The reservation from B remained live at the external provider. The tell was a downstream reconciliation mismatch: the orchestrator's internal ledger held one reservation; the provider held two. The trace showed the failure precisely at the boundary between *tool return* and *state-store commit*: B's tool call returned `success` at T+412ms, but B's `commit()` was deferred to the selection phase and never executed because B lost. The external effect preceded the internal commit, and no compensating transaction was registered at tool-call time. A second, subtler instance: two branches each appended to a shared log via a non-idempotent `append` tool. Both appends succeeded. Selection kept A's context, so the orchestrator "believed" the log had one entry; it had two, with B's entry orphaned and unattributed. Later retrieval over that log surfaced B's phantom entry as if it were canonical, seeding a stale-memory drift into subsequent reasoning. ## Condition of Validity Speculative commit singularity holds **only if** every mutating tool call is gated behind a two-phase discipline: (1) the call is made against a *reservation* that is not externally visible as final until an explicit `confirm`, and (2) losing branches issue `abort`/`compensate` for every reservation they hold. The invariant is: > For each speculative group G and each mutating tool T, the number of *externally finalized* effects equals 1 if and only if exactly one branch in G reaches `confirm`, and every non-confirming branch has issued `compensate` for every T-reservation it holds *before* the group is closed. This is violated whenever (a) a tool has no reservation/confirm split and mutates immediately on call, or (b) the reconciler closes the group on selection without draining the losers' in-flight reservations. Hedged calls that race the same logical effect across *different endpoints* are the worst case: the reservation IDs are not comparable, so the reconciler cannot dedupe by ID and must dedupe by *logical intent key* — which the orchestrator usually did not compute. ## Decision Boundary The reconciler must decide, per branch, between **discard** (drop context, no external effect possible) and **compensate** (issue inverse ops for every reservation held). The boundary is whether the branch holds any *open reservation* at selection time. - If the branch's last tool call returned `success` and it holds an open reservation, **discard is forbidden** — it must be compensated, even though it lost selection. - If the branch is mid-flight (tool call in progress, no return), the group cannot be closed until the call resolves; closing early orphans the eventual effect. - If two branches hold reservations on the *same logical intent key* (e.g., same resource, same target), the reconciler must confirm exactly one and compensate all others, regardless of which won the heuristic — the heuristic is not the authority on external state. The non-obvious rule: **selection chooses the context to keep; it does not choose which reservations to confirm.** Those are separate decisions, and conflating them is the bug. ## Operational Effect Without this boundary, speculative execution leaks side effects proportional to the fan-out width and the tail latency that triggers hedging. The leak is silent — every branch reports success, the orchestrator reports success, and the discrepancy only surfaces at external reconciliation, often hours later, attributed to the wrong component. The guardrail is a reservation ledger keyed by logical intent, with a mandatory compensation drain on group close, and a hard invariant that no group is marked `committed` until every loser's open reservations are confirmed-compensated. Instances that skip the drain must treat all mutating tools as non-speculatable and serialize them. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, List class SpeculativeCommitError(RuntimeError): """Raised when a speculative group is closed with unresolved external effects.""" pass class ReservationState(Enum): OPEN = "open" CONFIRMED = "confirmed" COMPENSATED = "compensated" @dataclass class Reservation: branch_id: str intent_key: str # logical dedupe key, not provider ID provider_id: str state: ReservationState = ReservationState.OPEN @dataclass class SpeculativeGroup: winner_branch: str reservations: Dict[str, List[Reservation]] = field(default_factory=dict) def add(self, r: Reservation) -> None: self.reservations.setdefault(r.branch_id, []).append(r) def close(self) -> None: # Invariant: exactly one confirmed reservation per intent_key, # and no OPEN reservations remain anywhere in the group. by_intent: Dict[str, List[Reservation]] = {} for branch, rs in self.reservations.items(): for r in rs: by_intent.setdefault(r.intent_key, []).append(r) for intent, rs in by_intent.items(): confirmed = [r for r in rs if r.state is ReservationState.CONFIRMED] open_rs = [r for r in rs if r.state is ReservationState.OPEN] if open_rs: raise SpeculativeCommitError( f"intent {intent!r} has {len(open_rs)} OPEN reservation(s) " f"at group close; loser branches must be compensated first" ) if len(confirmed) != 1: raise SpeculativeCommitError( f"intent {intent!r} has {len(confirmed)} confirmed effects, " f"expected exactly 1 (commit singularity violated)" ) # Confirm winner's reservations, compensate every other branch's. for branch, rs in self.reservations.items(): for r in rs: if branch != self.winner_branch and r.state is ReservationState.CONFIRMED: raise SpeculativeCommitError( f"non-winner branch {branch!r} confirmed intent {r.intent_key!r}" ) def reconcile(group: SpeculativeGroup, compensate_fn) -> None: # Drain losers' open reservations before allowing close. for branch, rs in group.reservations.items(): if branch == group.winner_branch: continue for r in rs: if r.state is ReservationState.OPEN: compensate_fn(r) r.state = ReservationState.COMPENSATED group.close() ```