Skip to content

Commit cd7a9d2

Browse files
committed
fix(gateway): avoid quadratic session store discovery
Configured agents now use their canonical direct store paths while retired and manual owners retain broad discovery. This prevents Gateway startup prewarm from rescanning every agent root once per configured agent.
1 parent e9d70a1 commit cd7a9d2

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎src/config/sessions/targets.test.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import { withTempHome } from "openclaw/plugin-sdk/test-env";
5-
import { describe, expect, it } from "vitest";
5+
import { describe, expect, it, vi } from "vitest";
6+
import * as sessionDirs from "../../agents/session-dirs.js";
67
import {
78
registerOpenClawAgentDatabase,
89
unregisterOpenClawAgentDatabase,
@@ -615,14 +616,22 @@ describe("resolveAgentSessionStoreTargetsSync", () => {
615616
await withTempHome(async (home) => {
616617
const customRoot = path.join(home, "custom-state");
617618
const storePaths = await createAgentSessionStores(customRoot, ["main", "codex"]);
618-
const cfg = createCustomRootCfg(customRoot, "main");
619-
620-
expect(resolveAgentSessionStoreTargetsSync(cfg, "codex", { env: process.env })).toEqual([
621-
{
622-
agentId: "codex",
623-
storePath: storePaths.codex,
624-
},
625-
]);
619+
const cfg: OpenClawConfig = {
620+
...createCustomRootCfg(customRoot, "main"),
621+
agents: { list: [{ id: "main", default: true }, { id: "codex" }] },
622+
};
623+
const enumerateAgentDirs = vi.spyOn(sessionDirs, "resolveAgentSessionDirsFromAgentsDirSync");
624+
try {
625+
expect(resolveAgentSessionStoreTargetsSync(cfg, "codex", { env: process.env })).toEqual([
626+
{
627+
agentId: "codex",
628+
storePath: storePaths.codex,
629+
},
630+
]);
631+
expect(enumerateAgentDirs).not.toHaveBeenCalled();
632+
} finally {
633+
enumerateAgentDirs.mockRestore();
634+
}
626635
});
627636
});
628637

‎src/config/sessions/targets.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ export function resolveAgentSessionStoreTargetsSync(
575575
}
576576
}
577577

578+
// Configured agents own canonical direct paths; broad discovery is retired/manual-only.
579+
// Falling through here makes per-agent Gateway prewarm scan the full roster quadratically.
580+
if (isConfiguredSessionStoreAgentId(cfg, requested)) {
581+
return dedupeTargetsByStorePath(targets);
582+
}
583+
578584
const { agentsRoots } = resolveSessionStoreDiscoveryState(cfg, env);
579585
for (const agentsDir of agentsRoots) {
580586
try {

0 commit comments

Comments
 (0)