{"record":{"id":"8f2a22b83e6662a4","repo":"gastownhall/beads","slug":"failed-to-parse-memory-record-w","errorCode":null,"errorMessage":"failed to parse memory record: %w","messagePattern":"failed to parse memory record: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/import.go","lineNumber":275,"sourceCode":"\n\t\t// Skip the optional beads-jsonl header record (§J1.3). A canonical\n\t\t// export may prepend a provenance line, e.g.\n\t\t// {\"_schema\":\"beads-jsonl/1\",\"_dolt_branch\":\"main\",\"_sort\":\"stable-v1\"}.\n\t\t// It carries no _type and no issue fields; without this guard it falls\n\t\t// through to the issue path, unmarshals into an empty Issue, and aborts\n\t\t// the whole import with \"title is required\". parseJSONLFile (the\n\t\t// bootstrap reader) has always skipped it; this loop — the one `bd\n\t\t// import` and `bd import -` run through — did not.\n\t\tif _, isHeader := peek[\"_schema\"]; isHeader {\n\t\t\tcontinue\n\t\t}\n\n\t\tif rawType, ok := peek[\"_type\"]; ok {\n\t\t\tvar typeStr string\n\t\t\tif err := json.Unmarshal(rawType, &typeStr); err == nil && typeStr == \"memory\" {\n\t\t\t\tvar mem memoryRecord\n\t\t\t\tif err := json.Unmarshal([]byte(line), &mem); err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse memory record: %w\", err)\n\t\t\t\t}\n\t\t\t\tif mem.Key != \"\" && mem.Value != \"\" {\n\t\t\t\t\tmemories = append(memories, mem)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tvar issue types.Issue\n\t\tif err := json.Unmarshal([]byte(line), &issue); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse issue from JSONL: %w\", err)\n\t\t}\n\t\tif issue.Status == \"tombstone\" {\n\t\t\tcontinue\n\t\t}\n\t\tapplyImportWispPlane(peek, &issue)\n\t\tissue.SetDefaults()\n\t\tissues = append(issues, &issue)","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/import.go#L257-L293","documentation":"A JSONL line whose `_type` is \"memory\" failed to unmarshal into the internal memoryRecord struct. The line is valid JSON (it passed the peek) but does not match the expected memory shape (Key/Value fields with correct types).","triggerScenarios":"`bd import` encounters a `\"_type\":\"memory\"` record whose JSON structure mismatches memoryRecord — e.g. `key`/`value` fields of wrong JSON types, null where a string is required, or a record assembled by hand or from another tool's schema.","commonSituations":"Hand-crafting memory records for `bd` config-style memories; importing JSONL produced by an older/newer beads version with a different memory schema; scripted line rewriting that broke field types.","solutions":["Inspect the failing line and give it the expected shape: {\"_type\":\"memory\",\"key\":\"...\",\"value\":\"...\"}","Quote/unescape properly: value must be a JSON string, not a nested object or null","Re-export memories from the source repo with `bd export` rather than synthesizing them","Check source and target `bd --version` for schema drift between releases"],"exampleFix":"// before\n{\"_type\":\"memory\",\"key\":\"team\",\"value\":{\"name\":\"core\"}}\n// after\n{\"_type\":\"memory\",\"key\":\"team\",\"value\":\"core\"}","handlingStrategy":"validation","validationCode":"jq -c 'select(._type==\"memory\") | has(\"key\") and has(\"value\") and (.value|type==\"string\")' file.jsonl","typeGuard":null,"tryCatchPattern":"if ! bd import data.jsonl 2>err.log; then\n  grep 'failed to parse memory record' err.log   # fix that record's key/value types\nfi","preventionTips":["Emit memory records exactly as {\"_type\":\"memory\",\"key\":\"...\",\"value\":\"...\"}","Ensure key and value are JSON strings, never objects, arrays, or null","Copy memory records from a real bd export, not hand-written templates","Match the beads version that produced the export to the importing binary"],"tags":["json","parsing","memory-record"],"backgroundTag":"record-schema-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}