JuliusBrussee/caveman · error

recordOutcome: evidence must be a plain object

Error message

recordOutcome: evidence must be a plain object

What it means

The evidence field of recordOutcome must be a plain object mapping reference keys to scalar values (e.g. { commit: 'abc123', suiteId: 42 }). The implementation iterates Object.entries over it to build evidence references, so null, arrays, strings, numbers, and class instances are rejected before any network call.

Solutions

  1. Pass an object literal with at least one entry: evidence: { commit: sha }
  2. Default null/undefined to a populated object before the call: evidence ?? { commit: 'unknown' }
  3. Type the payload so TypeScript rejects non-object evidence at compile time

Example fix

// before
recordOutcome(client, { taskId, contract, values, evidence: null });

// after
recordOutcome(client, { taskId, contract, values, evidence: { commit: sha } });
Defensive patterns

Strategy: validation

Validate before calling

function isPlainObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null &&
    (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
}

Type guard

function isEvidenceObject(v: unknown): v is Record<string, string | number | boolean> {
  return isPlainObject(v);
}

Prevention

When it happens

Trigger: recordOutcome(client, { ..., evidence: null }) or evidence: [] or evidence: 'commit:abc123' — anything that is not a plain object.

Common situations: An optional evidence builder returning null when nothing was collected; spreading a JSON-parsed value that was null; config defaults of null flowing into the call.

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/b6c204361b2ddf65. Report an issue: GitHub.

Appendix: source

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

 * confidence outside [0,1], or values that are not plain JSON. Exactly one
 * request is made — no retries — and a non-2xx response throws a
 * {@link CavemanOutcomeError} carrying the status and body verbatim.
 */
export async function recordOutcome(
  client: CavemanOutcomeClient,
  input: RecordOutcomeInput,
): Promise<RecordOutcomeResult> {
  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`);

View on GitHub (pinned to 766dce6b13)