{"record":{"id":"ef903defbd9033bd","repo":"JuliusBrussee/caveman","slug":"cave-reasoning-usage-unavailable","errorCode":"cave_reasoning_usage_unavailable","errorMessage":"cave_reasoning_usage_unavailable","messagePattern":"cave_reasoning_usage_unavailable","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":1585,"sourceCode":"            );\n          }\n        }\n        if (reservation !== undefined && reservation.length > 0) {\n          markSpendIncomplete(reservation.map((item) => item.ledger));\n          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","sourceCodeStart":1567,"sourceCodeEnd":1603,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L1567-L1603","documentation":"When running under an efficiency plan, reasoning (thinking) token usage is mandatory for budget accounting. If the provider did not report reasoning usage, the run fails closed rather than enforcing budgets against partial numbers.","triggerScenarios":"streamAgent called with an efficiencyPlan while reasoningUsageUnavailable is true at the next model call — i.e. the provider/model did not return reasoning-token counts for the previous turn.","commonSituations":"Using a model or provider endpoint that omits reasoning usage fields (older API versions, non-thinking models, proxy gateways that strip usage details) while an efficiency plan is active.","solutions":["Use a model/provider configuration that reports reasoning token usage","Remove the efficiencyPlan requirement or run without the plan","Update the provider adapter/gateway so reasoning usage fields pass through"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"if (efficiencyPlan && !model.supportsReasoningUsage) {\n  throw new Error(\"plan requires a model that reports reasoning usage\");\n}","typeGuard":null,"tryCatchPattern":"try { await runWithPlan(); } catch (e) { if (e.message === \"cave_reasoning_usage_unavailable\") return runWithoutPlan(); throw e; }","preventionTips":["Verify reasoning-token fields appear in provider responses before enabling plans","Avoid gateways/proxies that strip usage detail fields","Pin provider API versions that include reasoning usage"],"tags":["reasoning-tokens","usage-accounting","efficiency-plan","provider-compat"],"backgroundTag":"unexpected-api-response-shape","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"}