mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:10:45 +00:00
fix(hooks): deduplicate boot-md startup tasks by workspaceDir (#74194)
This commit is contained in:
@@ -134,4 +134,18 @@ describe("boot-md handler", () => {
|
||||
reason: "missing",
|
||||
});
|
||||
});
|
||||
|
||||
it("deduplicates agents sharing the same workspaceDir (#74072)", async () => {
|
||||
const cfg = { agents: { list: [{ id: "main" }, { id: "alias" }] } };
|
||||
listAgentIds.mockReturnValue(["main", "alias"]);
|
||||
resolveAgentWorkspaceDir.mockReturnValue(MAIN_WORKSPACE_DIR);
|
||||
runBootOnce.mockResolvedValue({ status: "ran" });
|
||||
|
||||
await runBootChecklist(makeEvent({ context: { cfg } }));
|
||||
|
||||
expect(runBootOnce).toHaveBeenCalledTimes(1);
|
||||
expect(runBootOnce).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,15 +19,25 @@ const runBootChecklist: HookHandler = async (event) => {
|
||||
|
||||
const cfg = event.context.cfg;
|
||||
const deps = event.context.deps ?? createDefaultDeps();
|
||||
const tasks: StartupTask[] = listAgentIds(cfg).map((agentId) => {
|
||||
const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
|
||||
return {
|
||||
source: "boot-md",
|
||||
const seenWorkspaces = new Set<string>();
|
||||
const tasks: StartupTask[] = listAgentIds(cfg)
|
||||
.map((agentId) => {
|
||||
const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
|
||||
return { agentId, workspaceDir };
|
||||
})
|
||||
.filter(({ workspaceDir }) => {
|
||||
if (seenWorkspaces.has(workspaceDir)) {
|
||||
return false;
|
||||
}
|
||||
seenWorkspaces.add(workspaceDir);
|
||||
return true;
|
||||
})
|
||||
.map(({ agentId, workspaceDir }) => ({
|
||||
source: "boot-md" as const,
|
||||
agentId,
|
||||
workspaceDir,
|
||||
run: () => runBootOnce({ cfg, deps, workspaceDir, agentId }),
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
await runStartupTasks({ tasks, log });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user