Skip to content

fix(desktop): prevent WSL backend exiting with code 0 by keeping stdi…#3613

Open
jibin7jose wants to merge 13 commits into
pingdotgg:mainfrom
jibin7jose:fix-wsl-code-0-exit
Open

fix(desktop): prevent WSL backend exiting with code 0 by keeping stdi…#3613
jibin7jose wants to merge 13 commits into
pingdotgg:mainfrom
jibin7jose:fix-wsl-code-0-exit

Conversation

@jibin7jose

@jibin7jose jibin7jose commented Jun 30, 2026

Copy link
Copy Markdown

…n open

Fixes #3611 by appending Stream.never to the bootstrap stream so the Windows-side pipe does not close before the backend process completes reading it.

What Changed

Why

UI Changes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Touches desktop backend spawn/restart lifecycle and WSL preflight gating; changes are scoped but affect when the app falls back from WSL and how bootstrap is read over stdin.

Overview
Fixes WSL backends exiting with code 0 right after bootstrap by appending Stream.never to the stdin bootstrap stream so the Windows-side pipe stays open until the child finishes reading the envelope (stdin-delivery only; fd3 Windows-native unchanged).

Adds a neverReadyAttempt counter for stdin-delivery backends that tracks consecutive exits before HTTP readiness. After MAX_PREFLIGHT_FAILURE_ATTEMPTS, the manager calls onPreflightFailed and stops or restarts based on its result instead of looping forever; successful readiness resets the counter.

WSL preflight now prints nodeVersion: from the node-pty probe and parseNodeVersion validates it against nodeEngineRange, failing fast with a fatal, actionable error when Node is missing or incompatible.

Server readBootstrapEnvelope registers the error listener on the readline interface (not the raw stream) and runs cleanup on error, line, and close so early stream errors are handled consistently.

Reviewed by Cursor Bugbot for commit 0b8f928. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix WSL backend exiting prematurely by keeping stdin open for stdin-delivery backends

  • For stdin-delivery backends (e.g. WSL), stdin is now kept open after writing the bootstrap JSON by appending Stream.never, preventing the child process from exiting with code 0 immediately after receiving its envelope.
  • Consecutive exits before HTTP readiness are now tracked via a neverReadyAttempt counter; after MAX_PREFLIGHT_FAILURE_ATTEMPTS, onPreflightFailed is invoked and the manager stops or restarts based on its result rather than restarting indefinitely.
  • The WSL node-pty probe script now emits the detected Node.js version on a nodeVersion: line; ensureNodePtyImpl validates this against a supplied semver range and returns { ok: false, fatal: true } when the version is missing or out of range.
  • Error handling in readBootstrapEnvelope is fixed to register the error listener on the readline interface rather than the raw stream, ensuring cleanup runs on all error paths.

Macroscope summarized 0b8f928.

…n open

Fixes pingdotgg#3611 by appending Stream.never to the bootstrap stream so the Windows-side pipe does not close before the backend process completes reading it.
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eab09290-c4e9-465f-9f0f-2d14deb84332

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Jun 30, 2026
Comment thread apps/desktop/src/backend/DesktopBackendManager.ts
@macroscopeapp

macroscopeapp Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces new runtime behavior for WSL backend lifecycle: stdin stream handling changes, new failure tracking with fallback logic after consecutive never-ready exits, and Node.js version validation. These are meaningful behavioral changes to backend management that warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Tests using fd3 delivery were hanging because the stream never terminated. Only stdin delivery (WSL) needs the stream kept open.
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jun 30, 2026
…gg#3611)

Consolidates fixes from PRs pingdotgg#3613, pingdotgg#3621, and pingdotgg#3623 to address both root causes and add a fail-safe:

1. DesktopWslEnvironment: Parse the Node version in the WSL node-pty probe and validate it against options.nodeEngineRange. Preflight now fails cleanly with an actionable error if the distro's default Node is incompatible.

2. DesktopBackendManager: Track neverReadyAttempt to cap consecutive post-spawn exits on stdin delivery. Prevents the desktop from permanently getting stuck restarting if the WSL backend consistently fails before readiness.

3. bootstrap: Clean up the readline interface on all event paths to prevent leaks when stdin stays open, and register the error listener on the readline interface to safely catch early stream errors.
@jibin7jose jibin7jose force-pushed the fix-wsl-code-0-exit branch from 340fb76 to 215bd10 Compare July 2, 2026 12:52
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Jul 2, 2026
@macroscopeapp macroscopeapp Bot dismissed their stale review July 2, 2026 12:52

Dismissing prior approval to re-evaluate 215bd10

Comment thread apps/desktop/src/backend/DesktopBackendManager.ts
Comment thread apps/desktop/src/backend/DesktopBackendManager.ts
Comment thread apps/desktop/src/backend/DesktopBackendManager.ts
@jibin7jose

Copy link
Copy Markdown
Author

@juliusmarminge Could you please approve the workflows for this PR so the checks can run? Thank you!

Comment thread apps/desktop/src/backend/DesktopBackendManager.ts Outdated
Comment thread apps/desktop/src/backend/DesktopBackendManager.ts Outdated
Comment thread .github/CODEOWNERS Outdated
Comment thread .github/CODEOWNERS Outdated
@jibin7jose

Copy link
Copy Markdown
Author

Hi @juliusmarminge! When you have time, could you please take a look at this PR? It addresses issue #3611 by fixing the WSL backend exiting early when using stdin bootstrap delivery. I’ve incorporated the follow-up fixes and kept the PR up to date with main. If you have any feedback or would like any changes, I’d be happy to update the PR. Thank you!

@jibin7jose

Copy link
Copy Markdown
Author

Hi @juliusmarminge, @t3dotgg, and @codex! When you have a chance, could you please take a look at this PR? It fixes the WSL backend exiting early when using stdin bootstrap delivery, includes the follow-up fixes from earlier feedback, and has been kept up to date with main. Once the workflows are approved and the checks complete, I'd really appreciate your review. Thank you!

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Windows desktop 0.0.28 gets stuck on connecting to WSL after enabling WSL support

1 participant