{"record":{"id":"327e687071c2a74f","repo":"JuliusBrussee/caveman","slug":"cave-reasoning-budget-exceeded","errorCode":"cave_reasoning_budget_exceeded","errorMessage":"cave_reasoning_budget_exceeded","messagePattern":"cave_reasoning_budget_exceeded","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":1590,"sourceCode":"          spendFailure ??= failure;\n        }\n      }\n      finalMessage = message;\n    };\n    const streamFn: StreamFn = async (selected, context, streamOptions) => {\n      if (options.signal?.aborted) {\n        throw options.signal.reason ?? new Error(\"cave_run_aborted\");\n      }\n      if (spendFailure) throw spendFailure;\n      if (usageFailure) throw usageFailure;\n      if (nestedUsage.incomplete) throw new Error(\"cave_nested_usage_incomplete\");\n      if (efficiencyPlan && reasoningUsageUnavailable) {\n        throw new Error(\"cave_reasoning_usage_unavailable\");\n      }\n      if (efficiencyPlan) {\n        enforceSemanticBudgets(contextBill(lowered.ir), outputTokens, efficiencyPlan);\n        if (reasoningTokens > efficiencyPlan.budgets.reasoning) {\n          throw new Error(\"cave_reasoning_budget_exceeded\");\n        }\n      }\n      // The hard model-call ceiling is a stop condition, not a failure: ending\n      // the run through the same graceful path as every other stop keeps the\n      // partial work and the receipt intact. Checked before the\n      // increment so exactly `maxModelCalls` calls are allowed.\n      if (modelCalls >= maxModelCalls) {\n        stopReason = \"call_budget_exhausted\";\n        refusalPending = true;\n        throw new Error(\"cave_run_stopped\");\n      }\n      modelCalls++;\n      // Between-calls stop point. Nothing is in flight here: the previous turn\n      // and its tools have finished and settled, and this call has not started.\n      const plan = () => decideNextCall({\n        meter: budgetMeter,\n        breakers,\n        deadlineAt,","sourceCodeStart":1572,"sourceCodeEnd":1608,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L1572-L1608","documentation":"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.","triggerScenarios":"A streamAgent run with an efficiencyPlan where accumulated reasoningTokens across turns exceed budgets.reasoning, checked at the start of each model call.","commonSituations":"Setting a reasoning budget too small for a task that requires heavy thinking; switching to a more verbose reasoning model without raising the budget.","solutions":["Raise efficiencyPlan.budgets.reasoning to accommodate the task","Reduce reasoning effort (e.g. lower thinking budget on the model request)","Run without the efficiency plan if reasoning spend need not be capped"],"exampleFix":"// before\nconst plan = { budgets: { reasoning: 1000, ... } };\n// after\nconst plan = { budgets: { reasoning: 10000, ... } };","handlingStrategy":"validation","validationCode":"if (expectedReasoningTokens > efficiencyPlan.budgets.reasoning) {\n  throw new Error(\"raise budgets.reasoning before starting this task\");\n}","typeGuard":null,"tryCatchPattern":"try { await streamAgent(opts); } catch (e) { if (e.message === \"cave_reasoning_budget_exceeded\") { /* raise budgets.reasoning and resume from receipt */ } else throw e; }","preventionTips":["Size the reasoning budget generously for thinking-heavy models/tasks","Track reasoning spend in receipts across runs to calibrate budgets","Lower the model's reasoning effort when budgets are tight"],"tags":["budget-exceeded","reasoning-tokens","efficiency-plan"],"backgroundTag":"rate-limit-exceeded","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}