{"record":{"id":"b4902eff543b5ad2","repo":"gastownhall/beads","slug":"check-existing-issues-before-import-w","errorCode":null,"errorMessage":"check existing issues before import: %w","messagePattern":"check existing issues before import: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/import_shared.go","lineNumber":717,"sourceCode":"\t\tnewIDsSeen[id] = struct{}{}\n\t\tplan.NewIDs = append(plan.NewIDs, id)\n\t}\n\n\tif len(ids) == 0 {\n\t\t// There is no ID to look up, but title-only rows still create on\n\t\t// execution. Classify each non-nil row before the short-circuit so a\n\t\t// dry run reports it as created rather than unchanged.\n\t\tfor _, issue := range issues {\n\t\t\tif issue != nil {\n\t\t\t\taddNew(issue.ID)\n\t\t\t}\n\t\t}\n\t\treturn issues, nil, plan, nil\n\t}\n\n\tlocalIssues, err := store.GetIssuesByIDs(ctx, ids)\n\tif err != nil {\n\t\treturn nil, nil, plan, fmt.Errorf(\"check existing issues before import: %w\", err)\n\t}\n\tlocalByID := make(map[string]*types.Issue, len(localIssues))\n\tfor _, issue := range localIssues {\n\t\tif issue != nil && issue.ID != \"\" && !issue.UpdatedAt.IsZero() {\n\t\t\tlocalByID[issue.ID] = issue\n\t\t}\n\t}\n\n\tif len(localByID) == 0 {\n\t\t// Nothing matched locally, so every considered row is new.\n\t\tfor _, issue := range issues {\n\t\t\tif issue == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\taddNew(issue.ID)\n\t\t}\n\t\treturn issues, nil, plan, nil\n\t}","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/import_shared.go#L699-L735","documentation":"The stale-guard pre-filter queries the local store with GetIssuesByIDs to compare incoming import rows against existing issues' updated_at. If that read fails, the import cannot safely decide which rows are stale, so it aborts with `check existing issues before import:` plus the cause. No data has been written.","triggerScenarios":"Calling filterStaleImportIssues (via importIssuesCore, classifyDryRunImport, or the dry-run path) when the underlying GetIssuesByIDs read errors: storage unavailable, connection refused, locked DB, or query failure.","commonSituations":"SQLite DB locked by another process during `bd import` or `bd import --dry-run`; Dolt server unreachable; corrupted or migrated schema lacking expected columns; permissions problems after copying a database file.","solutions":["Read the wrapped cause to find the storage-level failure.","Ensure no other process holds the DB lock; retry after the competing process exits.","Verify storage connectivity (daemon running, Dolt server reachable) with `bd doctor`.","Run `bd doctor` / integrity checks if a schema or corruption issue is suspected, restoring from backup if needed."],"exampleFix":"// before\nbd import issues.jsonl   # check existing issues before import: database is locked\n// after\nfuser .beads/*.db         # find/stop the competing process\nbd import issues.jsonl","handlingStrategy":"try-catch","validationCode":"// quick connectivity probe before the import read\nconn, err := store.GetIssuesByIDs(ctx, []string{})\nif err != nil {\n    return fmt.Errorf(\"storage unavailable, aborting import: %w\", err)\n}\n_ = conn","typeGuard":null,"tryCatchPattern":"_, _, _, err := filterStaleImportIssues(ctx, store, issues, allowStale)\nif err != nil {\n    var preErr error\n    if strings.Contains(err.Error(), \"check existing issues before import:\") {\n        // read-only stage failed; safe to retry after storage recovers\n        preErr = fmt.Errorf(\"storage read failed, import aborted safely: %w\", err)\n    }\n    return preErr\n}","preventionTips":["Close competing `bd` processes before importing (SQLite single-writer).","Run `bd doctor` to verify storage health before scripted imports.","Don't move/copy the DB file while bd is running; restore from backup if corruption is suspected.","Retry on transient backend errors — the pre-filter is read-only."],"tags":["import","stale-guard","storage-read","sqlite"],"backgroundTag":"import-prefilter-read-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}