From 5d9915c38afa3a82aa2b49c641e60e6382670143 Mon Sep 17 00:00:00 2001 From: Priya Raman Date: Thu, 27 Aug 2026 04:31:31 +0000 Subject: [PATCH] fix(server): close the native Codex vertical-slice test's db client before teardown The test created a postgres client with createDb() inside the test body but never closed it. The embedded Postgres process could then shut down while the client still had a queued write, so the driver later threw an unhandled TypeError from a null socket. Close the client in afterAll, before the embedded database stops, matching the pattern every other integration test in this file's directory already uses. Co-authored-by: Paperclip --- .../native-runtime/native-codex-runner.integration.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/services/native-runtime/native-codex-runner.integration.test.ts b/server/src/services/native-runtime/native-codex-runner.integration.test.ts index feafba78c4f..aa3280055f6 100644 --- a/server/src/services/native-runtime/native-codex-runner.integration.test.ts +++ b/server/src/services/native-runtime/native-codex-runner.integration.test.ts @@ -90,6 +90,7 @@ describeEmbeddedPostgres("native Codex server vertical slice", () => { let temporary: Awaited> | null = null; let runtimeRoot: string | null = null; let server: Server | null = null; + let db: ReturnType | null = null; beforeAll(async () => { ensureRunnerTestBinaries(); @@ -107,13 +108,17 @@ describeEmbeddedPostgres("native Codex server vertical slice", () => { afterAll(async () => { runnerPrpWebSocketInternals.resetForTests(); await closeServer(server); + // Close the postgres client before the embedded database process stops. + // Otherwise a queued write can fire after the socket is gone and throw + // an unhandled TypeError from the driver's internals. + await db?.$client?.end?.({ timeout: 0 }); await temporary?.cleanup(); if (runtimeRoot) await rm(runtimeRoot, { recursive: true, force: true }); }); it("returns a durable result and resumes the provider session on the next run", async () => { if (!temporary || !runtimeRoot) throw new Error("Vertical-slice fixture was not initialized"); - const db = createDb(temporary.connectionString); + db = createDb(temporary.connectionString); const companyId = randomUUID(); const agentId = randomUUID(); const issueId = randomUUID();