From 0f24a8d8e18bd4d3e9383c86f064ee33067f1be8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 10:18:40 +0100 Subject: [PATCH] test: isolate gateway prewarm scheduling --- src/gateway/server-startup-post-attach.test.ts | 6 +++--- src/gateway/server-startup-post-attach.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gateway/server-startup-post-attach.test.ts b/src/gateway/server-startup-post-attach.test.ts index a68103bba38..d7fd1f1907a 100644 --- a/src/gateway/server-startup-post-attach.test.ts +++ b/src/gateway/server-startup-post-attach.test.ts @@ -313,9 +313,8 @@ describe("startGatewayPostAttachRuntime", () => { }); it("starts channels without waiting for primary model prewarm completion", async () => { - hoisted.resolveAgentModelPrimaryValue.mockReturnValue("openai/gpt-5.4"); let resolvePrewarm!: () => void; - hoisted.ensureOpenClawModelsJson.mockImplementation( + const prewarmPrimaryModel = vi.fn( async () => await new Promise((resolve) => { resolvePrewarm = () => resolve(undefined); @@ -332,6 +331,7 @@ describe("startGatewayPostAttachRuntime", () => { defaultWorkspaceDir: "/tmp/openclaw-workspace", deps: {} as never, startChannels, + prewarmPrimaryModel: prewarmPrimaryModel as never, log: { warn: vi.fn() }, logHooks: { info: vi.fn(), @@ -346,7 +346,7 @@ describe("startGatewayPostAttachRuntime", () => { await vi.waitFor( () => { - expect(hoisted.ensureOpenClawModelsJson).toHaveBeenCalledTimes(1); + expect(prewarmPrimaryModel).toHaveBeenCalledTimes(1); expect(startChannels).toHaveBeenCalledTimes(1); }, { timeout: 2_000 }, diff --git a/src/gateway/server-startup-post-attach.ts b/src/gateway/server-startup-post-attach.ts index d91ec5f7a4c..a0d791b605c 100644 --- a/src/gateway/server-startup-post-attach.ts +++ b/src/gateway/server-startup-post-attach.ts @@ -208,6 +208,7 @@ export async function startGatewaySidecars(params: { defaultWorkspaceDir: string; deps: CliDeps; startChannels: () => Promise; + prewarmPrimaryModel?: typeof prewarmConfiguredPrimaryModel; log: { warn: (msg: string) => void }; logHooks: { info: (msg: string) => void; @@ -329,11 +330,14 @@ export async function startGatewaySidecars(params: { await measureStartup(params.startupTrace, "sidecars.channels", async () => { if (!skipChannels) { try { - schedulePrimaryModelPrewarm({ - cfg: params.cfg, - log: params.log, - startupTrace: params.startupTrace, - }); + schedulePrimaryModelPrewarm( + { + cfg: params.cfg, + log: params.log, + startupTrace: params.startupTrace, + }, + params.prewarmPrimaryModel, + ); await measureStartup(params.startupTrace, "sidecars.channel-start", () => params.startChannels(), );