# How should an instance reconcile speculative branch divergence when rollback cost exceeds forward-hedge cost mid-execution **Date of Record:** 2026 November 30 **Scope:** Applies to any orchestrator that forks parallel speculative agent branches (hedged execution) over a shared tool/effect surface and must decide, at a mid-flight checkpoint, whether to roll back a losing branch or carry it forward as a hedge. Does not apply to read-only fan-out where branches have no side effects, nor to single-branch retry logic. ## Core Distinction There are two economically distinct ways to "abandon" a speculative branch. **Rollback** means undoing its committed side effects (reverting writes, releasing locks, compensating external calls) so the branch's state contribution vanishes. **Forward-hedge** means leaving the branch's partial effects in place and continuing to pay its marginal token/tool cost because the probability-weighted value of it winning later still exceeds the cost of keeping it alive. These are not the same decision, and the common failure is treating "this branch is losing" as equivalent to "kill this branch." A branch can be losing on current evidence yet cheaper to hedge than to unwind—and the orchestrator's rollback ledger is usually the thing that decides, not the branch's score. The non-obvious boundary: **rollback is not free and is not instantaneous.** It is itself a multi-step agent operation with its own failure modes, its own token budget, and its own divergence risk. When the compensation cost of a branch exceeds its remaining forward cost, the correct action is to *stop scoring it as a candidate but keep paying for it as a hedge*—a state the orchestrator must represent explicitly or it will double-count the branch's effects during reconciliation. ## What Was Observed A three-branch speculative planner (`A`, `B`, `C`) forks at step 4 of a 12-step task. Each branch has executed 3 tool calls with external effects: `A` reserved an inventory row, `B` sent a confirmation email, `C` wrote a draft record. At the step-7 checkpoint the scorer ranks `A=0.71, B=0.22, C=0.09` and the orchestrator elects to roll back `B` and `C`. The rollback of `B` requires a compensating "send correction / retract" tool call. That call is itself non-deterministic: the email provider returns `202 Accepted` but the retraction may or may not land before the recipient reads it. The orchestrator's rollback routine treats `202` as success and marks `B` reverted. It then reconciles `A`'s branch against the shared state and finds a phantom conflict: `B`'s retraction had *also* touched the inventory row (the email referenced a reservation), and the retraction's late-arriving write now races `A`'s commit. The reconciliation sees a write it did not author and aborts `A` with a spurious `StateConflict`, collapsing the only surviving branch. The trace, condensed: 1. Checkpoint at step 7 → score → elect rollback of `B`, `C`. 2. `B.rollback()` issues retraction; provider returns `202`; orchestrator records `B: reverted`. 3. `C.rollback()` issues draft-delete; succeeds synchronously; `C: reverted`. 4. `A` proceeds to commit inventory row. 5. Retraction's compensating write (delayed ~1.4s) lands on the same row. 6. `A.reconcile()` sees foreign write → raises `StateConflict` → branch `A` aborted. 7. Orchestrator has zero live branches; task fails at step 7 despite `A` having been correct. The root cause is not the race per se. It is that the orchestrator modeled rollback as a *boolean* (`reverted: true`) rather than as a *pending, fallible operation with a completion predicate*. The `202` was interpreted as terminal when it was advisory. The reconciliation invariant "no foreign writes during commit" was enforced against a branch the orchestrator believed dead but which was still emitting effects. ## Condition of Validity The "roll back the losers" heuristic is only valid when **all** of the following hold at the decision checkpoint: - The compensating operation for each losing branch is **synchronous and verifiable** (returns a terminal success that is causally prior to the winner's commit), OR - The winner's commit is **quiesced** (no shared-resource writes) until every rollback's completion predicate is satisfied, AND - The rollback cost `R_i` (tokens + tool latency + probability-of-incomplete-retraction × expected damage) is **less than** the forward-hedge cost `H_i` (remaining marginal cost of keeping branch `i` alive). When the compensating call is asynchronous-advisory (`202`), the second condition is the only safe one: you must gate the winner on a *reconciliation barrier* that waits for the loser's completion predicate, not on a fire-and-forget acknowledgment. When `R_i > H_i`—e.g., the retraction is expensive, slow, or itself risky—the correct move is to keep the branch alive as a hedge and mark it `HEDGED`, excluded from winner-selection but included in the reconciliation barrier's expected-writer set. ## Decision Boundary The boundary is a cost comparison evaluated per branch at each checkpoint, not once at fork time: ``` rollback_now iff R_i < H_i AND compensation_is_verifiable hedge iff R_i >= H_i OR compensation_is_advisory_only ``` Two failure directions: - **Over-rollback** (the observed case): treating advisory acknowledgments as terminal, and treating "losing" as "cheap to kill." Produces phantom reconciliation conflicts and, worse, silent incomplete retractions that corrupt the winner's view of shared state. - **Over-hedge**: keeping every branch alive because rollback is scary. This exhausts the token budget and, critically, leaves multiple live writers on shared resources, so the *reconciliation barrier* must serialize them—which reintroduces the very contention rollback was meant to avoid. The invariant that bounds both: **a branch's effect on shared state is governed by its lifecycle state, and the lifecycle state must be a lattice with explicit `HEDGED` and `ROLLBACK_PENDING` members, not a boolean.** `ROLLBACK_PENDING` branches are still writers; the winner's commit must wait on them. `HEDGED` branches are still writers too, but their writes are *expected* and the reconciler must attribute them rather than abort. Only `REVERTED_VERIFIED` branches are guaranteed silent. ## Operational Effect With the boolean model, the orchestrator's reconciliation invariant ("abort on foreign write") is correct only if every non-winner is provably silent—which the boolean model cannot guarantee. The practical consequence is a class of task failures where the *correct* branch is killed by the *cleanup* of an *incorrect* one, and the failure is misattributed to "model divergence" rather than to the rollback ledger. With the lattice model, three things change: 1. The winner's commit is gated on a **reconciliation barrier** that awaits completion predicates of all `ROLLBACK_PENDING` branches, with a bounded wait. On timeout the barrier escalates to `HEDGED` rather than proceeding. 2. The reconciler distinguishes **expected writers** (from `HEDGED` and `ROLLBACK_PENDING` branches, attributed by branch id) from **foreign writers** (unattributed, genuinely anomalous). Only the latter trigger `StateConflict`. 3. The cost comparison is re-evaluated at every checkpoint, so a branch that becomes cheap to roll back later is rolled back later, and a branch that becomes expensive to roll back is downgraded to `HEDGED` rather than force-unwound. The cost-aware hedge is thus not a fallback—it is the *default* whenever rollback's completion predicate cannot be established synchronously. The orchestrator must be able to answer, for every losing branch at every checkpoint: *is this branch silent, pending, or hedged, and what is the evidence?* A `202` is not evidence of silence. ```python from __future__ import annotations import time from dataclasses import dataclass, field from enum import Enum from typing import Callable, Dict, Optional class RollbackLedgerError(RuntimeError): """Raised when a branch lifecycle transition violates the reconciliation invariant.""" class BranchState(Enum): LIVE = "live" ROLLBACK_PENDING = "rollback_pending" REVERTED_VERIFIED = "reverted_verified" HEDGED = "hedged" ABORTED = "aborted" @dataclass class Branch: branch_id: str score: float rollback_cost: float # R_i: tokens + latency + risk-adjusted damage forward_cost: float # H_i: remaining marginal cost of keeping alive compensation_verifiable: bool # True iff completion predicate is synchronous state: BranchState = BranchState.LIVE completion_predicate: Optional[Callable[[], bool]] = None effects: set = field(default_factory=set) class SpeculativeOrchestrator: def __init__(self, barrier_timeout_s: float = 5.0) -> None: self.branches: Dict[str, Branch] = {} self.barrier_timeout_s = barrier_timeout_s def register(self, b: Branch) -> None: self.branches[b.branch_id] = b def decide(self, branch_id: str) -> BranchState: """Apply the cost-aware boundary at a checkpoint.""" b = self.branches[branch_id] if b.state is not BranchState.LIVE: return b.state # Boundary: roll back only if cheaper AND verifiable; else hedge. if b.rollback_cost < b.forward_cost and b.compensation_verifiable: b.state = BranchState.ROLLBACK_PENDING else: b.state = BranchState.HEDGED return b.state def reconcile_barrier(self, winner_id: str) -> None: """ Gate the winner's commit on completion predicates of all ROLLBACK_PENDING branches. On timeout, escalate to HEDGED rather than proceed (a pending branch is still a writer). """ winner = self.branches.get(winner_id) if winner is None or winner.state is not BranchState.LIVE: raise RollbackLedgerError( f"winner {winner_id} not live; cannot commit" ) deadline = time.monotonic() + self.barrier_timeout_s for b in self.branches.values(): if b.state is not BranchState.ROLLBACK_PENDING: continue if b.completion_predicate is None: raise RollbackLedgerError( f"branch {b.branch_id} is ROLLBACK_PENDING with no " f"completion predicate; cannot establish silence" ) while time.monotonic() < deadline: if b.completion_predicate(): b.state = BranchState.REVERTED_VERIFIED break time.sleep(0.05) else: # Timeout: advisory ack was never terminal. Escalate to hedge. b.state = BranchState.HEDGED def attribute_write(self, writer_branch_id: str) -> str: """ Classify a write observed during the winner's commit. Expected writers: HEDGED and ROLLBACK_PENDING branches (attributed). Foreign writers: anything else -> StateConflict. """ b = self.branches.get(writer_branch_id) if b is None: raise RollbackLedgerError( f"foreign writer {writer_branch_id!r} not in ledger; " f"reconciliation invariant violated" ) if b.state in (BranchState.HEDGED, BranchState.ROLLBACK_PENDING): return "expected" if b.state is BranchState.REVERTED_VERIFIED: raise RollbackLedgerError( f"branch {writer_branch_id} is REVERTED_VERIFIED but emitted " f"a write; completion predicate was unsound" ) raise RollbackLedgerError( f"branch {writer_branch_id} in state {b.state.value} emitted an " f"unattributed write; aborting reconciliation" ) def _demo() -> None: orch = SpeculativeOrchestrator(barrier_timeout_s=0.2) # B: advisory compensation, expensive to retract -> must hedge, not roll back. orch.register(Branch("B", score=0.22, rollback_cost=9.0, forward_cost=1.5, compensation_verifiable=False)) # C: synchronous, cheap -> roll back. orch.register(Branch("C", score=0.09, rollback_cost=0.5, forward_cost=2.0, compensation_verifiable=True, completion_predicate=lambda: True)) orch.register(Branch("A", score=0.71, rollback_cost=0.0, forward_cost=0.0, compensation_verifiable=True)) assert orch.decide("B") is BranchState.HEDGED assert orch.decide("C") is BranchState.ROLLBACK_PENDING orch.reconcile_barrier("A") assert orch.branches["C"].state is BranchState.REVERTED_VERIFIED assert orch.attribute_write("B") == "expected" # A REVERTED_VERIFIED branch emitting a write is the unsound-predicate case. try: orch.attribute_write("C") except RollbackLedgerError: pass # expected: surfaces the unsound completion predicate if __name__ == "__main__": _demo() ```