JuliusBrussee/caveman · error · Error

cave_reasoning_budget_exceeded

cave_reasoning_budget_exceeded

Error message

cave_reasoning_budget_exceeded

What it means

Thrown when reasoning tokens consumed exceed the efficiency plan's reasoning budget (efficiencyPlan.budgets.reasoning). It is the deliberate budget-exceeded stop for thinking-token spend under a plan.

Solutions

  1. Raise efficiencyPlan.budgets.reasoning to accommodate the task
  2. Reduce reasoning effort (e.g. lower thinking budget on the model request)
  3. Run without the efficiency plan if reasoning spend need not be capped

Example fix

// before
const plan = { budgets: { reasoning: 1000, ... } };
// after
const plan = { budgets: { reasoning: 10000, ... } };
Defensive patterns

Strategy: validation

Validate before calling

if (expectedReasoningTokens > efficiencyPlan.budgets.reasoning) {
  throw new Error("raise budgets.reasoning before starting this task");
}

Try / catch

try { await streamAgent(opts); } catch (e) { if (e.message === "cave_reasoning_budget_exceeded") { /* raise budgets.reasoning and resume from receipt */ } else throw e; }

Prevention

When it happens

Trigger: A streamAgent run with an efficiencyPlan where accumulated reasoningTokens across turns exceed budgets.reasoning, checked at the start of each model call.

Common situations: Setting a reasoning budget too small for a task that requires heavy thinking; switching to a more verbose reasoning model without raising the budget.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/327e687071c2a74f. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/runtime.ts:1590

          spendFailure ??= failure;
        }
      }
      finalMessage = message;
    };
    const streamFn: StreamFn = async (selected, context, streamOptions) => {
      if (options.signal?.aborted) {
        throw options.signal.reason ?? new Error("cave_run_aborted");
      }
      if (spendFailure) throw spendFailure;
      if (usageFailure) throw usageFailure;
      if (nestedUsage.incomplete) throw new Error("cave_nested_usage_incomplete");
      if (efficiencyPlan && reasoningUsageUnavailable) {
        throw new Error("cave_reasoning_usage_unavailable");
      }
      if (efficiencyPlan) {
        enforceSemanticBudgets(contextBill(lowered.ir), outputTokens, efficiencyPlan);
        if (reasoningTokens > efficiencyPlan.budgets.reasoning) {
          throw new Error("cave_reasoning_budget_exceeded");
        }
      }
      // The hard model-call ceiling is a stop condition, not a failure: ending
      // the run through the same graceful path as every other stop keeps the
      // partial work and the receipt intact. Checked before the
      // increment so exactly `maxModelCalls` calls are allowed.
      if (modelCalls >= maxModelCalls) {
        stopReason = "call_budget_exhausted";
        refusalPending = true;
        throw new Error("cave_run_stopped");
      }
      modelCalls++;
      // Between-calls stop point. Nothing is in flight here: the previous turn
      // and its tools have finished and settled, and this call has not started.
      const plan = () => decideNextCall({
        meter: budgetMeter,
        breakers,
        deadlineAt,

View on GitHub (pinned to 3ee70a1026)