{"record":{"id":"a86996468ce1baea","repo":"JuliusBrussee/caveman","slug":"local-learn-snapshot-has-no-sinks-array-at-snaps","errorCode":null,"errorMessage":"local learn snapshot has no sinks array at ${snapshotPath}","messagePattern":"local learn snapshot has no sinks array at (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":10426,"sourceCode":"  return `${subject} · ${out.tokensSaved} estimated tokens saved (inferred; counter basis ${out.tokenCountBasis})${destination}`;\n}\n\n// syncLocalPracticeFindings moves only stable ids + non-negative token rates\n// from the current learn snapshot. Titles, suggestions, evidence, file paths,\n// and payload text never leave the machine. Empty snapshots are sent so stale\n// rows for this user are removed server-side.\nasync function syncLocalPracticeFindings(cfg: Config): Promise<PracticeSyncOutcome> {\n  const snapshotPath = join(cavemanHome(), \"reports\", \"caveman-learn.json\");\n  let raw: Record<string, unknown>;\n  try {\n    raw = JSON.parse(readFileSync(snapshotPath, \"utf8\")) as Record<string, unknown>;\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return { kind: \"no_snapshot\" };\n    throw new Error(`local learn snapshot is unreadable at ${snapshotPath}`);\n  }\n\n  if (!Array.isArray(raw.sinks)) {\n    throw new Error(`local learn snapshot has no sinks array at ${snapshotPath}`);\n  }\n  const observed = typeof raw.generated_at === \"string\" ? new Date(raw.generated_at) : null;\n  if (!observed || Number.isNaN(observed.valueOf())) {\n    throw new Error(`local learn snapshot has no valid generated_at at ${snapshotPath}`);\n  }\n  const sessions = typeof raw.sessions_scanned === \"number\" && Number.isFinite(raw.sessions_scanned)\n    ? Math.max(0, Math.trunc(raw.sessions_scanned))\n    : 0;\n  const counter = (value: unknown) =>\n    typeof value === \"number\" && Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : 0;\n\n  const findings = raw.sinks\n    .filter((sink): sink is Record<string, unknown> =>\n      !!sink && typeof sink === \"object\" && !Array.isArray(sink))\n    .filter((sink) => typeof sink.practice_id === \"string\" && sink.practice_id.length > 0)\n    .map((sink) => ({\n      sink_id: typeof sink.sink_id === \"string\" ? sink.sink_id : \"\",\n      practice_id: sink.practice_id as string,","sourceCodeStart":10408,"sourceCodeEnd":10444,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L10408-L10444","documentation":"Thrown when the learn snapshot JSON parses but does not contain a `sinks` array at the top level. The CLI requires this field to process the snapshot and refuses to guess from a structurally invalid file.","triggerScenarios":"Loading a caveman-learn.json whose parsed object lacks `sinks` — e.g. a hand-edited report, a snapshot written by an incompatible/older CLI version with a different schema, or `sinks` present but of the wrong type (object/string/null).","commonSituations":"Schema drift after a CLI upgrade (old snapshots without sinks); manually editing reports and removing/renaming the field; another tool overwriting the file with unrelated JSON.","solutions":["Regenerate the snapshot with the current CLI: run `caveman learn` to write a schema-compliant caveman-learn.json.","Remove the stale/incompatible snapshot file so the command treats it as no_snapshot and relearns.","If you must keep it, add a top-level `\"sinks\": []` array in the JSON (empty is acceptable).","Check CLI version compatibility if the snapshot came from a different machine or version."],"exampleFix":"// before: hand-edited snapshot missing the field\n{ \"generated_at\": \"2026-09-01T00:00:00Z\" }\n// after\n{ \"generated_at\": \"2026-09-01T00:00:00Z\", \"sinks\": [] }","handlingStrategy":"type-guard","validationCode":"// Validate the snapshot shape before consuming it\nconst raw = JSON.parse(readFileSync(snapshotPath, \"utf8\"));\nif (!Array.isArray(raw.sinks)) console.warn(\"snapshot lacks sinks[] — regenerate with `caveman learn`\");","typeGuard":"function hasSinks(v: unknown): v is { sinks: unknown[]; generated_at: string } {\n  const r = v as Record<string, unknown>;\n  return Array.isArray(r.sinks) && typeof r.generated_at === \"string\";\n}","tryCatchPattern":"try {\n  const snap = loadLearnSnapshot();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"has no sinks array\")) {\n    rmSync(snapshotPath, { force: true }); // treat as stale schema\n    await runLearn();\n  } else throw e;\n}","preventionTips":["Regenerate snapshots after upgrading the CLI — the schema is versioned.","Never remove or rename top-level fields when hand-editing reports.","Don't let unrelated tools write to reports/caveman-learn.json.","Treat an unparseable or schema-invalid snapshot as stale and re-run learn."],"tags":["json","schema","snapshot","validation"],"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"}