diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6f0480e48..a668c6264b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ Docs: https://docs.openclaw.ai - Memory/QMD: cap QMD command output buffering to prevent memory exhaustion from pathological `qmd` command output. - Memory/QMD: query QMD index using exact docid matches before falling back to prefix lookup for better recall correctness and index efficiency. - Memory/QMD: make QMD result JSON parsing resilient to noisy command output by extracting the first JSON array from noisy `stdout`. +- Memory/QMD: pass result limits to `search`/`vsearch` commands so QMD can cap results earlier. - Models/CLI: guard `models status` string trimming paths to prevent crashes from malformed non-string config values. (#16395) Thanks @BinHPdev. ## 2026.2.14 diff --git a/src/memory/qmd-manager.test.ts b/src/memory/qmd-manager.test.ts index cb906b354e2..a4dda48d4ef 100644 --- a/src/memory/qmd-manager.test.ts +++ b/src/memory/qmd-manager.test.ts @@ -340,7 +340,15 @@ describe("QmdMemoryManager", () => { ).resolves.toEqual([]); const searchCall = spawnMock.mock.calls.find((call) => call[1]?.[0] === "search"); - expect(searchCall?.[1]).toEqual(["search", "test", "--json", "-c", "workspace"]); + expect(searchCall?.[1]).toEqual([ + "search", + "test", + "--json", + "-n", + String(resolved.qmd?.limits.maxResults), + "-c", + "workspace", + ]); expect(spawnMock.mock.calls.some((call) => call[1]?.[0] === "query")).toBe(false); expect(maxResults).toBeGreaterThan(0); await manager.close(); @@ -394,7 +402,7 @@ describe("QmdMemoryManager", () => { (args): args is string[] => Array.isArray(args) && ["search", "query"].includes(args[0]), ); expect(searchAndQueryCalls).toEqual([ - ["search", "test", "--json", "-c", "workspace"], + ["search", "test", "--json", "-n", String(maxResults), "-c", "workspace"], ["query", "test", "--json", "-n", String(maxResults), "-c", "workspace"], ]); await manager.close(); @@ -558,7 +566,21 @@ describe("QmdMemoryManager", () => { await manager.search("test", { sessionKey: "agent:main:slack:dm:u123" }); const searchCall = spawnMock.mock.calls.find((call) => call[1]?.[0] === "search"); - expect(searchCall?.[1]).toEqual(["search", "test", "--json", "-c", "workspace", "-c", "notes"]); + const maxResults = resolved.qmd?.limits.maxResults; + if (!maxResults) { + throw new Error("qmd maxResults missing"); + } + expect(searchCall?.[1]).toEqual([ + "search", + "test", + "--json", + "-n", + String(maxResults), + "-c", + "workspace", + "-c", + "notes", + ]); await manager.close(); }); diff --git a/src/memory/qmd-manager.ts b/src/memory/qmd-manager.ts index ec65cbdaa6a..c1b3fe36af0 100644 --- a/src/memory/qmd-manager.ts +++ b/src/memory/qmd-manager.ts @@ -972,7 +972,7 @@ export class QmdMemoryManager implements MemorySearchManager { if (command === "query") { return ["query", query, "--json", "-n", String(limit)]; } - return [command, query, "--json"]; + return [command, query, "--json", "-n", String(limit)]; } }