Skip to content

Stop two agent-runtime process-lifecycle tests from depending on process start speed - #8147

Merged
ymichael merged 2 commits into
mainfrom
fix-stderr-drain-test-flake
Nov 25, 2026
Merged

ymichael merged 2 commits into
mainfrom
fix-stderr-drain-test-flake

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Two tests in packages/agent-runtime/src/runtime.process-lifecycle.test.ts fail at random in Tests (packages-host) on loaded runners. Both depend on how fast processes start under CPU load.

drains provider stderr before reporting process exit fails with expected null to be 'stderr-after-exit', for example on #8075's merge run (job, 2286 ms). The fake provider spawned a grandchild that inherits stderr, then exited at once. The grandchild had to boot Node and wait 50 ms before writing. After a provider exits, the runtime waits at most PROVIDER_PROCESS_CLOSE_GRACE_MS (1 s) for stderr to close. On a loaded runner, Node startup alone can take longer than that.

does not wait for stalled replacement initialization during full shutdown times out at 15 s, followed by an unhandled Provider "fake" failed to start: spawn .../node ENOENT (job; it failed on all three attempts of that branch, and took 12.1 s on #8076's passing run). Before reaching its stalled replacement, the test started and retired a full scripted-echo bridge. #8141 measured a full start at 3.7–4.6 s under load, and stopping one can take up to 5 s plus kill and stderr grace periods. On other PRs' loaded runs the test took 3–12 s. When it overran, Vitest timed the test out but its body kept running. afterEach removed tmpDir, and the replacement then spawned into the missing cwd, which Node reports as spawn <node> ENOENT. The ENOENT is a consequence of the timeout, not its cause. #8136 and #8141 fixed the sibling retirement tests the same way; this one was left.

What changed

runtime.process-lifecycle.test.ts only. No runtime code changes.

  • stderr drain: the grandchild reports ready over IPC, the provider exits only after that, and the grandchild writes to stderr 50 ms after the IPC channel disconnects, which happens when the provider exits. The write still lands after the exit, but Node startup no longer counts toward the 1 s grace period.
  • stalled shutdown: the first process is the idle child (process.stdin.resume(), no post-initialize requests) that the sibling tests use. The adapter it uses is pulled out into a createIdleAdapter helper that createIdleProviderManager now shares. The replacement still uses the real fake adapter on the raw stalled script, so it receives initialize and holds its reply for 3 s, which is the behavior under test.

How you verified

CPU starvation locally: the test runs at background QoS (taskpolicy -b) next to 32 busy-loop processes on a 16-core Mac. This reproduces both CI failures.

Test Before After
stderr drain 2 CI-assertion failures before I stopped it 6 of 6 pass
stalled shutdown 2 of 4 time out (18.9 s, 21.4 s); passes took 13.1 s and 2.3 s 4 of 4 pass in 198–358 ms

Both tests still catch the bugs they guard:

  • stderr drain: with PROVIDER_PROCESS_CLOSE_GRACE_MS temporarily set to 0, the new test fails 3 of 3.
  • stalled shutdown: with shutdown() temporarily changed to await in-flight provider starts, the new test fails.

pnpm exec turbo run typecheck lint test --filter=@bb/agent-runtime: pass (316 tests, 1 skipped).

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 24, 2026 15:42
"drains provider stderr before reporting process exit" spawned a
grandchild that booted Node and then waited 50 ms before writing to the
inherited stderr, while the provider exited at once. The runtime waits at
most PROVIDER_PROCESS_CLOSE_GRACE_MS (1 s) after exit for stderr to close,
so on a loaded runner Node startup alone overran the grace period and the
exit callback saw no stderr. The grandchild now reports ready over IPC,
the provider exits only then, and the grandchild writes 50 ms after the
IPC channel disconnects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"does not wait for stalled replacement initialization during full
shutdown" started and retired a full scripted-echo bridge before its
stalled replacement, and that start and retirement took 3-12 s on loaded
CI runners against a 15 s deadline. When it overran, the timed-out test
body kept running after afterEach removed tmpDir and spawned the
replacement into the missing cwd, which surfaced as an unhandled
"spawn node ENOENT". The first process is now the idle child that #8136
and #8141 use for the sibling retirement tests; the stalled replacement
still uses the real fake adapter so it receives initialize and holds its
reply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael ymichael changed the title Start the stderr-drain test's late writer before the provider exits Stop two agent-runtime process-lifecycle tests from depending on process start speed Nov 25, 2026
@ymichael
ymichael merged commit 06d3c31 into main Nov 25, 2026
34 checks passed
@ymichael
ymichael deleted the fix-stderr-drain-test-flake branch November 25, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant