fix (gateway/memory): start qmd onBoot for all agents
This commit is contained in:
@@ -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"',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<void> {
|
||||
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}"`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user