fix(hooks): deduplicate boot-md startup tasks by workspaceDir (#74194)

This commit is contained in:
Logan Ye
2026-04-29 17:48:31 +08:00
committed by GitHub
parent d7cc8d0b03
commit 3af661384c
2 changed files with 30 additions and 6 deletions

View File

@@ -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" }),
);
});
});

View File

@@ -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 });
};