Memory: make QMD cache eviction callback idempotent

This commit is contained in:
Vignesh Natarajan
2026-02-07 17:01:46 -08:00
committed by Vignesh
parent c741d008dd
commit 6f1ba986b3
2 changed files with 42 additions and 2 deletions

View File

@@ -114,4 +114,35 @@ describe("getMemorySearchManager caching", () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(QmdMemoryManager.create).toHaveBeenCalledTimes(2);
});
it("does not evict a newer cached wrapper when closing an older failed wrapper", async () => {
const retryAgentId = "retry-agent-close";
const cfg = {
memory: { backend: "qmd", qmd: {} },
agents: { list: [{ id: retryAgentId, default: true, workspace: "/tmp/workspace" }] },
} as const;
mockPrimary.search.mockRejectedValueOnce(new Error("qmd query failed"));
const first = await getMemorySearchManager({ cfg, agentId: retryAgentId });
expect(first.manager).toBeTruthy();
if (!first.manager) {
throw new Error("manager missing");
}
await first.manager.search("hello");
const second = await getMemorySearchManager({ cfg, agentId: retryAgentId });
expect(second.manager).toBeTruthy();
if (!second.manager) {
throw new Error("manager missing");
}
expect(second.manager).not.toBe(first.manager);
await first.manager.close?.();
const third = await getMemorySearchManager({ cfg, agentId: retryAgentId });
expect(third.manager).toBe(second.manager);
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(QmdMemoryManager.create).toHaveBeenCalledTimes(2);
});
});