#9624: fix(memory): resolve QMD search returning empty results [AI-assisted]
stale
Cluster:
QMD Memory Management Fixes
## Summary
Fixes #9000 - memory_search returns empty when memory.backend=qmd, but qmd CLI works.
## Root Cause
The resolveDocLocation method only used docid (a 6-char hash) to look up documents in the SQLite database. When QMD CLI returns JSON results, it includes both:
- docid (e.g., #abc123)
- file (e.g., qmd://collection/path/to/file.md)
If the docid lookup failed (e.g., DB timing, hash mismatch), all results were silently filtered out.
## Fix
1. Updated resolveDocLocation to accept both docid and file parameters
2. Added fallback logic: if docid lookup fails, parse the qmd:// URI from the file field
3. Added parseQmdPath helper to extract collection name and path from qmd://collection/path format
4. Updated search call to pass both entry.docid and entry.file
## Testing
- [x] pnpm build passes
- [x] pnpm check passes (lint + format)
- [x] pnpm test src/memory/qmd-manager.test.ts passes
- [x] Added unit test for parseQmdPath helper
## AI Disclosure
This PR was AI-assisted (Claude). The code changes have been reviewed and I understand what they do. The fix is straightforward: add a fallback path resolution when the primary docid lookup fails.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `QmdMemoryManager`’s search result resolution to accept both `docid` and `file` from QMD JSON results, attempting a SQLite `docid` lookup first and falling back to parsing `qmd://<collection>/<path>` from the `file` field. It also adds a unit test around the new path parsing helper.
In the current state, the fallback path parsing logic has an off-by-one bug that prevents `qmd://` URIs from being parsed correctly, so the intended fix for “empty results” won’t actually take effect when the DB lookup fails.
<h3>Confidence Score: 2/5</h3>
- This PR is not safe to merge as-is due to a functional bug in the new fallback path parsing.
- The core change is meant to prevent QMD searches from returning empty results by parsing `qmd://` URIs when the SQLite lookup fails, but `parseQmdPath` currently slices the prefix incorrectly, causing valid `qmd://` inputs to return null and making the fallback ineffective. The added test also doesn’t exercise the full fallback wiring, so it wouldn’t catch this regression.
- src/memory/qmd-manager.ts (parseQmdPath/resolveDocLocation), src/memory/qmd-manager.test.ts (coverage of fallback behavior)
<!-- 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
#20085: Fix QMD memory_search empty results when docid key changes
by rylena · 2026-02-18
89.4%
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
85.0%
#9149: Fix: Allow QMD backend to work without OpenAI auth
by vishaltandale00 · 2026-02-04
84.9%
#15307: fix(memory): handle mixed/no-results QMD query output
by MohammadErfan-Jabbari · 2026-02-13
84.5%
#21471: fix: check QMD backend before memory search config
by lbo728 · 2026-02-20
83.6%
#16917: fix(memory): close stale SQLite connection after qmd update
by zerone0x · 2026-02-15
82.8%
#20125: fix(doctor): skip memorySearch provider check when using QMD backend
by brandonwise · 2026-02-18
82.2%
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai · 2026-02-07
81.1%
#22937: fix: remove legacy unsuffixed QMD collections on upgrade
by sud0n1m-ziggy · 2026-02-21
80.5%
#9381: Fix: Allow QMD CLI memory search when scope is restrictive
by vishaltandale00 · 2026-02-05
80.3%