{"record":{"id":"071abb06000053f8","repo":"gastownhall/beads","slug":"auto-export-shrink-guard-refusing-to-overwrite-s","errorCode":null,"errorMessage":"auto-export shrink guard: refusing to overwrite %s because it contains %d record(s) outside auto-export scope (%d memories, %d infra/template/ephemeral issues, %d unknown); run an explicit export if you want to replace it","messagePattern":"auto-export shrink guard: refusing to overwrite (.+?) because it contains (.+?) record\\(s\\) outside auto-export scope \\((.+?) memories, (.+?) infra/template/ephemeral issues, (.+?) unknown\\); run an explicit export if you want to replace it","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/export_auto.go","lineNumber":746,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\tif err := classifyExistingAutoExportRecord([]byte(line), infraTypes, includeMemories, storeIDs, &stats); err != nil {\n\t\t\treturn fmt.Errorf(\"auto-export shrink guard: inspect existing JSONL line %d: %w\", lineNo, err)\n\t\t}\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"auto-export shrink guard: inspect existing JSONL: %w\", err)\n\t}\n\n\t// Store-presence rule (#4069 vs #4988): block on memories (when\n\t// excluded), unknown record types, and out-of-scope issue rows whose id\n\t// is STILL present in the store — those are exactly what #4069 says we\n\t// must not silently drop. An out-of-scope row absent from the store\n\t// (e.g. a TTL-compacted wisp) is safe to drop and does not block.\n\tif stats.FilteredRecords == 0 {\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"auto-export shrink guard: refusing to overwrite %s because it contains %d record(s) outside auto-export scope (%d memories, %d infra/template/ephemeral issues, %d unknown); run an explicit export if you want to replace it\", path, stats.FilteredRecords, stats.Memories, stats.FilteredIssues, stats.UnknownRecords)\n}\n\ntype autoExportOverwriteStats struct {\n\tFilteredRecords int // blocking total: Memories + FilteredIssues + UnknownRecords\n\tMemories        int\n\tFilteredIssues  int // infra/template/ephemeral issues still present in the store — blocking (restores GH#4069)\n\tUnknownRecords  int\n}\n\nfunc classifyExistingAutoExportRecord(line []byte, infraTypes map[string]bool, includeMemories bool, storeIDs map[string]struct{}, stats *autoExportOverwriteStats) error {\n\tvar record struct {\n\t\tType       string          `json:\"_type\"`\n\t\tIssueType  types.IssueType `json:\"issue_type\"`\n\t\tIsTemplate bool            `json:\"is_template\"`\n\t\tEphemeral  bool            `json:\"ephemeral\"`\n\t\tID         string          `json:\"id\"`\n\t}\n\tif err := json.Unmarshal(line, &record); err != nil {","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/export_auto.go#L728-L764","documentation":"The auto-export shrink guard refuses to overwrite the JSONL when it contains records outside auto-export scope: memories (when not included), infra/template/ephemeral issues still present in the store (GH#4069), or unknown record types. Overwriting would silently drop those records, so bd aborts and asks for an explicit export instead.","triggerScenarios":"guardAutoExportOverwrite returns this when stats.FilteredRecords > 0 after scanning the existing file — e.g. the file has memories but the export config excludes memories, or it contains infra/template/ephemeral issue rows whose IDs are still in the store, or unrecognized record lines.","commonSituations":"A repo previously synced with memories included now exports with memories excluded; issues were flipped to type template/ephemeral but still exist in the store; a hand-edited or older-format JSONL has record types the current bd doesn't recognize.","solutions":["Run an explicit full export (`bd export -o .beads/issues.jsonl`) if you genuinely want to replace the file","Include memories in the export config if the memories in the file are wanted","Clean up or export the out-of-scope issues (infra/template/ephemeral) so the file matches auto-export scope","Check the file for hand-added/unknown records and remove or migrate them"],"exampleFix":"// before\n// auto-export blocked: refusing to overwrite .beads/issues.jsonl (5 records outside scope...)\n// after\nbd export -o .beads/issues.jsonl   # explicit export intentionally replaces the file","handlingStrategy":"validation","validationCode":"// Check the JSONL for out-of-scope records before exporting\nclassify := func(line []byte) bool { var r map[string]any; return json.Unmarshal(line, &r) == nil }\nf, _ := os.Open(\".beads/issues.jsonl\")\nscanner := bufio.NewScanner(f)\nfor scanner.Scan() {\n    var rec map[string]any\n    if json.Unmarshal(scanner.Bytes(), &rec) != nil { fmt.Println(\"unknown record present\") }\n    if rec[\"type\"] == \"memory\" { fmt.Println(\"memory record present — include memories or export explicitly\") }\n}","typeGuard":null,"tryCatchPattern":"if err := autoExport(); err != nil && strings.Contains(err.Error(), \"refusing to overwrite\") {\n    // Intentional replacement requires explicit export\n    runCmd(\"bd\", \"export\", \"-o\", \".beads/issues.jsonl\")\n}","preventionTips":["Keep export config (memories inclusion, owner exclusions) stable across machines","Don't hand-add records of unknown shape to the JSONL","Run an explicit `bd export` after intentionally flipping issues to infra/template/ephemeral types","Review .beads/issues.jsonl diffs for unexpected record types"],"tags":["auto-export","data-loss-guard","scope-mismatch"],"backgroundTag":"auto-export-shrink-guard","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}