Memory: fail closed when QMD has no collections

This commit is contained in:
Vignesh Natarajan
2026-02-07 19:56:28 -08:00
parent 7eece6dd7f
commit b44c6b5ebe
2 changed files with 47 additions and 11 deletions

View File

@@ -411,12 +411,50 @@ describe("QmdMemoryManager", () => {
if (!manager) {
throw new Error("manager missing");
}
const maxResults = resolved.qmd?.limits.maxResults;
if (!maxResults) {
throw new Error("qmd maxResults missing");
}
await manager.search("test", { sessionKey: "agent:main:slack:dm:u123" });
const queryCall = spawnMock.mock.calls.find((call) => call[1]?.[0] === "query");
expect(queryCall?.[1]).toEqual(
expect.arrayContaining(["query", "test", "-c", "workspace", "-c", "notes"]),
);
expect(queryCall?.[1]).toEqual([
"query",
"test",
"--json",
"-n",
String(maxResults),
"-c",
"workspace",
"-c",
"notes",
]);
await manager.close();
});
it("fails closed when no managed collections are configured", async () => {
cfg = {
...cfg,
memory: {
backend: "qmd",
qmd: {
includeDefaultMemory: false,
update: { interval: "0s", debounceMs: 60_000, onBoot: false },
paths: [],
},
},
} as OpenClawConfig;
const resolved = resolveMemoryBackendConfig({ cfg, agentId });
const manager = await QmdMemoryManager.create({ cfg, agentId, resolved });
expect(manager).toBeTruthy();
if (!manager) {
throw new Error("manager missing");
}
const results = await manager.search("test", { sessionKey: "agent:main:slack:dm:u123" });
expect(results).toEqual([]);
expect(spawnMock.mock.calls.some((call) => call[1]?.[0] === "query")).toBe(false);
await manager.close();
});

View File

@@ -253,14 +253,12 @@ export class QmdMemoryManager implements MemorySearchManager {
this.qmd.limits.maxResults,
opts?.maxResults ?? this.qmd.limits.maxResults,
);
const args = [
"query",
trimmed,
"--json",
"-n",
String(limit),
...this.buildCollectionFilterArgs(),
];
const collectionFilterArgs = this.buildCollectionFilterArgs();
if (collectionFilterArgs.length === 0) {
log.warn("qmd query skipped: no managed collections configured");
return [];
}
const args = ["query", trimmed, "--json", "-n", String(limit), ...collectionFilterArgs];
let stdout: string;
try {
const result = await this.runQmd(args, { timeoutMs: this.qmd.limits.timeoutMs });