JuliusBrussee/caveman · error · Error
cave_nested_usage_incomplete
cave_nested_usage_incomplete
Error message
cave_nested_usage_incomplete
What it means
During streaming, if the accumulated usage for nested/sub-agent calls is flagged incomplete, streamFn throws this instead of producing a receipt with unaccountable spend. It guards the invariant that every token in the run is metered before budgets are enforced.
Solutions
- Ensure nested streams complete with full usage reporting (check provider response usage fields)
- Upgrade/fix the nested provider adapter so usage is always surfaced
- Retry the run if the incomplete usage was caused by a transient provider issue
Defensive patterns
Strategy: retry
Validate before calling
// pre-flight: confirm the provider adapter surfaces usage on every turn type
const probe = await provider.complete({ ..., max_tokens: 1 });
if (!probe.usage) throw new Error("provider does not report usage; nested runs will fail"); Try / catch
try { await streamAgent(opts); } catch (e) { if (e.message === "cave_nested_usage_incomplete") { /* retry once or drop nested sub-agent usage expectations */ } else throw e; } Prevention
- Keep nested provider SDKs updated so usage fields are always returned
- Avoid aborting nested streams mid-flight when accounting matters
- Monitor receipts for incomplete-usage flags before chaining runs
When it happens
Trigger: A nested agent/sub-stream completed without reporting complete usage (nestedUsage.incomplete === true), detected at the start of the next streamFn invocation.
Common situations: Nested agent runs whose provider response omitted usage fields, sub-streams aborted mid-flight, or provider SDK versions that stopped returning usage on some turn types.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- bounded_response_unavailable
- cave_provider_terminal_${finalMessage.stopReason}
- cave_reasoning_usage_unavailable
- runtime policy response stream returned invalid bytes
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/e4d7598df2270ee3.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:1583
budgetReservation.amount,
"unavailable_worst_case",
);
}
}
if (reservation !== undefined && reservation.length > 0) {
markSpendIncomplete(reservation.map((item) => item.ledger));
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");
}View on GitHub (pinned to 3ee70a1026)