{"record":{"id":"43987809028dcc98","repo":"JuliusBrussee/caveman","slug":"invalid-decision-ledger-response","errorCode":null,"errorMessage":"invalid Decision Ledger response","messagePattern":"invalid Decision Ledger response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":14138,"sourceCode":"  line(\"unresolved assumptions\", String(receipt.policy.unresolved_assumptions ?? 0));\n  console.log(\"\\nClaim status\");\n  line(\"compression reduction\", receipt.claim_status.compression_reduction ?? \"not_attested\");\n  line(\"task savings\", receipt.claim_status.task_savings ?? \"not_verified\");\n}\n\nfunction nativeWhy(argv: string[]) {\n  const json = argv.includes(\"--json\");\n  const decisionID = argv.find((arg) => !arg.startsWith(\"--\"));\n  if (!decisionID || !/^dec_[0-9a-f]{24}$/.test(decisionID)) {\n    console.error(`usage: ${invokedAs()} why <decision-id> [--json]`);\n    process.exitCode = 2;\n    return;\n  }\n  let explanation: NativeWhy;\n  try {\n    const parsed = JSON.parse(proxyExec([\"native-why\", \"--decision\", decisionID], process.env, false)) as NativeWhy;\n    if (parsed?.schema !== \"caveman.native.why.v1\" || parsed.decision_id !== decisionID || typeof parsed.input_basis !== \"object\") {\n      throw new Error(\"invalid Decision Ledger response\");\n    }\n    explanation = parsed;\n  } catch (error) {\n    if (process.exitCode) return;\n    console.error(`caveman why: ${(error as Error).message}`);\n    process.exitCode = 1;\n    return;\n  }\n  if (json) {\n    print(explanation);\n    return;\n  }\n  const line = (label: string, value: string) => console.log(`  ${label.padEnd(22)} ${value}`);\n  console.log(`Decision ${explanation.decision_id}`);\n  line(\"session\", explanation.session_id);\n  line(\"action\", explanation.action);\n  line(\"reason\", explanation.reason);\n  line(\"input basis\", JSON.stringify(explanation.input_basis));","sourceCodeStart":14120,"sourceCodeEnd":14156,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L14120-L14156","documentation":"`caveman why` parses the Decision Ledger response from the proxy (`native-why --decision <id>`) and validates the schema: it must be schema 'caveman.native.why.v1', match the requested decision_id, and include an object input_basis. Any mismatch raises this error before displaying an explanation.","triggerScenarios":"The proxy returned JSON that fails validation — wrong/missing schema field, decision_id mismatch, or non-object input_basis; also thrown by JSON.parse failures inside the same try (proxy returned non-JSON).","commonSituations":"Proxy and CLI version skew (different schema versions); passing a decision id from a different ledger; proxy returning an HTML/empty error page.","solutions":["Upgrade the CLI and proxy together so both use caveman.native.why.v1","Confirm the --decision id exists in the current ledger (re-run the decision)","Run the proxy command manually (`native-why --decision <id>`) and inspect the raw output for corruption","Check proxy logs for an underlying failure producing the bad response"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function isNativeWhy(v: unknown): v is NativeWhy {\n  const p = v as NativeWhy;\n  return !!p && p.schema === 'caveman.native.why.v1' && typeof p.decision_id === 'string' && typeof p.input_basis === 'object';\n}","typeGuard":"const isNativeWhy = (v: unknown): v is NativeWhy =>\n  typeof v === 'object' && v !== null &&\n  (v as any).schema === 'caveman.native.why.v1' &&\n  typeof (v as any).input_basis === 'object';","tryCatchPattern":"try {\n  const parsed = JSON.parse(raw);\n  if (!isNativeWhy(parsed)) throw new Error('invalid Decision Ledger response');\n} catch (e) {\n  // check proxy/CLI version skew and re-fetch the decision\n}","preventionTips":["Keep CLI and proxy on the same version","Validate decision ids exist before querying","Log raw proxy output on parse failures"],"tags":["validation","schema","proxy","why"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}