JuliusBrussee/caveman · error

recordOutcome: evidence.

Error message

recordOutcome: evidence.${key} must be a finite number

What it means

Numeric evidence values must be finite. NaN and ±Infinity are rejected per-key because they serialize to invalid JSON numbers (NaN is not representable in JSON) and would corrupt the stored 'key:value' reference on the platform.

Solutions

  1. Guard computed metrics before including them: Number.isFinite(x) ? x : 0 — or omit the entry
  2. Fix the upstream math: guard divide-by-zero, validate parseFloat inputs

Example fix

// before
evidence: { durationSec: elapsed / count } // count === 0 -> Infinity

// after
evidence: { durationSec: count > 0 ? elapsed / count : 0 }
Defensive patterns

Strategy: validation

Validate before calling

function evidenceNumbersFinite(evidence: Record<string, unknown>): boolean {
  return Object.values(evidence).every((v) => typeof v !== 'number' || Number.isFinite(v));
}

Type guard

function isFiniteEvidenceNumber(v: unknown): v is number {
  return typeof v === 'number' && Number.isFinite(v);
}

Prevention

When it happens

Trigger: evidence: { score: NaN } or { ratio: Infinity } — typically the result of dividing by zero, or parseFloat on a non-numeric string.

Common situations: Computing rates/averages from counters that were zero; parseFloat('') yielding NaN; downstream missing data feeding a computed metric.

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


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/f45dacbe0b8cc6b0. Report an issue: GitHub.

Appendix: source

Thrown at packages/mastra/src/index.ts:661

  const controlApiUrl = requireBaseUrl(client.controlApiUrl, "recordOutcome: controlApiUrl");
  const token = requireNonEmpty(client.token, "recordOutcome: token");
  const projectId = requireNonEmpty(client.projectId, "recordOutcome: projectId");
  const taskId = requireNonEmpty(input.taskId, "recordOutcome: taskId");
  const contract = requireNonEmpty(input.contract, "recordOutcome: contract");

  if (!isPlainObject(input.values) || Object.keys(input.values).length === 0) {
    throw new Error("recordOutcome: values must be a non-empty plain object");
  }
  if (!isPlainObject(input.evidence)) {
    throw new Error("recordOutcome: evidence must be a plain object");
  }
  const evidenceRefs = Object.entries(input.evidence).map(([key, value]) => {
    if (!key.trim()) throw new Error("recordOutcome: evidence keys must be non-empty");
    if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
      throw new Error(`recordOutcome: evidence.${key} must be a string, number, or boolean`);
    }
    if (typeof value === "number" && !Number.isFinite(value)) {
      throw new Error(`recordOutcome: evidence.${key} must be a finite number`);
    }
    const ref = `${key}:${String(value)}`;
    if (!ref.slice(key.length + 1)) throw new Error(`recordOutcome: evidence.${key} must be non-empty`);
    return ref;
  });
  if (evidenceRefs.length === 0) {
    throw new Error("recordOutcome: evidence must contain at least one reference");
  }
  if (evidenceRefs.length > MAX_EVIDENCE_REFS) {
    throw new Error(`recordOutcome: evidence must contain at most ${MAX_EVIDENCE_REFS} references`);
  }

  const confidence = input.confidence;
  if (typeof confidence !== "number" || !Number.isFinite(confidence) || confidence < 0 || confidence > 1) {
    throw new Error("recordOutcome: confidence is required and must be a number within [0,1]");
  }
  if (typeof input.source !== "string" || !OUTCOME_SOURCES.has(input.source)) {
    throw new Error("recordOutcome: source is required and must be one of ci|environment|database|business_event|human");

View on GitHub (pinned to 766dce6b13)