JuliusBrussee/caveman · error
cave_provider_terminal_${finalMessage.stopReason}
cave_provider_terminal_${finalMessage.stopReason}
Error message
cave_provider_terminal_${finalMessage.stopReason} What it means
'cave_provider_terminal_error' or 'cave_provider_terminal_aborted' is thrown when the final assistant message reports a terminal stopReason of "error" or "aborted" (runtime.ts:2109-2111). The template interpolates the actual stopReason, so the message tells you exactly which terminal provider state ended the run.
Solutions
- If _aborted: check whether your code (or a timeout) called abort on the signal; remove premature aborts or extend the deadline.
- If _error: inspect provider status — check rate limits, quota, and API key validity, then retry with backoff.
- Check RunResult/receipt breakers and budget state to confirm a framework guard didn't trigger the abort path.
- Retry the run; transient provider errors (overloaded) usually clear.
Example fix
// before: aborting as soon as the first chunk arrives, producing cave_provider_terminal_aborted
const controller = new AbortController();
streamAgent(agent, input, { signal: controller.signal });
controller.abort();
// after: let the run finish; abort only on genuine cancellation
const controller = new AbortController();
process.on("SIGINT", () => controller.abort());
await collect(streamAgent(agent, input, { signal: controller.signal })); Defensive patterns
Strategy: try-catch
Type guard
function isProviderTerminal(msg: AssistantMessage): boolean {
return msg.stopReason === "error" || msg.stopReason === "aborted";
} Try / catch
try {
const result = await runAgent(agent, input, { signal });
} catch (e) {
const msg = e instanceof Error ? e.message : "";
if (msg === "cave_provider_terminal_aborted") {
// your signal aborted the run — handle cancellation
} else if (msg === "cave_provider_terminal_error") {
// provider failed mid-stream — retry with backoff
}
} Prevention
- Only abort the signal on genuine user cancellation, not proactively.
- Prefer RunOptions.deadlineMs for time limits — it stops between calls.
- Watch provider rate limits and quota to avoid mid-stream error stops.
- Wrap runs with bounded exponential-backoff retries for transient provider errors.
When it happens
Trigger: The provider's last assistant message carries stopReason === 'error' (provider-side failure during generation) or 'aborted' (the run was aborted via options.signal or pi.abort()) and that message became finalMessage at the end of streamAgentInternal.
Common situations: Caller aborts the AbortSignal mid-run (yields _aborted); provider API error mid-stream (rate limit, overloaded, auth revoked) surfaces as stopReason error; network interruption terminates the stream with an error stop.
Related errors
- AbortError
- bounded_response_unavailable
- cave_claude_provider_unsupported
- cave_incomplete_evidence
- cave_nested_usage_incomplete
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/35e6bfa412b99937.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:2111
(efficiencyPlan !== undefined ||
executionContext.spendLedgers.length > 0 ||
usageFailure.message === "cave_provider_model_identity_mismatch" ||
usageFailure.message === "cave_provider_identity_missing")) {
throw usageFailure;
}
if (pendingSpendReservations.length > 0) {
markSpendIncomplete(executionContext.spendLedgers);
throw new Error("cave_subagent_spend_evidence_incomplete");
}
// A run stopped before its first call has no assistant message, and that is
// the honest outcome rather than missing evidence: the caller gets an empty
// answer, zero usage, and the reason the runtime declined to spend.
if (!finalMessage && stopReason === undefined) {
throw new Error("cave_incomplete_evidence: Pi emitted no final assistant message");
}
if (finalMessage &&
(finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
throw new Error(`cave_provider_terminal_${finalMessage.stopReason}`);
}
const text = finalMessage === undefined ? "" : assistantText(finalMessage);
if (definition.output?.schema && finalMessage !== undefined) {
let parsed: unknown;
try {
parsed = JSON.parse(text);
} catch {
throw new Error("cave_output_schema_invalid_json");
}
if (!Value.Check(definition.output.schema, parsed)) {
throw new Error("cave_output_schema_mismatch");
}
}
if (appliedPlan.appliedTransformIDs.length > 0 && !cacheBoundaryKnown) {
cacheBust = true;
markRequestPassThrough(headers, appliedPlan, "cache_boundary_unobserved");
}
for (const child of nestedReceipts) receipt.recordSubagent(child);View on GitHub (pinned to 3ee70a1026)