{"record":{"id":"47b8075cc2946cd8","repo":"JuliusBrussee/caveman","slug":"cave-run-stopped","errorCode":"cave_run_stopped","errorMessage":"cave_run_stopped","messagePattern":"cave_run_stopped","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"info","filePath":"packages/agent/src/runtime.ts","lineNumber":1600,"sourceCode":"      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,\n        selected,\n        context,\n        requestedOutputTokens: streamOptions?.maxTokens,\n        outputMaxTokens: definition.output?.maxTokens,\n        planOutputTokens: efficiencyPlan?.budgets.output,\n        restorableBytes: restorableRequestBytes(\n          conversationOriginals,\n          instructions,\n          originalInstructions,\n        ),","sourceCodeStart":1582,"sourceCodeEnd":1618,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L1582-L1618","documentation":"Not a malfunction: thrown as the control-flow signal when the hard model-call ceiling is reached (modelCalls >= maxModelCalls). The library sets stopReason \"call_budget_exhausted\" and marks a refusal as pending, ending the run gracefully so partial work and the receipt survive; callers treat the throw as a normal stop.","triggerScenarios":"Any streamAgent run whose number of model calls reaches the ceiling (default 64, or options.maxModelCalls) while more calls are still needed.","commonSituations":"Loops where the model keeps retrying tool calls, tasks genuinely larger than the ceiling, or a ceiling set low for testing and forgotten.","solutions":["Raise options.maxModelCalls for larger tasks","Inspect the receipt's stopReason/refusal and finish the task in a follow-up run","Fix the agent loop (e.g. tool errors causing endless retries) that consumes the call budget"],"exampleFix":"// before\nstreamAgent({ task }); // stops at 64 calls\n// after\nstreamAgent({ task, maxModelCalls: 256 });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { const r = await streamAgent(opts); } catch (e) { if (e.message === \"cave_run_stopped\") { /* expected: check receipt.stopReason === \"call_budget_exhausted\" and continue in a new run */ } else throw e; }","preventionTips":["Set maxModelCalls above the expected call count for the task","Detect retry loops in tool results early so calls are not wasted","Treat this as a normal stop condition, not a bug"],"tags":["call-budget","stop-condition","graceful-stop"],"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"}