JuliusBrussee/caveman · error · Error
local learn snapshot has no sinks array at
Error message
local learn snapshot has no sinks array at ${snapshotPath} What it means
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.
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.
Example fix
// before: hand-edited snapshot missing the field
{ "generated_at": "2026-09-01T00:00:00Z" }
// after
{ "generated_at": "2026-09-01T00:00:00Z", "sinks": [] } Defensive patterns
Strategy: type-guard
Validate before calling
// Validate the snapshot shape before consuming it
const raw = JSON.parse(readFileSync(snapshotPath, "utf8"));
if (!Array.isArray(raw.sinks)) console.warn("snapshot lacks sinks[] — regenerate with `caveman learn`"); Type guard
function hasSinks(v: unknown): v is { sinks: unknown[]; generated_at: string } {
const r = v as Record<string, unknown>;
return Array.isArray(r.sinks) && typeof r.generated_at === "string";
} Try / catch
try {
const snap = loadLearnSnapshot();
} catch (e) {
if (e instanceof Error && e.message.includes("has no sinks array")) {
rmSync(snapshotPath, { force: true }); // treat as stale schema
await runLearn();
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
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
- cave_output_schema_mismatch
- report fixture
- unsupported catalog shape
- assembly slot content is not JSON-serializable
- canonical span
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/a86996468ce1baea.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:10426
return `${subject} · ${out.tokensSaved} estimated tokens saved (inferred; counter basis ${out.tokenCountBasis})${destination}`;
}
// syncLocalPracticeFindings moves only stable ids + non-negative token rates
// from the current learn snapshot. Titles, suggestions, evidence, file paths,
// and payload text never leave the machine. Empty snapshots are sent so stale
// rows for this user are removed server-side.
async function syncLocalPracticeFindings(cfg: Config): Promise<PracticeSyncOutcome> {
const snapshotPath = join(cavemanHome(), "reports", "caveman-learn.json");
let raw: Record<string, unknown>;
try {
raw = JSON.parse(readFileSync(snapshotPath, "utf8")) as Record<string, unknown>;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { kind: "no_snapshot" };
throw new Error(`local learn snapshot is unreadable at ${snapshotPath}`);
}
if (!Array.isArray(raw.sinks)) {
throw new Error(`local learn snapshot has no sinks array at ${snapshotPath}`);
}
const observed = typeof raw.generated_at === "string" ? new Date(raw.generated_at) : null;
if (!observed || Number.isNaN(observed.valueOf())) {
throw new Error(`local learn snapshot has no valid generated_at at ${snapshotPath}`);
}
const sessions = typeof raw.sessions_scanned === "number" && Number.isFinite(raw.sessions_scanned)
? Math.max(0, Math.trunc(raw.sessions_scanned))
: 0;
const counter = (value: unknown) =>
typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : 0;
const findings = raw.sinks
.filter((sink): sink is Record<string, unknown> =>
!!sink && typeof sink === "object" && !Array.isArray(sink))
.filter((sink) => typeof sink.practice_id === "string" && sink.practice_id.length > 0)
.map((sink) => ({
sink_id: typeof sink.sink_id === "string" ? sink.sink_id : "",
practice_id: sink.practice_id as string,View on GitHub (pinned to 3ee70a1026)