JuliusBrussee/caveman · error
cave_provider_usage_incomplete
cave_provider_usage_incomplete
Error message
cave_provider_usage_incomplete
What it means
validateProviderUsage throws cave_provider_usage_incomplete when token counters are not non-negative safe integers, totalTokens is not the exact sum of input+output+cacheRead+cacheWrite tokens, or reasoningTokens exceed outputTokens. The kernel requires internally consistent usage math before pricing.
Solutions
- Recompute totalTokens as input+output+cacheRead+cacheWrite before validation
- Ensure all four token fields are present, non-negative safe integers (default missing fields to 0)
- Fix the provider adapter so reasoningTokens is a subset of outputTokens
- Bypass strict validation only by supplying a correctly normalized evidence object
Example fix
// before
const evidence = { inputTokens: 10, outputTokens: 5, totalTokens: 15, reasoningTokens: 7 };
// after
const evidence = { inputTokens: 10, outputTokens: 5, cacheReadTokens: 0, cacheWriteTokens: 0,
totalTokens: 15, reasoningTokens: 3 }; // reasoning <= output, total == sum Defensive patterns
Strategy: validation
Validate before calling
const sum = e.inputTokens + e.outputTokens + e.cacheReadTokens + e.cacheWriteTokens;
if (![e.inputTokens,e.outputTokens,e.cacheReadTokens,e.cacheWriteTokens].every(v => Number.isSafeInteger(v) && v >= 0) || e.totalTokens !== sum || e.reasoningTokens > e.outputTokens) throw new Error("incomplete usage"); Type guard
function isCompleteUsage(e) { const f = [e.inputTokens,e.outputTokens,e.cacheReadTokens,e.cacheWriteTokens]; return f.every(v => Number.isSafeInteger(v) && v >= 0) && e.totalTokens === f.reduce((a,b)=>a+b,0) && e.totalTokens > 0 && e.reasoningTokens <= e.outputTokens; } Try / catch
try { kernel.usage(evidence); } catch (err) { if (err.message === "cave_provider_usage_incomplete") { evidence = normalizeUsage(evidence); } else throw err; } Prevention
- Normalize provider responses into the disjoint-sum format the kernel expects
- Default absent token fields to 0
- Clamp reasoningTokens to outputTokens at the adapter layer
- Unit-test adapters against the usage invariant
When it happens
Trigger: Evidence with missing/NaN/negative token fields; totalTokens computed inclusively with cached tokens double-counted (total != disjoint sum); reasoningTokens greater than outputTokens; fractional token counts.
Common situations: Providers that report totalTokens including cache reads while the kernel expects disjoint sums; adapters filling unknown fields with -1 or undefined; reasoning-model outputs where reasoning tokens exceed reported output tokens due to adapter bugs.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- apiKey, baseURL, and agent are required
- arm must be or
- artifact_id is required
- artifactId is required
- ASGI context resolver or request bounds are invalid
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/c12fa818ca203b46.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/execution-kernel.ts:150
}
if (options.expected !== undefined &&
(evidence.provider !== options.expected.provider || evidence.model !== options.expected.model)) {
throw new Error("cave_provider_model_identity_mismatch");
}
const values = [
evidence.inputTokens,
evidence.outputTokens,
evidence.cacheReadTokens,
evidence.cacheWriteTokens,
evidence.reasoningTokens,
evidence.totalTokens,
];
const disjointTotal = evidence.inputTokens + evidence.outputTokens +
evidence.cacheReadTokens + evidence.cacheWriteTokens;
if (values.some((value) => !Number.isSafeInteger(value) || value < 0) ||
evidence.totalTokens <= 0 || evidence.totalTokens !== disjointTotal ||
evidence.reasoningTokens > evidence.outputTokens) {
throw new Error("cave_provider_usage_incomplete");
}
const priced = catalogCost({
provider: evidence.provider,
model: evidence.model,
inputTokens: evidence.inputTokens,
outputTokens: evidence.outputTokens,
cacheReadTokens: evidence.cacheReadTokens,
cacheWriteTokens: evidence.cacheWriteTokens,
reasoningTokens: evidence.reasoningTokens,
});
if (!priced.priced && options.requirePriced === true) {
throw new Error("cave_provider_usage_unpriced");
}
if (options.reportedCostUsd !== undefined &&
(!priced.priced || !Number.isFinite(options.reportedCostUsd) ||
options.reportedCostUsd < 0 ||
Math.abs(options.reportedCostUsd - priced.usd) > 1e-12)) {
throw new Error("cave_provider_cost_mismatch");View on GitHub (pinned to 3ee70a1026)