From 5d27cb426faaeacf73559535154ab18979c4d6fd Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Fri, 12 Jun 2026 12:07:44 -0700 Subject: [PATCH] refactor(eval): brainbench exits through the #2084 flushThenExit seam The hand-rolled grace-tick predates the merge of the central write-fence + aliveness-grace exit seam; same trap (PGLite exitCode hijack + Bun stdout discard), now one tested implementation. --- src/commands/eval-brainbench.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/commands/eval-brainbench.ts b/src/commands/eval-brainbench.ts index 228163844..e83efc760 100644 --- a/src/commands/eval-brainbench.ts +++ b/src/commands/eval-brainbench.ts @@ -18,6 +18,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { execSync } from 'node:child_process'; +import { flushThenExit } from '../core/cli-force-exit.ts'; import { cliOptsToProgressOptions, getCliOptions } from '../core/cli-options.ts'; import { createProgress } from '../core/progress.ts'; import { buildMetricGlossaryMeta } from '../core/eval/metric-glossary.ts'; @@ -216,14 +217,14 @@ function gitHeadSha(): string { /** * Bun discards queued stdout on process.exit and PGLite stomps - * process.exitCode on its own ticks — hold the verdict locally, give the - * event loop one grace window to drain pipes, then exit explicitly - * (learnings pglite-emscripten-hijacks-process-exitcode + - * bun-pipe-stdout-only-flushes-while-alive). + * process.exitCode on its own ticks — hold the verdict locally and exit + * through the #2084 central seam (write-fence + ref'd aliveness grace), + * which exists for exactly this trap. */ async function exitWith(code: 0 | 1 | 2): Promise { - await new Promise((resolve) => setTimeout(resolve, 300)); - process.exit(code); + flushThenExit(code); + // flushThenExit exits after its bounded fence + grace; never resolve. + return new Promise(() => {}); } function readBaselineFile(path: string): BrainBenchBaseline {