From 02c268eec1e56d5db6771c2b4ec1dd2f3c8091e0 Mon Sep 17 00:00:00 2001 From: Vignesh Natarajan Date: Mon, 16 Feb 2026 10:35:12 -0800 Subject: [PATCH] fix (gateway/memory): start qmd onBoot for all agents --- src/gateway/server-startup-memory.test.ts | 25 ++++++++++++++------ src/gateway/server-startup-memory.ts | 28 ++++++++++++----------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/gateway/server-startup-memory.test.ts b/src/gateway/server-startup-memory.test.ts index 77a4db4d8..fd4be09e2 100644 --- a/src/gateway/server-startup-memory.test.ts +++ b/src/gateway/server-startup-memory.test.ts @@ -30,7 +30,7 @@ describe("startGatewayMemoryBackend", () => { expect(log.warn).not.toHaveBeenCalled(); }); - it("initializes qmd backend for the default agent", async () => { + it("initializes qmd backend for each configured agent", async () => { const cfg = { agents: { list: [{ id: "ops", default: true }, { id: "main" }] }, memory: { backend: "qmd", qmd: {} }, @@ -40,26 +40,37 @@ describe("startGatewayMemoryBackend", () => { await startGatewayMemoryBackend({ cfg, log }); - expect(getMemorySearchManagerMock).toHaveBeenCalledWith({ cfg, agentId: "ops" }); - expect(log.info).toHaveBeenCalledWith( + expect(getMemorySearchManagerMock).toHaveBeenCalledTimes(2); + expect(getMemorySearchManagerMock).toHaveBeenNthCalledWith(1, { cfg, agentId: "ops" }); + expect(getMemorySearchManagerMock).toHaveBeenNthCalledWith(2, { cfg, agentId: "main" }); + expect(log.info).toHaveBeenNthCalledWith( + 1, 'qmd memory startup initialization armed for agent "ops"', ); + expect(log.info).toHaveBeenNthCalledWith( + 2, + 'qmd memory startup initialization armed for agent "main"', + ); expect(log.warn).not.toHaveBeenCalled(); }); - it("logs a warning when qmd manager init fails", async () => { + it("logs a warning when qmd manager init fails and continues with other agents", async () => { const cfg = { - agents: { list: [{ id: "main", default: true }] }, + agents: { list: [{ id: "main", default: true }, { id: "ops" }] }, memory: { backend: "qmd", qmd: {} }, } as OpenClawConfig; const log = { info: vi.fn(), warn: vi.fn() }; - getMemorySearchManagerMock.mockResolvedValue({ manager: null, error: "qmd missing" }); + getMemorySearchManagerMock + .mockResolvedValueOnce({ manager: null, error: "qmd missing" }) + .mockResolvedValueOnce({ manager: { search: vi.fn() } }); await startGatewayMemoryBackend({ cfg, log }); expect(log.warn).toHaveBeenCalledWith( 'qmd memory startup initialization failed for agent "main": qmd missing', ); - expect(log.info).not.toHaveBeenCalled(); + expect(log.info).toHaveBeenCalledWith( + 'qmd memory startup initialization armed for agent "ops"', + ); }); }); diff --git a/src/gateway/server-startup-memory.ts b/src/gateway/server-startup-memory.ts index 11360e601..5ead1518e 100644 --- a/src/gateway/server-startup-memory.ts +++ b/src/gateway/server-startup-memory.ts @@ -1,5 +1,5 @@ import type { OpenClawConfig } from "../config/config.js"; -import { resolveDefaultAgentId } from "../agents/agent-scope.js"; +import { listAgentIds } from "../agents/agent-scope.js"; import { resolveMemoryBackendConfig } from "../memory/backend-config.js"; import { getMemorySearchManager } from "../memory/index.js"; @@ -7,18 +7,20 @@ export async function startGatewayMemoryBackend(params: { cfg: OpenClawConfig; log: { info?: (msg: string) => void; warn: (msg: string) => void }; }): Promise { - const agentId = resolveDefaultAgentId(params.cfg); - const resolved = resolveMemoryBackendConfig({ cfg: params.cfg, agentId }); - if (resolved.backend !== "qmd" || !resolved.qmd) { - return; - } + const agentIds = listAgentIds(params.cfg); + for (const agentId of agentIds) { + const resolved = resolveMemoryBackendConfig({ cfg: params.cfg, agentId }); + if (resolved.backend !== "qmd" || !resolved.qmd) { + continue; + } - const { manager, error } = await getMemorySearchManager({ cfg: params.cfg, agentId }); - if (!manager) { - params.log.warn( - `qmd memory startup initialization failed for agent "${agentId}": ${error ?? "unknown error"}`, - ); - return; + const { manager, error } = await getMemorySearchManager({ cfg: params.cfg, agentId }); + if (!manager) { + params.log.warn( + `qmd memory startup initialization failed for agent "${agentId}": ${error ?? "unknown error"}`, + ); + continue; + } + params.log.info?.(`qmd memory startup initialization armed for agent "${agentId}"`); } - params.log.info?.(`qmd memory startup initialization armed for agent "${agentId}"`); }