#20085: Fix QMD memory_search empty results when docid key changes
size: XS
Cluster:
QMD Memory Management Fixes
Fixes #20082
Some QMD versions emit result objects with keys like `doc_id` / `docId` (instead of `docid`). The gateway parser treated these hits as missing doc IDs, so `resolveDocLocation()` dropped every result and `memory_search` returned an empty list.
This normalizes common doc-id key variants to `docid` during JSON parsing and adds a small test for the alternate keys.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a bug where `memory_search` returned empty results when QMD versions emit doc-id keys under variant names (`doc_id`, `docId`, `document_id`, `documentId`, `hash`, `id`) instead of the expected `docid`. The parser now normalizes these key variants during JSON parsing, along with `path`→`file` and `text`→`snippet` aliases.
- Adds key normalization in `parseQmdQueryResultArray` to map common doc-id key variants to the canonical `docid` field
- Explicitly constructs `QmdQueryResult` objects with only known fields (previously used a raw type cast on parsed JSON)
- Adds test coverage for `doc_id` and `docId` normalization
- The downstream consumers in `qmd-manager.ts` (`resolveDocLocation`, multi-collection dedup) already handle `undefined` docid safely, so this change is backwards-compatible
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it fixes a real parsing bug with a straightforward normalization approach and has no impact on the happy path.
- The change is well-scoped, fixes a clear bug (empty results from variant key names), and downstream code already handles missing docid gracefully. One minor style concern about runtime type safety on the docid fallback chain, but it's unlikely to cause issues in practice since QMD document identifiers are string hashes.
- No files require special attention.
<sub>Last reviewed commit: 991bf1e</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9624: fix(memory): resolve QMD search returning empty results [AI-assisted]
by kowshik24 · 2026-02-05
89.4%
#15307: fix(memory): handle mixed/no-results QMD query output
by MohammadErfan-Jabbari · 2026-02-13
82.4%
#21471: fix: check QMD backend before memory search config
by lbo728 · 2026-02-20
82.2%
#16917: fix(memory): close stale SQLite connection after qmd update
by zerone0x · 2026-02-15
79.7%
#20125: fix(doctor): skip memorySearch provider check when using QMD backend
by brandonwise · 2026-02-18
79.7%
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
79.7%
#9149: Fix: Allow QMD backend to work without OpenAI auth
by vishaltandale00 · 2026-02-04
78.8%
#22937: fix: remove legacy unsuffixed QMD collections on upgrade
by sud0n1m-ziggy · 2026-02-21
78.6%
#16968: fix(qmd): per-collection search to prevent large collections drowni...
by ProgramCaiCai · 2026-02-15
77.3%
#17660: fix: skip embedding provider check in doctor when QMD backend is co...
by echoVic · 2026-02-16
77.2%