Skip to content

Commit 08a0bac

Browse files
committed
fix(memory): reuse full qmd manager for status
1 parent 3d72fce commit 08a0bac

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/memory/search-manager.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ describe("getMemorySearchManager caching", () => {
216216
expect(second.manager).toBe(first.manager);
217217
});
218218

219+
it("reuses cached full qmd manager for status-only requests", async () => {
220+
const agentId = "status-reuses-full-agent";
221+
const cfg = createQmdCfg(agentId);
222+
223+
const full = await getMemorySearchManager({ cfg, agentId });
224+
const status = await getMemorySearchManager({ cfg, agentId, purpose: "status" });
225+
226+
requireManager(full);
227+
requireManager(status);
228+
expect(status.manager).toBe(full.manager);
229+
// eslint-disable-next-line @typescript-eslint/unbound-method
230+
expect(createQmdManagerMock).toHaveBeenCalledTimes(1);
231+
});
232+
219233
it("does not evict a newer cached wrapper when closing an older failed wrapper", async () => {
220234
const retryAgentId = "retry-agent-close";
221235
const {

src/memory/search-manager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ export async function getMemorySearchManager(params: {
5252
if (cached) {
5353
return { manager: cached };
5454
}
55+
if (statusOnly) {
56+
// Reuse an existing full manager for status requests to avoid duplicate
57+
// QMD managers and extra sqlite handles for the same agent/config.
58+
const fullCached = QMD_MANAGER_CACHE.get(`${baseCacheKey}:full`);
59+
if (fullCached) {
60+
QMD_MANAGER_CACHE.set(cacheKey, fullCached);
61+
return { manager: fullCached };
62+
}
63+
}
5564
try {
5665
const { QmdMemoryManager } = await import("./qmd-manager.js");
5766
const primary = await QmdMemoryManager.create({

0 commit comments

Comments
 (0)