test(ssh): zombie-reap launch test no longer races the shell #20052
main fromrefs/pull/20052/head·opened View on GitHubProblem#
launch script > replaces a managed server that exited but was not reaped in packages/ssh/src/tunnel.test.ts fails intermittently on CI with AssertionError: expected '' to include 'Z' (example run, on a PR that does not touch packages/ssh).
The test built its zombie with sh -c "sleep 600 & echo $!; exec sleep 600", killed the background pid as soon as it was printed, and then expected ps to report Z. When the kill lands before sh reaches exec, dash is still the parent and reaps the child: on SIGCHLD it runs wait4(-1, WNOHANG) between commands. No zombie is left, so ps prints nothing.
Change#
The test now kills the child only after sh has exec'd into node. Node does not reap a child it did not spawn, because libuv only waits on its own process handles. Node prints the pid from its SIGCHLD handler, which the kernel only sends once the child is a zombie. The test reads that line instead of waiting on a timer, so it now checks ps once. That replaces the polling loop #15715 added for the same flake. The rest of the test is unchanged.
Scope and approval#
Test-only fix for an obvious flake, with one problem in one file and no product behavior change, so it qualifies as a very small, focused fix without a prior issue.
Verification#
- Root cause. On Linux with dash,
straceof the old shape showed dash reaping the background child withwait4(-1, WNOHANG)after SIGCHLD and beforeexec. Widening the window betweenechoandexecwith a builtin-only busy loop reproduced the emptypsoutput in 9 of 10 runs. - Polling loop on
main. The loop #15715 added covers a kill that has not finished yet, but not this reap. A standalone repro ofmain's exact check passed 100 of 100 times with the natural timing. With the kill forced beforeexec, it failed 10 of 10 times, exiting 1 with empty output:psfinds no process and the loop exits at once. - Still failing on
mainwith the loop. In the first five hours after #15715 merged, this test failed 5 times at the loop's ownassert.equal(zombieState.exitCode, 0, zombieState.stdout)(tunnel.test.ts:1472). Four were pushes tomainthat include #15715 (1, 2, 3, 4) and one was a PR run. Each message is a bareexpected 1 to equal +0with no loop output in front of it. Empty output meanspsfound no process on its first try: the child had already been reaped. A child still dying would have printedSorR. These came from the logs of all 128 failed test jobs in CI runs since #15715 merged. - New setup. A standalone script performing the same steps as the test produced a zombie 100 of 100 times idle and 100 of 100 times with every core saturated by busy loops.
- Focused test.
vp test run packages/ssh/src/tunnel.test.ts -t "replaces a managed server that exited but was not reaped"passed 50 of 50 runs idle and 50 of 50 with all cores loaded. The same loops passed again after rebasing onto currentmain, and a full run oftunnel.test.tspassed 34 of 34.vp lintandvp fmt --checkon the file are clean. - Not checked. macOS was not run.
/bin/shthere is bash, whose own reaping is the same hazard the new setup avoids, but this is unverified on a Mac.
Written with Claude Opus 5.5 in Claude Code (T3 Code); reviewed with GPT-6.1-Sol in Codex.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This is a small, ignored test-only fix with no apparent product-runtime change. The modified file is within the SSH/authentication-sensitive package, so human review is required under the safety criteria.
Notes:
- No code objects were reviewed. Approvability was decided on eligibility alone.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8905c2df-d8ad-41e5-add6-515f3ff2f20e
📥 Commits
-
Reviewing files that changed from the base of the PR and between 1cae508878a1063710569725bf8a65cd5e921f2a and b3d651a5999b6de57e5c919d51a458263f5eff5e.
📒 Files selected for processing: 1
-
packages/ssh/src/tunnel.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The zombie-process test replaces shell-based polling with a Node-controlled fixture. The fixture kills the child after
SIGCHLD, prints its PID, and verifies thatpsreports zombie state before testing replacement.Changes: SSH tunnel zombie-process test
Layer / File(s) Summary Zombie-process test setup
packages/ssh/src/tunnel.test.tsThe test uses a Node-controlled child process fixture. It prints the child PID after the child is killed and SIGCHLDis received. The test directly verifies the zombie state and retains the replacement check.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~5 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
b3d65-
The test-only change has no identified issue blocking merge, subject to normal checks.
Architecture risk: 🔵 Low · up to
b3d65-
The change affects 1 system.
Changed systems:
packages/sshArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — packages/ssh (library) was modified; 1 changed file maps to changed impact.
Before / after behavior
- observed — Modified behavior in packages/ssh/src/tunnel.test.ts: The test replaces its shell-based zombie setup and polling loop with a Node-controlled fixture:
shstartssleep, execs into Node, Node kills the child afterSIGCHLD, prints its PID, and the test directly verifiespsreportsZ.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main change: preventing a race in the SSH zombie-reaping launch test. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The pull request description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the failure, fix, scope rationale, focused verification results, unteste… Full details: Description check
-
Explanation
The pull request description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the failure, fix, scope rationale, focused verification results, untested macOS coverage, and the agent and harness used.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Claude Opus 5.5 responding on behalf of @tris203
Closing: #22427 fixed the same race, where dash reaps the killed child before
exec. It waits for the parent to exec before killing the child, and no test job that has failed in CI since it merged shows this test failing. What's left here would only swap thosepsloops for the SIGCHLD signal, which isn't worth a separate PR.tris203(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed