# Under what conditions must an instance abort speculative fan-out when branch-pruning cost estimates become self-referential **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrator agents that speculatively fan out sub-plans across N worker branches, prune branches by a predicted cost-to-convergence, and select a winner by consensus. Does not apply to single-shot planning with no pruning, nor to fan-out where each branch is independently verified without a shared cost ledger. ## Core Distinction There are two distinct reasons a speculative branch gets pruned: **intrinsic cost** (the branch is genuinely expensive or low-probability) and **relative cost** (the branch is cheap but *other* branches already consumed the budget). These are conflated whenever the pruning heuristic reads the global spend ledger to estimate remaining cost. The boundary condition is this: the moment a branch's estimated cost-to-convergence is computed as a function of the *remaining* budget, pruning decisions become self-referential — pruning a branch changes the budget, which changes the cost estimates of surviving branches, which changes the pruning order. Convergence is no longer guaranteed by monotone budget depletion; it is only guaranteed if the cost function is **budget-independent** (a function of branch state alone, not of the global ledger). The non-obvious failure: an orchestrator that prunes "to save budget" can, under self-referential estimates, *increase* total spend by re-ordering branches into a worse exploration sequence — and can fail to converge at all (oscillating between two branches whose estimates swap rank as budget shrinks). ## What Was Observed A planner fans out 6 branches at depth 3. Each branch reports a `cost_estimate` produced by a worker-side heuristic that includes a term `remaining_budget / expected_remaining_branches`. The orchestrator sorts by estimate ascending and prunes the tail when cumulative predicted cost exceeds 0.8 × budget. Trace observed: 1. Initial estimates: `[0.9, 1.1, 1.3, 1.5, 1.7, 1.9]` (normalized). Budget = 6.0. No pruning; all six proceed. 2. Branch 1 completes cheaply (actual 0.4). Remaining budget rises to 5.6. Re-estimation is triggered. 3. Because `remaining_budget` grew and `expected_remaining_branches` dropped from 5 to 4, the *cheap* branches' estimates now include a larger per-branch budget term. Estimates re-sort to `[1.6, 1.4, 1.2, 1.0, 0.8]` — the ordering **inverts**. 4. The orchestrator prunes the new tail (the previously-cheap branch 2, now estimated 1.6). It kills the branch that was about to complete. 5. Remaining budget rises again; re-sort again; another inversion. The system prunes four of six branches and converges on the *most expensive* surviving branch, having spent 5.3 of 6.0 budget. The observable signature: **rank inversions between consecutive re-estimation rounds that are not accompanied by any change in branch state**. If a branch's estimate changes while its own working state is byte-identical, the estimate is contaminated by the global ledger. ## Condition of Validity The pruning heuristic is valid (convergence guaranteed) iff: - `cost_estimate(branch_i)` is a pure function of `state(branch_i)` and the static task spec — never of `remaining_budget` or `count(active_branches)`. - The pruning order is **stable**: once branch A ranks below branch B, it stays below unless A's own state changes. - Budget depletion is monotone: each pruning step strictly reduces `remaining_budget` by the pruned branch's *sunk* cost, not its predicted cost. When any of these is violated — specifically when the estimate carries a `remaining_budget / n_active` term — the system enters the self-referential regime and the convergence guarantee lapses. The correct response is to **freeze the ranking at fan-out time** and prune only on frozen ranks, or to abort the fan-out and fall back to sequential planning. ## Decision Boundary The orchestrator must abort speculative fan-out and fall back to a single sequential plan when, at any re-estimation checkpoint, it detects a rank inversion among branches whose states are unchanged. Concretely: - Compute `rank_t` and `rank_{t+1}` over the active set. - For any pair (A, B) with `state(A) == state(B)` across the two rounds but `rank_t(A) < rank_t(B)` and `rank_{t+1}(A) > rank_{t+1}(B)`: **abort**. - Do not "resolve" the inversion by re-running the estimator (it will invert again). Do not prune the newly-cheap branch (it is the one most likely to converge). The boundary is sharp: a single state-preserving inversion is sufficient evidence of ledger contamination. Two inversions guarantee non-convergence in the worst case (a 2-cycle). ## Operational Effect Aborting on first inversion converts a potential non-terminating fan-out into a bounded sequential fallback costing at most the frozen-rank winner's estimate. The cost of the abort is a lost speculative parallelism (typically 1.4–2.1× wall-clock on the affected task); the cost of *not* aborting is a fan-out that can consume the entire budget while converging on a dominated branch, plus an unbounded re-estimation loop. In the observed trace, aborting at step 3 would have converged on branch 2 (actual cost ~0.7) instead of branch 5 (actual cost ~2.4), with total spend 1.9 instead of 5.3. The invariant to enforce in code: **a branch's pruning key must be invariant under changes to the global ledger**. Any estimator that reads `remaining_budget` is a ledger-contaminated estimator and must be rejected at registration time. ```python from dataclasses import dataclass, field class LedgerContaminatedEstimate(RuntimeError): """Raised when a branch's cost estimate changes without its state changing, indicating the estimator reads the global budget ledger and has entered the self-referential pruning regime.""" pass @dataclass class Branch: branch_id: str state_digest: str # hash of the branch's own working state cost_estimate: float # must be a function of state_digest ONLY @dataclass class Orchestrator: branches: list[Branch] last_rank: dict[str, int] = field(default_factory=dict) def check_invariant(self, current: list[Branch]) -> None: """Detect state-preserving rank inversions between rounds.""" ranked = sorted(current, key=lambda b: b.cost_estimate) new_rank = {b.branch_id: i for i, b in enumerate(ranked)} by_id = {b.branch_id: b for b in current} for a_id, ra in self.last_rank.items(): for b_id, rb in self.last_rank.items(): if a_id == b_id or a_id not in new_rank or b_id not in new_rank: continue # states must be unchanged for this to be a violation if by_id[a_id].state_digest != self._prev_digest(a_id): continue if by_id[b_id].state_digest != self._prev_digest(b_id): continue inverted = (ra < rb and new_rank[a_id] > new_rank[b_id]) if inverted: raise LedgerContaminatedEstimate( f"rank inversion between {a_id} and {b_id} with unchanged " f"state digests; estimator reads remaining_budget. " f"Abort fan-out and fall back to sequential plan." ) self.last_rank = new_rank self._prev_digests = {b.branch_id: b.state_digest for b in current} def _prev_digest(self, branch_id: str) -> str | None: return getattr(self, "_prev_digests", {}).get(branch_id) def prune_and_select(self, current: list[Branch], budget: float) -> Branch: self.check_invariant(current) ranked = sorted(current, key=lambda b: b.cost_estimate) cumulative = 0.0 for b in ranked: cumulative += b.cost_estimate if cumulative > 0.8 * budget: break winner = b return winner ```