Skip to content

test(wsl): make the bash relay reap test deterministic - #34329

Merged
nwparker merged 1 commit into
mainfrom
nwparker/wsl-relay-reap-test-deterministic
Oct 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/wsl-relay-reap-test-deterministic

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7
Prod 0 0 0 0

ELI5

A test added in #34260 sometimes failed by chance. It checks that our WSL connection relay cleans up its helper processes. Sometimes the test's fake helpers weren't ready yet when the relay stopped them, so the check came out wrong. Now the test waits until the fakes are ready, and tells them apart reliably, so it passes or fails for real reasons only.

What Changed

Before: orcad-bash-stdio-bridge.test.ts › "waits for the cat it kills before exiting" failed intermittently (for example, shard 5 of run 40471530389 failed in 12 ms). It had two races:

  • the relay could kill a stub cat before that stub had installed its TERM trap;
  • the stub decided whether it was the socket reader or the stdin reader by which one won a mkdir first.

After:

  • Each stub writes a mark once its trap is in place. The test hangs up the socket only after both marks exist (an expect.poll with a 10 s bound).
  • A stub knows it's the socket reader when its stdin is the relay's socket ([ /dev/fd/0 -ef /dev/fd/3 ]). That reader exits with orcad; the stdin reader stays blocked until the relay kills it.

The 0.3 s the killed stub takes to die is not a race. The relay must wait for it, and the test checks the mark exists the moment the relay exits.

Why

The test now waits on the conditions it depends on instead of on timing. Telling the two stubs apart by their file descriptors, rather than by file type, works whether stdin is a pipe or a socket pair: Bun, which runs the tests, hands the child a socket pair.

Linked Issue

Follow-up to #34260 (R40).

Visual Proof

N/A: this changes a test only.

Testing

  • Eight passes in a row locally. With the relay's wait removed, it fails every time (3/3), so it still catches the bug.
  • The same stub and relay in an ubuntu:24.04 container: exit 0, and the killed stub's mark exists at exit.
  • The full bash relay suite passes (14 tests).

Flag-off: this is a test-only change; nothing ships.

  • Automated tests added/updated

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (typecheck, the suite, the changed-code gate and the flaky-test ratchet pass locally; CI runs the rest)

It raced the relay's kill against the stub cats setting their TERM trap, and picked the cat to
keep blocked by start order. It now hangs up only once both traps are in place, and tells the
socket reader from the stdin reader by whether its stdin is the relay's socket (fd 3).
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1f5f45a3-8ace-40eb-b31b-c6dc49c09cf3
Commits

Reviewing files that changed from the base of the PR and between 755bbfa and c28110d.

Files selected for processing: 1
  • src/main/ssh/orcad-bash-stdio-bridge.test.ts

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

Walkthrough

The reaping test now records when each stub cat process installs its TERM trap. It identifies the socket reader by comparing file descriptors 0 and 3. Before closing the socket, the test waits for both trap markers. After the bridge exits, the test checks for the killed marker.

Priority: Low

Merge Risk: Minimal · up to c2811

No actionable merge-blocking risk remains for this test-only change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the test-only change and its purpose: making the WSL bash relay reap test deterministic.
Description check Passed The description is mostly complete. It explains the failure, the deterministic fix, testing results, visual proof, and scope. It references issue #34260, although it does not use the template's exact …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is mostly complete. It explains the failure, the deterministic fix, testing results, visual proof, and scope. It references issue #34260, although it does not use the template's exact "Fixes #" format, and it notes that some checks will run in CI.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 72a4fd1 into main Oct 27, 2026
33 checks passed
nwparker added a commit that referenced this pull request Oct 27, 2026
The fake cat backgrounded the real cat with `&`, which a non-interactive sh starts on
/dev/null (dash even under `<&0`). The socket reader therefore ended at once, before orcad
hung up, and the relay killed its partner, sometimes before that cat's TERM trap was set:
on Linux under load the trap count stayed at 1 even after #34329 (3 of 6 rounds of 50
failed). The fake cat now passes stdin on fd 5, as the relay itself does, so the socket
reader ends only when orcad hangs up and the stdin reader blocks until killed.
nwparker added a commit that referenced this pull request Oct 27, 2026
* test(wsl): hand the reap test's fake cat its real stdin

The fake cat backgrounded the real cat with `&`, which a non-interactive sh starts on
/dev/null (dash even under `<&0`). The socket reader therefore ended at once, before orcad
hung up, and the relay killed its partner, sometimes before that cat's TERM trap was set:
on Linux under load the trap count stayed at 1 even after #34329 (3 of 6 rounds of 50
failed). The fake cat now passes stdin on fd 5, as the relay itself does, so the socket
reader ends only when orcad hangs up and the stdin reader blocks until killed.

* test(wsl): mark the fake cat armed only once its child is known; tighten the comment
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