Skip to content
Source
Sign inSign up
pingdotgg/t3code

test(ssh): zombie-reap launch test no longer races the shell #20052

Closedtris203(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/20052/headopened View on GitHub

Problem

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, strace of the old shape showed dash reaping the background child with wait4(-1, WNOHANG) after SIGCHLD and before exec. Widening the window between echo and exec with a builtin-only busy loop reproduced the empty ps output 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 of main's exact check passed 100 of 100 times with the natural timing. With the kill forced before exec, it failed 10 of 10 times, exiting 1 with empty output: ps finds no process and the loop exits at once.
  • Still failing on main with the loop. In the first five hours after #15715 merged, this test failed 5 times at the loop's own assert.equal(zombieState.exitCode, 0, zombieState.stdout) (tunnel.test.ts:1472). Four were pushes to main that include #15715 (1, 2, 3, 4) and one was a PR run. Each message is a bare expected 1 to equal +0 with no loop output in front of it. Empty output means ps found no process on its first try: the child had already been reaped. A child still dying would have printed S or R. 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 current main, and a full run of tunnel.test.ts passed 34 of 34. vp lint and vp fmt --check on the file are clean.
  • Not checked. macOS was not run. /bin/sh there 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

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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 that ps reports zombie state before testing replacement.

      Changes: SSH tunnel zombie-process test

      Layer / File(s)Summary
      Zombie-process test setup
      packages/ssh/src/tunnel.test.ts
      The test uses a Node-controlled child process fixture. It prints the child PID after the child is killed and SIGCHLD is 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/ssh

      Architecture 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: sh starts sleep, execs into Node, Node kills the child after SIGCHLD, prints its PID, and the test directly verifies ps reports Z.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preventing a race in the SSH zombie-reaping launch test.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. 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 those ps loops for the SIGCHLD signal, which isn't worth a separate PR.

Sign in to join this conversation.