{"record":{"id":"72d7ec3da704d4f1","repo":"gastownhall/beads","slug":"failed-to-search-issues-w","errorCode":null,"errorMessage":"failed to search issues: %w","messagePattern":"failed to search issues: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/export_auto.go","lineNumber":279,"sourceCode":"func shouldExport(state *exportAutoState, interval time.Duration) bool {\n\tif state.Timestamp.IsZero() {\n\t\treturn true\n\t}\n\treturn time.Since(state.Timestamp) >= interval\n}\n\nfunc shouldSkipEmptyAutoExport(ctx context.Context, path string) (bool, int, error) {\n\texistingCount, err := countIssueRecordsInJSONL(path)\n\tif err != nil {\n\t\treturn false, 0, err\n\t}\n\tif existingCount == 0 {\n\t\treturn false, 0, nil\n\t}\n\n\tissues, err := store.SearchIssues(ctx, \"\", autoExportFilter(ctx))\n\tif err != nil {\n\t\treturn false, 0, fmt.Errorf(\"failed to search issues: %w\", err)\n\t}\n\n\treturn len(issues) == 0, existingCount, nil\n}\n\nfunc countIssueRecordsInJSONL(path string) (int, error) {\n\tids, err := issueIDsInJSONL(path)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn len(ids), nil\n}\n\nfunc missingJSONLIssueIDsInStore(ctx context.Context, path, fromCommit string) ([]string, error) {\n\t// GH#4988: only refuse when *in-scope* JSONL issue records are absent from\n\t// the store. Ephemeral wisps, templates, and infra types are outside\n\t// auto-export scope (buildAutoExportFilter / GH#3649). Compaction can\n\t// delete wisps from Dolt while an older JSONL still lists them; treating","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/export_auto.go#L261-L297","documentation":"shouldSkipEmptyAutoExport queries the store with SearchIssues using the auto-export filter to decide whether the database is empty enough to skip writing the JSONL. A failed search is wrapped with this message; the caller cannot safely decide, so the auto-export path aborts with an error instead of potentially truncating the export.","triggerScenarios":"store.SearchIssues(ctx, \"\", autoExportFilter(ctx)) fails — store nil/uninitialized, Dolt query error, or driver-level failure while listing issues with the applied filter.","commonSituations":"Auto-export triggered in an environment where DB access is degraded (embedded Dolt lock contention, server unreachable); corrupted local metadata breaking the issue query; running with a filter referencing infrastructure types whose metadata is inconsistent.","solutions":["Inspect the wrapped cause; run `bd doctor` for storage health","Retry the export — the failure occurs before any JSONL write, so no data was lost","Ensure the database is reachable and not locked (close competing bd processes)","If the DB is genuinely empty, initialize properly (`bd init`) rather than forcing an export"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if !dbReachable() { skipAutoExport(\"store unreachable\") }","typeGuard":null,"tryCatchPattern":"if err := maybeAutoExport(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to search issues\") {\n        // safe to retry: no JSONL was written\n        time.Sleep(backoff); retryAutoExport()\n    }\n}","preventionTips":["Avoid concurrent bd writers holding the DB lock during auto-export","Run `bd doctor` in CI before export-dependent jobs","Let auto-export fail loudly rather than forcing an empty export"],"tags":["search","auto-export","storage"],"backgroundTag":"search-issues-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}