Repository navigation
fix(bench): keep V8 trace harness stdout off a non-blocking pipe - #1569
Merged
Merged
Conversation
The client-hot-paths and ssr-final-replay function harnesses parsed V8's
--print-bytecode/--trace-opt/DebugPrint output and a FUNCTIONS_JSON result
line from one piped stdout. Node makes that pipe O_NONBLOCK, so when the
parent drains slowly V8's C-stdio writes fail with EAGAIN and records are
dropped or split mid-line ("worker did not return results", "<name>
bytecode missing", or a silently shorter optimizationTrace).
Give the worker a regular file for stdout, which never blocks, and have it
write its result to a file named by CLIENT_FUNCTION_RESULT /
SSR_FUNCTION_RESULT. Manual --worker runs without the variable still print
FUNCTIONS_JSON. Both temp files are removed after reading.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 14:55
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
3 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two V8 diagnostic harnesses,
benchmarks/client-hot-paths/functions.mjsandbenchmarks/ssr-final-replay/diagnostics.mjs, spawn a worker with--print-bytecode,--trace-optand%DebugPrint. Each one parsed V8's native trace output and aFUNCTIONS_JSONresult line from the same piped stdout. On a loaded machine that protocol drops or splits records. This PR moves both harnesses onto file-backed stdout.Why it breaks: Node switches a stdout pipe to
O_NONBLOCKthe first timeprocess.stdoutis touched. V8 writes its traces through C stdio on that same fd. When the parent drains the pipe slowly, those writes fail withEAGAIN, and records are lost or split mid-line. The harness then fails withworker did not return resultsor<name> bytecode missing. Under milder load it can instead exit 0 with a report that is quietly missing trace lines.Change (identical in both harnesses):
run()opens a regular file for the worker's stdout and passesstdio: ['ignore', fd, 'pipe']. A regular file never blocks, and Node writes to it synchronously. Stderr stays piped.CLIENT_FUNCTION_RESULT/SSR_FUNCTION_RESULT. When the variable is unset, it still printsFUNCTIONS_JSONfor manual--workerruns.worker-<pid>-<n>.log/.json, in the harness'snode_modules/.cachedirectory) are removed after reading, including when the worker fails. A failing worker still reports its stderr plus the tail of stdout.The
functions.mjschange is copied byte-for-byte from the session that found the problem, so both harness fixes ship together here.No changeset: this is internal benchmark tooling with no package or user-facing change.
Validation
All runs on Node 24.18 / V8 13.6, darwin arm64, on a machine with a load average of about 35–50.
Idle report unchanged.
diagnostics.mjs: three patched runs are byte-identical to the pre-change report in every field, including all 19optimizationTracelines.functions.mjs: every field exceptoptimizationTracematches the pre-change report. The two pre-change runs differ from each other there, by V8's globalopt idcounter, so that field already varied run to run. Two patched runs are identical to each other.Throttled drain, worker level. I piped the SSR worker's stdout through a slow reader (4 KB reads, 5 ms sleeps). Output shrank from 4.16 MB to 2.93 MB, 2 of the 3 target bytecode records were lost, and 2
FUNCTION_REFERENCEmarkers landed mid-line. An earlier client-worker reproduction (2 KB reads, 0.3 ms sleeps) shrank stdout from about 15.8 MB to 11.9 MB and lost thecomponentSlotImplbytecode record.Throttled drain, end to end. Each harness ran while its own process was SIGSTOP/SIGCONT-cycled, so it drained the worker's output slowly:
ssr-final-replay/diagnostics.mjsssrTry bytecode missingclient-hot-paths/functions.mjsreconcileKeyed bytecode missingmapSlotdeopt event differs in kind (JIT variance, not loss)With a weaker, late-starting throttle, the old SSR harness exited 0 but silently dropped the
ssrTrydeopt line fromoptimizationTrace.Also checked:
SSR_FUNCTION_TRACE_DIRECTORYstill dumps the full worker stdout.worker-*temp files remain after any run.Gates:
pnpm sync: no generated changespnpm format:files:checkon both filespnpm typecheck(these.mjsharnesses belong to no TypeScript project)pnpm test: not run. Neither harness is imported by a test or invoked by CI.Risk / follow-ups
Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Changes are limited to internal benchmark harnesses that are not run in CI and do not affect packages or runtime behavior.
Overview
Fixes flaky or silently incomplete V8 diagnostic reports in
benchmarks/client-hot-paths/functions.mjsandbenchmarks/ssr-final-replay/diagnostics.mjswhen the parent process drains the worker’s stdout slowly. V8 writes traces through C stdio on a pipe that Node marks non-blocking, which can drop or split lines and break bytecode/trace parsing (or pass with missing trace data).Each harness’s
run()now sends worker stdout to a cache-dir log file (stdio: ['ignore', fd, 'pipe']) and reads it back after the child exits. Structured results go to a separate JSON file viaCLIENT_FUNCTION_RESULT/SSR_FUNCTION_RESULTinstead of aFUNCTIONS_JSONline mixed into the trace stream; manual--workerruns still logFUNCTIONS_JSONwhen those env vars are unset. Temp.log/.jsonfiles are removed after reading, including on failure.Reviewed by Cursor Bugbot for commit 2f51fd9. Bugbot is set up for automated code reviews on this repo. Configure here.