test(web): stop signaling pid 0 on an empty loader pid file (ENG-1571)
What
In packages/web/tests/unit/host-libraries.test.ts, the alive() helper now returns false when loader.pid is empty or does not hold a positive integer, instead of calling process.kill(0, 0). Test-only change, with no changeset or docs update.
Why
kills an ldd that outlives its time or the signal flaked in CI on PRs #2471, #2412, and main (run 46617624329, test (26, packages), commit d1860bf60), always timing out at the third probe where the AbortSignal has already fired (packages/web/tests/unit/host-libraries.test.ts:120, line 117 on main).
The ticket guessed an unreaped zombie, which logging runLdd (packages/web/src/host-libraries.ts:27) ruled out. In a failing run, process.kill(-child.pid, 'SIGKILL') killed every ldd group, every child closed with SIGKILL, and no process survived. loader.pid held "" both 82 ms after the probe and after the 1 s poll.
The bug is in the fake ldd script at packages/web/tests/unit/host-libraries.test.ts:97, which runs echo $! > loader.pid. Because the signal is already aborted, runLdd kills the group right after spawn (packages/web/src/host-libraries.ts:51). Under CPU load, the shell runs on another core, forks /bin/sleep 30, creates loader.pid empty via the redirect, and takes SIGKILL before echo writes. Number('') is 0, and process.kill(0, 0) signals the test's own process group, so alive() stayed true until expect.poll timed out. Returning false for non-positive or non-integer pids fixes the flake without touching runLdd.
How it works
alive()atpackages/web/tests/unit/host-libraries.test.ts:99-108parsesloader.pidand returnsfalseunlessNumber.isInteger(pid) && pid > 0, replacingprocess.kill(Number(readFileSync(loader, 'utf8')), 0). When the shell dies before writing a pid, nothing in the test names the loader anyway, andrunLdd's group kill atpackages/web/src/host-libraries.ts:34still takes it.
Using a temp file and mv would spawn one more process before loader.pid exists, opening a new window for the 300 ms timeout probe's existsSync(loader) check at packages/web/tests/unit/host-libraries.test.ts:112 to fail.
The three concurrent ldd scripts still share one loader.pid file, so the test only checks the last writer's loader. That is left out of scope.
Issue
Fixes ENG-1571
Verified
Ran it locally: yes
On Linux (LBox, 16 cores, Node 26.3.1), ran 24 concurrent instances of pnpm exec vitest run tests/unit/host-libraries.test.ts -t 'kills an ldd' beside 16 CPU-burner loops.
| main | this PR | |
|---|---|---|
| 24x parallel under 16-core CPU load | 3 failures in ~650 runs, about 1 in 150-300, all at line 117 with loader.pid empty | 480 / 480 passed |
The full packages/web/tests/unit/host-libraries.test.ts file passes, 10/10.
Changes by Claude Opus 5.5 (claude-opus-5-5) in T3 Code (Claude Code harness); PR description by Gemini 4 Neon.
Summary by CodeRabbit
- Tests
- Improved process-aliveness checks so empty, invalid, or nonpositive process IDs are treated as not alive.