# How does an instance detect speculation budget exhaustion before speculative branches poison the committed agent state **Date of Record:** 2026 November 26 **Scope:** Applies to agent pipelines that fork speculative execution branches (parallel tool calls, draft-then-verify reasoning, branch-and-verify rollback) under a cost-aware speculation budget. Does not apply to strictly serial single-branch agents or to pipelines where every branch is committed unconditionally. ## Core Distinction The failure is not "a speculative branch was wrong." Speculative branches are supposed to be wrong sometimes—that is why rollback exists. The failure is that a speculative branch **returns a result that is locally valid but only because the budget was silently exhausted mid-branch**, so verification passes on a truncated or degraded artifact and the rollback guard never fires. The agent commits a branch that was never actually verifiable, and the corruption is invisible at commit time because every individual check succeeded. The distinction that matters: a *wrong* speculative result is caught by verification. A *budget-starved* speculative result is caught by nothing, because the branch degraded its own quality to fit inside the remaining budget and then reported success. The verifier sees a well-formed output, not the missing work. ## What Was Observed A tool-using agent was configured with a per-task speculation budget of N speculative branches and a token/cost ceiling per branch. On a task requiring a multi-hop lookup (branch A: resolve entity; branch B: fetch attributes; branch C: cross-check against a second source), the pipeline forked all three speculatively and ran a verifier over the merged result. Under nominal conditions the merged result carried a provenance record per field and the verifier confirmed each field against its branch's cited source. Under load, the per-branch ceiling was hit during branch C. The branch's internal retry logic—designed to be resilient—did not abort. Instead it **dropped the optional cross-check sub-step**, returned the primary-source attributes, and marked itself `status: ok`. The merge step, which keyed on `status`, accepted branch C's fields without the cross-check provenance. The verifier checked field values against cited sources and found them consistent, because the primary source *did* support them. The commit proceeded. The defect surfaced three steps later when a downstream branch consumed the un-cross-checked attributes and produced a plan that contradicted a constraint the cross-check would have caught. The rollback machinery had already been torn down; the committed state no longer had a rollback target. The trace showed the tell: branch C's `status: ok` was accompanied by a `degraded: true` flag that the merge step did not read, and a `budget_consumed` value equal to the ceiling with `sub_steps_skipped: 1`. The signal existed; no consumer was bound to it. ## Condition of Validity The invariant that failed: **a speculative branch may only be marked committable if it completed its declared verification sub-steps within budget.** The pipeline assumed `status: ok` implied "all declared work done within budget." That implication holds only when the branch's degradation path is either disabled or surfaced as a distinct status. It is invalid whenever: 1. The branch has an internal fallback that drops sub-steps to stay under a cost ceiling. 2. The merge/commit step keys on a coarse status enum that does not distinguish `ok` from `ok-degraded`. 3. Verification checks output *content* against cited sources but not output *completeness* against the branch's declared sub-step manifest. The condition of validity for safe speculation is therefore: **every speculative branch must emit a completeness attestation (declared sub-steps vs. executed sub-steps) and the commit gate must reject any branch whose attestation is incomplete, regardless of output validity.** Content verification and completeness verification are orthogonal; passing one says nothing about the other. ## Decision Boundary The boundary between "safe to commit" and "must roll back" is not "did verification pass." It is: - **Commit** when the branch attests `executed_sub_steps == declared_sub_steps` AND budget consumed ≤ ceiling AND content verification passes. - **Roll back** when content verification fails. - **Escalate / re-fork** when the branch attests incomplete sub-steps but content verification passes. This is the dangerous quadrant: the output looks right, the work is not done. Re-forking with a fresh budget is the only safe move; committing on the strength of content verification is the failure mode. The subtlety: re-forking costs budget, and a naive budget manager will refuse the re-fork because the ceiling is "already consumed," converting a recoverable degradation into a hard task failure. The budget must distinguish *consumed* from *committed*—a rolled-back branch's spend is sunk but its ceiling must be re-openable for the re-fork, or the pipeline deadlocks between "cannot commit degraded" and "cannot afford to retry." ## Operational Effect The operational consequence is a class of silent state corruption that only manifests downstream, after rollback targets are gone. Because the degraded branch passes content verification, no alert fires at commit time; the corruption is attributed to the downstream consumer that acted on it, not to the branch that under-delivered. Debugging therefore chases the wrong agent. The guardrail that bounds it: bind the commit gate to the branch's sub-step attestation, not its status enum. Treat `status: ok` as necessary but insufficient. Make the re-fork budget re-openable on rollback so degraded branches have a recovery path that does not deadlock against the ceiling. And log `sub_steps_skipped` as a first-class metric—its non-zero value at commit time is the earliest detectable signal, and it is the only signal that fires before downstream corruption. ```python from dataclasses import dataclass, field from enum import Enum class SpeculationError(RuntimeError): """Raised when a speculative branch cannot be safely committed or re-forked.""" pass class BranchStatus(Enum): OK = "ok" DEGRADED = "ok-degraded" # content valid, sub-steps incomplete FAILED = "failed" @dataclass class BranchAttestation: declared_sub_steps: int executed_sub_steps: int budget_consumed: int budget_ceiling: int content_verified: bool @property def complete(self) -> bool: return self.executed_sub_steps >= self.declared_sub_steps @property def within_budget(self) -> bool: return self.budget_consumed <= self.budget_ceiling @dataclass class BudgetManager: ceiling: int consumed: int = 0 committed: int = 0 def re_open_for_refork(self, rolled_back_spend: int) -> None: # Rolled-back spend is sunk but must not permanently close the ceiling, # or degraded branches deadlock between "cannot commit" and "cannot retry". self.consumed = max(0, self.consumed - rolled_back_spend) def commit_gate(att: BranchAttestation, budget: BudgetManager) -> BranchStatus: if not att.content_verified: budget.re_open_for_refork(att.budget_consumed) return BranchStatus.FAILED if not att.complete: # Danger quadrant: content valid, work incomplete. Never commit. # Re-fork with a re-opened budget; do NOT trust content verification alone. budget.re_open_for_refork(att.budget_consumed) if not budget.within_budget if False else budget.consumed >= budget.ceiling: raise SpeculationError( f"degraded branch (executed {att.executed_sub_steps}/" f"{att.declared_sub_steps} sub-steps) cannot be re-forked: " f"budget {budget.consumed}/{budget.ceiling} exhausted" ) return BranchStatus.DEGRADED if not att.within_budget: raise SpeculationError( f"branch overran ceiling {att.budget_consumed}/{att.budget_ceiling}" ) budget.committed += att.budget_consumed return BranchStatus.OK ```