diff --git a/src/gateway/agent-list.test.ts b/src/gateway/agent-list.test.ts index 0cbc987f3d0c..1ac35f2d8d15 100644 --- a/src/gateway/agent-list.test.ts +++ b/src/gateway/agent-list.test.ts @@ -1,11 +1,28 @@ /** * Gateway agent-list RPC regression tests. */ +import fs from "node:fs/promises"; +import path from "node:path"; import { describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; +import { withStateDirEnv } from "../test-helpers/state-dir-env.js"; import { listGatewayAgentsBasic } from "./agent-list.js"; describe("listGatewayAgentsBasic", () => { + it("omits reserved system-agent state directories from the discovered roster", async () => { + await withStateDirEnv("openclaw-agent-list-", async ({ stateDir }) => { + await Promise.all( + ["openclaw", "crestodian", "research"].map((id) => + fs.mkdir(path.join(stateDir, "agents", id), { recursive: true }), + ), + ); + + const result = listGatewayAgentsBasic({}); + + expect(result.agents.map((agent) => agent.id)).toEqual(["main", "research"]); + }); + }); + it("falls back to identity.name when the configured agent name is missing", () => { const cfg: OpenClawConfig = { session: { mainKey: "main" }, diff --git a/src/gateway/agent-list.ts b/src/gateway/agent-list.ts index 78e04348032a..e5fa6837d882 100644 --- a/src/gateway/agent-list.ts +++ b/src/gateway/agent-list.ts @@ -8,6 +8,7 @@ import { resolveStateDir } from "../config/paths.js"; import type { SessionScope } from "../config/sessions.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { normalizeAgentId, normalizeMainKey } from "../routing/session-key.js"; +import { isReservedSystemAgentId } from "../system-agent/agent-id.js"; type GatewayAgentListRow = { id: string; @@ -22,7 +23,7 @@ function listExistingAgentIdsFromDisk(): string[] { return entries .filter((entry) => entry.isDirectory()) .map((entry) => normalizeAgentId(entry.name)) - .filter(Boolean); + .filter((id) => id && !isReservedSystemAgentId(id)); } catch { return []; }