Skip to content

fix(wsl): reap the bash stdio relay's cats before it exits - #34260

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-bash-relay-reap
Oct 27, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-bash-relay-reap

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

ELI5

Orca talks to its server inside a WSL distro through a small relay script. When a connection closed, the relay stopped one of its two helper processes and exited without collecting it. Inside WSL nothing else collects such leftovers, so a "dead but not gone" process stayed behind, and WSL counted the distro as still in use. The distro never shut down even when Orca had nothing running there.

What Changed

Before: the bash relay (#33820) ended with wait -n; kill $r $w; exit 0. One cat was killed and left unreaped. On WSL that zombie stays under the session's /init forever. The session never ends, so the distro, and the WSL virtual machine with its memory, stay up.

After: wait -n; kill $r $w 2>/dev/null; wait; exit 0. The relay waits for both cats before exiting, so nothing is left behind.

How it was found: the real-WSL lane's new idle-release phase in #33084 timed out on every distro, so I added diagnostics.

  • At the timeout, no Orca, holder or node process was left. The only thing remaining was an orphaned /init holding one [cat] <defunct>.
  • The zombie's start time matched the first bridge dial in a timed log of every guest command.
  • The one run where the race went the other way passed: the distro stopped 39 s after the last client, and the VM process dropped from 1.22 GB to gone.

Flag-off: the bash relay runs only for WSL hosts. Its only caller is the WSL branch of resolveOrcadStdioBridge (src/main/ssh/orcad-stdio-bridge.ts:38), and WSL hosts run only with ORCA_INTERNAL_WSL_HOSTS set. With the flag off it never runs, so users see no change.

Why

Reaping in the relay is the root fix. The alternatives treat symptoms:

  • killing WSL's session init would be invasive;
  • going back to the Node bridge gives up the ~45 MB saving per connection;
  • detaching the cats would still leave them for an init that never reaps.

Linked Issue

Internal WSL-via-orcad tracker R40 / E17 (blocks #33084).

Visual Proof

N/A: there's no UI change. This is a process-lifecycle fix inside the WSL distro.

Testing

  • New behavioural test in orcad-bash-stdio-bridge.test.ts. A cat on PATH that takes 0.3 s to die after TERM leaves a mark when it does. orcad hangs up, and the relay must not exit before that mark exists. The test fails without the wait and passes with it.

  • The existing bash relay suite passes (byte-exact transfer, back-pressure both ways, teardown with no survivors).

  • The host-op byte budget and bridge resolution tests pass.

  • The zombie itself only appears under WSL's session init. The end-to-end proof is feat(wsl): let an idle WSL distro stop once its server idle-exits #33084's real-WSL idle-release phase, which carries this commit.

  • Automated tests added/updated

Notes

SSH hosts are unaffected: SSH Linux hosts use the Node bridge (orcadPosixStdioBridgeCommand), not this relay.

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 touched tests and the changed-code gate pass locally; CI runs the rest)

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

After wait -n returns, the Bash relay kills both cat processes and waits for them to be reaped before it exits. A test uses a cat wrapper with a delayed TERM handler and checks the bridge exit code and termination marker.

Priority: Normal

Merge Risk: Low · up to f379d

The cleanup appears sound, but its regression test should verify that the helper finishes before the relay exits. This is not a merge blocker.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reaping the Bash stdio relay's cat processes before exit.
Description check Passed The description is mostly complete. It includes the required explanation, change details, rationale, testing, visual-proof status, scope notes, and checklist. It identifies the related WSL tracker and…
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 includes the required explanation, change details, rationale, testing, visual-proof status, scope notes, and checklist. It identifies the related WSL tracker and #33084, although it does not provide an explicit Fixes issue link. Some full validation commands remain for CI.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. 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 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

The relay killed the surviving cat and exited at once. WSL's per-session init never reaps
orphans, so that cat stayed a zombie, its session never ended, and the distro never stopped
even with nothing of Orca's left in it (seen on every real-WSL idle-release run). Wait for both
cats after the kill.
@nwparker
nwparker force-pushed the nwparker/wsl-bash-relay-reap branch from 6db9f8e to f379d3f Compare October 27, 2026 05:02

@coderabbitai coderabbitai 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.

Nitpick comments: 1
src/main/ssh/orcad-bash-stdio-bridge.test.ts: 1

292-295: Trivial · Stability & Availability · Quick win

Assert marker creation before relay exit.

The test awaits exited before checking killed-cat. If the final relay wait is removed, the relay can exit before the delayed TERM trap creates the marker, and the later assertion can still pass. Hold the helper after creating the marker, assert that the relay is still running, then release it. Release the helper and terminate any unfinished child from finally so assertion failures do not leave the fixture running.


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: 6d242536-cb05-4944-9063-8a72a6996cc9
Commits

Reviewing files that changed from the base of the PR and between 2e1d149 and f379d3f.

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; 2 remain after this review.

@nwparker
nwparker merged commit fa4d2e9 into main Oct 27, 2026
104 of 108 checks passed
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