Skip to content

test(web): stop signaling pid 0 on an empty loader pid file (ENG-1571) - #2578

Merged
okwasniewski merged 1 commit into
mainfrom
krzysztof/eng-1571-flaky-host-libraries-test
Dec 1, 2026
Merged

okwasniewski merged 1 commit into
mainfrom
krzysztof/eng-1571-flaky-host-libraries-test

Conversation

@KrzysztofMoch

@KrzysztofMoch KrzysztofMoch commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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

  1. alive() at packages/web/tests/unit/host-libraries.test.ts:99-108 parses loader.pid and returns false unless Number.isInteger(pid) && pid > 0, replacing process.kill(Number(readFileSync(loader, 'utf8')), 0). When the shell dies before writing a pid, nothing in the test names the loader anyway, and runLdd's group kill at packages/web/src/host-libraries.ts:34 still 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.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Tests
    • Improved process-aliveness checks so empty, invalid, or nonpositive process IDs are treated as not alive.

The fake ldd writes the loader's pid with a redirect. Under load the group
kill can land between the redirect's open and the echo, leaving an empty
file. Number('') is 0, and kill(0, 0) signals the test's own process group,
so the test saw the loader alive until its poll timed out. Read a pid that
is not a positive integer as no loader recorded.
@github-actions github-actions Bot added e2e team Opened by the e2e team size:XS Up to 9 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Dec 1, 2026
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Loader liveness

Layer / File(s) Summary
Validate loader PID
packages/web/tests/unit/host-libraries.test.ts
The helper rejects empty, invalid, or nonpositive PID values before probing the process.

Change: Other

Merge Risk: Minimal · up to 7c5e1

This fixes a flaky unit test by treating an empty or invalid loader PID as not alive. It has no production impact and is safe to merge.

Security architecture risk: Minimal · up to 7c5e1

The change prevents an empty PID file from making a unit test check its own process group. It does not change how the product starts or stops processes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae5eb41c-198e-47bf-9be0-d78d285d7680
Commits

Reviewing files that changed from the base of the PR and between 990e0dc and 7c5e1a6.

Files selected for processing: 1

  • packages/web/tests/unit/host-libraries.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

View guided diff | Turn on auto-fix | Re-trigger cubic

@KrzysztofMoch KrzysztofMoch added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Dec 1, 2026
@KrzysztofMoch
KrzysztofMoch added this pull request to the merge queue Dec 1, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 1, 2026

@michal-e2e michal-e2e left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drafted by an AI agent and posted autonomously on Michal's behalf, without him reading it first.

Reviewed 7c5e1a618. Must fix: none.

The PID check keeps an empty loader.pid from making the test probe its own process group. A live positive PID still reaches the probe. Approval stays with the maintainer.

@okwasniewski
okwasniewski merged commit dd5d409 into main Dec 1, 2026
47 checks passed
@okwasniewski
okwasniewski deleted the krzysztof/eng-1571-flaky-host-libraries-test branch December 1, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e team Opened by the e2e team Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:XS Up to 9 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants