fix(context): skip eager warmup for non-model CLI commands

This commit is contained in:
Vincent Koc 2026-03-14 23:18:26 -07:00
parent 8e4a1d87e2
commit d1e4ee03ff
2 changed files with 31 additions and 2 deletions

View File

@ -90,6 +90,20 @@ describe("lookupContextTokens", () => {
}
});
it("skips eager warmup for logs commands that do not need model metadata at startup", async () => {
const loadConfigMock = vi.fn(() => ({ models: {} }));
mockContextModuleDeps(loadConfigMock);
const argvSnapshot = process.argv;
process.argv = ["node", "openclaw", "logs", "--limit", "5"];
try {
await import("./context.js");
expect(loadConfigMock).not.toHaveBeenCalled();
} finally {
process.argv = argvSnapshot;
}
});
it("retries config loading after backoff when an initial load fails", async () => {
vi.useFakeTimers();
const loadConfigMock = vi

View File

@ -108,9 +108,24 @@ function getCommandPathFromArgv(argv: string[]): string[] {
return tokens;
}
const SKIP_EAGER_WARMUP_PRIMARY_COMMANDS = new Set([
"backup",
"completion",
"config",
"directory",
"doctor",
"health",
"hooks",
"logs",
"plugins",
"secrets",
"update",
"webhooks",
]);
function shouldSkipEagerContextWindowWarmup(argv: string[] = process.argv): boolean {
const [primary, secondary] = getCommandPathFromArgv(argv);
return primary === "config" && secondary === "validate";
const [primary] = getCommandPathFromArgv(argv);
return primary ? SKIP_EAGER_WARMUP_PRIMARY_COMMANDS.has(primary) : false;
}
function primeConfiguredContextWindows(): OpenClawConfig | undefined {