fix(hooks): deduplicate boot-md startup tasks by workspaceDir (#74194) · openclaw/openclaw@3af6613
yelog
·
2026-04-29
·
via Recent Commits to openclaw:main
File tree
src/hooks/bundled/boot-md
| Original file line number | Diff line number | Diff line change |
|---|
@@ -134,4 +134,18 @@ describe("boot-md handler", () => {
|
134 | 134 | reason: "missing", |
135 | 135 | }); |
136 | 136 | }); |
| 137 | + |
| 138 | +it("deduplicates agents sharing the same workspaceDir (#74072)", async () => { |
| 139 | +const cfg = { agents: { list: [{ id: "main" }, { id: "alias" }] } }; |
| 140 | +listAgentIds.mockReturnValue(["main", "alias"]); |
| 141 | +resolveAgentWorkspaceDir.mockReturnValue(MAIN_WORKSPACE_DIR); |
| 142 | +runBootOnce.mockResolvedValue({ status: "ran" }); |
| 143 | + |
| 144 | +await runBootChecklist(makeEvent({ context: { cfg } })); |
| 145 | + |
| 146 | +expect(runBootOnce).toHaveBeenCalledTimes(1); |
| 147 | +expect(runBootOnce).toHaveBeenCalledWith( |
| 148 | +expect.objectContaining({ cfg, workspaceDir: MAIN_WORKSPACE_DIR, agentId: "main" }), |
| 149 | +); |
| 150 | +}); |
137 | 151 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,15 +19,25 @@ const runBootChecklist: HookHandler = async (event) => {
|
19 | 19 | |
20 | 20 | const cfg = event.context.cfg; |
21 | 21 | const deps = event.context.deps ?? createDefaultDeps(); |
22 | | -const tasks: StartupTask[] = listAgentIds(cfg).map((agentId) => { |
23 | | -const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId); |
24 | | -return { |
25 | | -source: "boot-md", |
| 22 | +const seenWorkspaces = new Set<string>(); |
| 23 | +const tasks: StartupTask[] = listAgentIds(cfg) |
| 24 | +.map((agentId) => { |
| 25 | +const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId); |
| 26 | +return { agentId, workspaceDir }; |
| 27 | +}) |
| 28 | +.filter(({ workspaceDir }) => { |
| 29 | +if (seenWorkspaces.has(workspaceDir)) { |
| 30 | +return false; |
| 31 | +} |
| 32 | +seenWorkspaces.add(workspaceDir); |
| 33 | +return true; |
| 34 | +}) |
| 35 | +.map(({ agentId, workspaceDir }) => ({ |
| 36 | +source: "boot-md" as const, |
26 | 37 | agentId, |
27 | 38 | workspaceDir, |
28 | 39 | run: () => runBootOnce({ cfg, deps, workspaceDir, agentId }), |
29 | | -}; |
30 | | -}); |
| 40 | +})); |
31 | 41 | |
32 | 42 | await runStartupTasks({ tasks, log }); |
33 | 43 | }; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。