{"record":{"id":"3a312f4dceaf0163","repo":"JuliusBrussee/caveman","slug":"recordoutcome-evidence-keys-must-be-non-empty","errorCode":null,"errorMessage":"recordOutcome: evidence keys must be non-empty","messagePattern":"recordOutcome: evidence keys must be non-empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mastra/src/index.ts","lineNumber":656,"sourceCode":" */\nexport async function recordOutcome(\n  client: CavemanOutcomeClient,\n  input: RecordOutcomeInput,\n): Promise<RecordOutcomeResult> {\n  const controlApiUrl = requireBaseUrl(client.controlApiUrl, \"recordOutcome: controlApiUrl\");\n  const token = requireNonEmpty(client.token, \"recordOutcome: token\");\n  const projectId = requireNonEmpty(client.projectId, \"recordOutcome: projectId\");\n  const taskId = requireNonEmpty(input.taskId, \"recordOutcome: taskId\");\n  const contract = requireNonEmpty(input.contract, \"recordOutcome: contract\");\n\n  if (!isPlainObject(input.values) || Object.keys(input.values).length === 0) {\n    throw new Error(\"recordOutcome: values must be a non-empty plain object\");\n  }\n  if (!isPlainObject(input.evidence)) {\n    throw new Error(\"recordOutcome: evidence must be a plain object\");\n  }\n  const evidenceRefs = Object.entries(input.evidence).map(([key, value]) => {\n    if (!key.trim()) throw new Error(\"recordOutcome: evidence keys must be non-empty\");\n    if (typeof value !== \"string\" && typeof value !== \"number\" && typeof value !== \"boolean\") {\n      throw new Error(`recordOutcome: evidence.${key} must be a string, number, or boolean`);\n    }\n    if (typeof value === \"number\" && !Number.isFinite(value)) {\n      throw new Error(`recordOutcome: evidence.${key} must be a finite number`);\n    }\n    const ref = `${key}:${String(value)}`;\n    if (!ref.slice(key.length + 1)) throw new Error(`recordOutcome: evidence.${key} must be non-empty`);\n    return ref;\n  });\n  if (evidenceRefs.length === 0) {\n    throw new Error(\"recordOutcome: evidence must contain at least one reference\");\n  }\n  if (evidenceRefs.length > MAX_EVIDENCE_REFS) {\n    throw new Error(`recordOutcome: evidence must contain at most ${MAX_EVIDENCE_REFS} references`);\n  }\n\n  const confidence = input.confidence;","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/mastra/src/index.ts#L638-L674","documentation":"After confirming evidence is a plain object, recordOutcome iterates its entries and requires each key to be non-blank after trimming. A key of '' or '   ' is rejected because it would produce a malformed ':value' reference string on the control API. This is per-entry validation, so the first blank key aborts the whole call.","triggerScenarios":"evidence: { '': 'x' } or evidence: { '  ': 1 }, commonly produced by computed keys like { [someVar]: val } where someVar is an empty/whitespace string.","commonSituations":"Building keys from variables (file names, step labels) that can be empty, parsing key/value pairs out of text where a separator produces an empty left side, or JSON payloads with \"\" keys round-tripped into evidence.","solutions":["Give every evidence entry a real label: { commit: sha, tests: 12 }.","Filter/validate computed keys before the call: skip entries whose trimmed key is empty.","If the key source may be blank, default it (e.g. key.trim() || 'unnamed')."],"exampleFix":"// before\nawait recordOutcome(client, { taskId, contract, values, evidence: { [label]: sha } }); // label === \"\"\n// after\nconst key = label.trim() || \"ref\";\nawait recordOutcome(client, { taskId, contract, values, evidence: { [key]: sha } });","handlingStrategy":"validation","validationCode":"function evidenceKeysValid(evidence: Record<string, unknown>): boolean {\n  return Object.keys(evidence).every(k => k.trim().length > 0);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await recordOutcome(client, input);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"evidence keys must be non-empty\")) {\n    const cleaned = Object.fromEntries(Object.entries(input.evidence).filter(([k]) => k.trim()));\n    return recordOutcome(client, { ...input, evidence: cleaned });\n  }\n  throw e;\n}","preventionTips":["Sanitize computed keys: default blank labels to a fallback name before use.","Never build evidence keys from unvalidated parsed text (split lines, filenames).","Filter empty-key entries out of dynamic payloads before calling recordOutcome."],"tags":["validation","api","telemetry"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}