Keep the ai-chat model-map build inside the server lifecycle

onServerStart fired #buildModelMap without awaiting or tracking it, so
the network fetches it does (notably Ollama auto-discovery, which is
enabled by default and doomed on any machine without a local Ollama)
kept running after server.shutdown() resolved. In vitest that let the
provider's console.error land during worker teardown, which surfaces as
"Closing rpc while onUserConsoleLog was pending" — the unhandled error
that intermittently fails CI (last seen attributed to
WispController.test.ts). A rejection in the detached chain would also
have been an unhandled rejection.

Track the promise, catch and log rejections, and await it from
onServerShutdown so no provider I/O or logging outlives the server.
Also disable Ollama auto-discovery in setupTestServer's defaults —
every test server was firing a pointless model-list fetch at localhost.
This commit is contained in:
jelveh
2026-07-26 12:15:56 -07:00
parent f20448cf98
commit 1b2482dcb8
2 changed files with 16 additions and 1 deletions
@@ -216,10 +216,22 @@ export class ChatCompletionDriver extends PuterDriver {
#providers: Record<string, IChatProvider> = {};
#modelIdMap: Record<string, IChatModel[]> = {};
#modelMapReady: Promise<void> = Promise.resolve();
override onServerStart() {
this.#registerProviders();
this.#buildModelMap();
// Not awaited — providers fetch model lists over the network and
// boot must not block on their latency. Shutdown awaits the
// tracked promise so provider I/O (and its error logging) never
// outlives the server; a rejection here must not become an
// unhandled one.
this.#modelMapReady = this.#buildModelMap().catch((e) => {
console.error('Failed to build ai-chat model map:', e);
});
}
override async onServerShutdown() {
await this.#modelMapReady;
}
// -- Interface methods -------------------------------------------
+3
View File
@@ -153,6 +153,9 @@ export const setupTestServer = async (
no_devwatch: true,
no_browser_launch: true,
import_ts_extensions: true,
// No local-Ollama auto-discovery: every test server would
// otherwise fire a doomed model-list fetch at localhost.
providers: { ollama: { enabled: false } },
}),
configOverrides ?? {},
) as IConfig;