fix(memory): use explicit qmd snippet line metadata#58181
Conversation
Greptile SummaryThis PR fixes a bug in the QMD/mcporter memory search integration where explicit Changes:
The fix is minimal and surgical. Fallback behavior (snippet-header parsing) is preserved for results that don't carry explicit line metadata, and the Confidence Score: 5/5Safe to merge — the change is narrowly scoped to result normalization, is non-breaking, and is covered by new targeted tests. All changed paths are defensive (strict type checks, positive-integer guard, swap-if-inverted), the old fallback is preserved when explicit metadata is absent, and the two new tests cover the newly added code path end-to-end. No data-integrity, security, or build concerns were found. No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/memory-host-sdk/src/host/qmd-query-parser.ts | Replaces bare type cast with explicit field mapping that preserves start_line/end_line as startLine/endLine on QmdQueryResult; all other fields correctly preserved. |
| extensions/memory-core/src/memory/qmd-manager.ts | Adds resolveSnippetLines() preferring explicit metadata over snippet-header fallback, normalizeSnippetLine() with positive-integer guard, and mirrors start_line extraction in the direct mcporter JSON path. |
| packages/memory-host-sdk/src/host/qmd-query-parser.test.ts | Adds test covering explicit start_line/end_line preservation through the parser. |
| extensions/memory-core/src/memory/qmd-manager.test.ts | Adds integration-style test verifying that explicit mcporter line metadata flows through to the final search hit result. |
| CHANGELOG.md | Adds changelog entry for the QMD explicit line metadata fix. |
Reviews (1): Last reviewed commit: "fix(memory): preserve qmd snippet line m..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86d909acb1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Improper input validation allows non-object entries (including null) in QMD query results, causing runtime crashes
Description
Vulnerable code: return parsed.map((item) => {
if (typeof item !== "object" || item === null) {
return item as QmdQueryResult;
}
// ...
});RecommendationReject or filter out non-object entries instead of returning them. Option A (filter non-objects out): return parsed
.filter((item): item is Record<string, unknown> => typeof item === "object" && item !== null)
.map((record) => {
const docid = typeof record.docid === "string" ? record.docid : undefined;
// ...
return {
docid,
// ...
startLine: parseQmdLineNumber(record.start_line ?? record.startLine),
endLine: parseQmdLineNumber(record.end_line ?? record.endLine),
} satisfies QmdQueryResult;
});Option B (hard-fail on invalid array contents): for (const item of parsed) {
if (typeof item !== "object" || item === null) {
throw new Error("qmd query JSON response contained non-object items");
}
}Either approach prevents Analyzed PR: #58181 at commit Last updated on: 2026-03-31T08:08:53Z |
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
* fix(memory): preserve qmd snippet line metadata * Memory/QMD: preserve snippet span with partial line metadata
Summary
memory_searchhits dropped explicitstart_line/end_linemetadata and reconstructed offsets from the snippet header instead.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
start_line/end_linepath.git blame, prior PR, issue, or refactor if known): contributor PR fix(memory): use start_line/end_line from QMD/mcporter response #47960 identified the right fix direction; this branch reapplies it on currentmain.Regression Test Plan (if applicable)
packages/memory-host-sdk/src/host/qmd-query-parser.test.ts,extensions/memory-core/src/memory/qmd-manager.test.tsUser-visible / Behavior Changes
Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
memory.backend=qmd,memory.qmd.mcporter.enabled=trueSteps
start_line/end_line.memory_searchresult.Expected
Actual
Evidence
Human Verification (required)
Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations