JuliusBrussee/caveman · critical · Error

caveman agent: run ended without terminal evidence

Error message

caveman agent: run ended without terminal evidence

What it means

runAgentWithOptions drives the event stream from streamAgentInternal and reduces it to a single final RunResult. If the generator completes without emitting a terminal event (result, error, or budget stop), this invariant throw fires: the run ended with no terminal evidence, so there is no result to return. It is an internal consistency guard — a well-formed run always emits exactly one terminal event.

Solutions

  1. Retry the run; a transient abort of the event generator is the usual cause.
  2. Check that no caller-supplied transport (custom streamFn/fetch) can silently close the stream without yielding a terminal event.
  3. If reproducible, report a bug with the run's receipt/event log — this is an internal invariant violation (internal-invariant-violation family).
  4. Upgrade the package; terminal-event emission guarantees have been hardened in later versions.

Example fix

// before
try {
  const result = await runAgent(def, input);
} catch (e) {
  // run ended without terminal evidence
}
// after
try {
  const result = await runAgent(def, input);
} catch (e) {
  if (e instanceof CavemanRunError) {
    // typed failure, e.receipt holds partial spend
  } else {
    // transient/invariant failure: retry with backoff
    const result = await runAgent(def, input);
  }
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const result = await runAgent(def, input);
} catch (err) {
  if (err instanceof CavemanRunError) {
    // typed failure: read err.receipt for partial spend
  } else if (err.message.includes("terminal evidence")) {
    // invariant/transient: log and retry with backoff
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: The internal event generator (streamAgentInternal) returns/completes without yielding a terminal CavemanRunEvent — e.g. an upstream abort or generator short-circuit path that exits the loop before any `final`-setting event is yielded.

Common situations: Runtime bugs or a transport aborting the async generator mid-run; calls via runAgent/runAgentInternal/runSubagent where the underlying stream closes cleanly but never terminated the run logically. End users should never see this directly; it usually indicates an interrupted or buggy execution path.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

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

  options: InternalRunOptions,
  executionContext: InternalExecutionContext,
): Promise<RunResult> {
  let final: RunResult | undefined;
  for await (const event of streamAgentWithOptions(
    definition,
    input,
    options,
    executionContext,
  )) {
    if (event.type === "run_end") final = event.result;
    if (event.type === "run_error") {
      // The ledger is not lost on the throwing path either: the partial receipt
      // rides on a typed `cause` so a caller that only awaits the promise can
      // still read what was spent before the failure.
      throw new CavemanRunError(event.code, event.message, event.receipt);
    }
  }
  if (!final) throw new Error("caveman agent: run ended without terminal evidence");
  return final;
}

export function streamAgent(
  definition: AgentDefinition,
  input: string,
  options: RunOptions = {},
): AsyncGenerator<CavemanRunEvent> {
  rejectInternalRunOptions(options);
  return streamAgentWithOptions(
    definition,
    input,
    options,
    rootExecutionContext(definition, options.maxCostUsd, options),
  );
}

function streamAgentWithOptions(

View on GitHub (pinned to 3ee70a1026)