JuliusBrussee/caveman · info · Error

cave_run_stopped

cave_run_stopped

Error message

cave_run_stopped

What it means

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.

Solutions

  1. Raise options.maxModelCalls for larger tasks
  2. Inspect the receipt's stopReason/refusal and finish the task in a follow-up run
  3. Fix the agent loop (e.g. tool errors causing endless retries) that consumes the call budget

Example fix

// before
streamAgent({ task }); // stops at 64 calls
// after
streamAgent({ task, maxModelCalls: 256 });
Defensive patterns

Strategy: try-catch

Try / catch

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; }

Prevention

When it happens

Trigger: Any streamAgent run whose number of model calls reaches the ceiling (default 64, or options.maxModelCalls) while more calls are still needed.

Common situations: Loops where the model keeps retrying tool calls, tasks genuinely larger than the ceiling, or a ceiling set low for testing and forgotten.


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

Appendix: source

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

      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,
        selected,
        context,
        requestedOutputTokens: streamOptions?.maxTokens,
        outputMaxTokens: definition.output?.maxTokens,
        planOutputTokens: efficiencyPlan?.budgets.output,
        restorableBytes: restorableRequestBytes(
          conversationOriginals,
          instructions,
          originalInstructions,
        ),

View on GitHub (pinned to 3ee70a1026)