Skip to content

fix(desktop): prevent WSL startup timeout on Windows - #6321

Open
chrismin13 wants to merge 3 commits into
pingdotgg:mainfrom
chrismin13:perf/wsl-packaged-startup
Open

fix(desktop): prevent WSL startup timeout on Windows#6321
chrismin13 wants to merge 3 commits into
pingdotgg:mainfrom
chrismin13:perf/wsl-packaged-startup

Conversation

@chrismin13

@chrismin13 chrismin13 commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #4535.

Related to #5522 and #5876. This PR reduces slow module loading, but it does not change readiness retry behavior or reduce the number of files unpacked by the installer.

What Changed

Fixes the packaged Windows app failing to launch when using the WSL backend.

The server runs inside WSL, but its files are installed on the Windows filesystem. WSL accesses those files through a mount such as /mnt/c, which is much slower than the Linux filesystem.

Before this change, the server loaded a large number of JavaScript files from node_modules through that mount. Startup could take longer than the desktop app’s 60-second readiness timeout. The desktop app then treated the WSL backend as failed, leaving the app stuck or unable to open.

This change bundles normal JavaScript dependencies into the server output. WSL now loads a few bundle files instead of resolving a large dependency tree through the Windows filesystem.

Packages that need native binaries or other files at runtime remain external.

Startup timing was also added to the logs. If startup becomes slow again, the logs will show whether the delay happened while starting the process, running database migrations, opening the HTTP server, or waiting for readiness.

Why

Without this change, the packaged app could be unusable with the WSL backend because the backend did not become ready before the timeout.

Increasing the timeout would only hide the problem and make failures take longer. Reducing filesystem work makes startup faster and more reliable.

Testing

  • Built the desktop app on Windows.
  • Launched the server through wsl.exe.
  • Confirmed the WSL backend became ready and the main window opened.
  • Confirmed there were no missing-package or WSL packaging errors.
  • vp test run apps/server/vite.config.test.ts
  • vp check
  • vp run typecheck

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes

Note

Medium Risk
Changes server packaging/bundling behavior for the packaged desktop CLI, which can break WSL or native-dep loading if the external allowlist is wrong. Timing logs are low risk.

Overview
Fixes packaged Windows + WSL backend startups timing out by bundling normal JS runtime deps into the server CLI, so WSL loads a few chunks instead of walking a large node_modules tree through the slow Windows filesystem mount.

shouldBundleCliDependency now bundles declared runtime dependencies by default, while keeping native/asset-owning packages external (node-pty, Bun-only packages, Claude agent SDK, etc.). Adds coverage for that bundling policy.

Also adds startup timing logs so slow boots are easier to diagnose: spawn/readiness elapsedMs in the desktop backend manager, plus processUptimeMs on migration completion and HTTP listen.

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

Note

Fix WSL startup timeout by improving CLI bundling and adding startup timing logs

  • Reworks shouldBundleCliDependency in vite.config.ts to bundle all declared runtime dependencies by default, while keeping native/runtime-sensitive packages (e.g. node-pty, @effect/sql-sqlite-bun) external via a new externalRuntimePackageNames set.
  • Adds structured startup timing logs across the backend and server: HTTP server listen address and processUptimeMs in server.ts, backend process spawn/readiness events with elapsedMs in DesktopBackendManager.ts, and migration timing in Migrations.ts.
  • Adds tests for shouldBundleCliDependency in vite.config.test.ts.
  • Behavioral Change: CLI build now bundles all direct runtime dependencies and their subpaths unless explicitly listed in externalRuntimePackageNames; previously only packages matching bundledPackagePrefixes were bundled.

Macroscope summarized d3e17f4.

Summary by CodeRabbit

  • Enhancements

    • Improved server and desktop backend startup logging with process details, readiness status, and elapsed times.
    • Improved migration completion logs with process uptime.
    • Updated server packaging to bundle runtime dependencies while preserving support for native and asset-based packages.
  • Tests

    • Added coverage for dependency bundling and externalization scenarios.

Copilot AI lite review requested due to automatic review settings August 12, 2026 13:24
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates CLI runtime dependency bundling and related WSL packaging documentation. It also adds elapsed-time and process details to desktop backend, migration, and HTTP server startup logs.

Changes

Runtime packaging

Layer / File(s) Summary
Runtime dependency bundling
apps/server/vite.config.ts, apps/server/vite.config.test.ts, apps/desktop/src/backend/DesktopBackendConfiguration.ts, apps/desktop/src/wsl/DesktopWslEnvironment.ts
CLI dependencies are bundled by default, while asset-owning, Bun-specific, and native-binary packages remain external. Tests cover direct, workspace, runtime-file, and unknown packages. WSL and packaged-build comments describe the dependency layout and environment isolation.

Startup observability

Layer / File(s) Summary
Desktop backend lifecycle logging
apps/desktop/src/backend/DesktopBackendManager.ts
Backend spawn and readiness logs now include process details, PID, URL, and elapsed milliseconds. Readiness handling captures the active process PID before logging and invoking onReady.
Server and migration timing logs
apps/server/src/persistence/Migrations.ts, apps/server/src/server.ts
Migration and HTTP listening logs now include rounded process uptime. HTTP startup logs include the bound address and available TCP port.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: juliusmarminge

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing WSL backend startup timeouts on Windows.
Description check ✅ Passed The description includes the required change, rationale, UI status, checklist, and detailed testing information.
✨ 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 the vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Aug 12, 2026
@github-actions github-actions Bot added the size:L 100-499 changed lines (additions + deletions). label Aug 12, 2026
Comment thread apps/desktop/src/backend/DesktopBackendManager.ts Outdated

Copilot AI 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.

Pull request overview

Fixes Windows packaged desktop app startup timeouts when using the WSL backend by reducing slow /mnt/c-mounted filesystem dependency resolution during server bootstrap, and by adding more granular startup timing logs to make future regressions diagnosable.

Changes:

  • Update server CLI bundling policy to bundle direct runtime JS dependencies by default, while keeping native/asset-owning/runtime-specific packages external.
  • Add unit coverage for the new bundling policy in apps/server/vite.config.test.ts.
  • Add startup timing logs for backend spawn/readiness (desktop) and for HTTP listen + migrations (server).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apps/server/vite.config.ts Changes CLI bundling policy: bundle direct runtime deps by default, with an explicit external allowlist.
apps/server/vite.config.test.ts Adds focused tests validating bundling vs externalization behavior.
apps/server/src/server.ts Logs HTTP listen timing details (incl. process uptime) during startup.
apps/server/src/persistence/Migrations.ts Annotates migration logs with process uptime timing.
apps/desktop/src/wsl/DesktopWslEnvironment.ts Updates probe comments to reflect the new “mostly bundled” server dependency model.
apps/desktop/src/backend/DesktopBackendManager.ts Adds elapsed-time logging for backend spawn, readiness success, and readiness failure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@macroscopeapp

macroscopeapp Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

1 blocking correctness issue found. The PR inverts the bundling defaults in vite.config.ts, changing from explicit inclusion to default bundling with exceptions. This build configuration change could affect runtime behavior if native or asset-resolving packages are incorrectly bundled, warranting human verification that the exclusion list is complete.

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

@chrismin13

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/server/vite.config.test.ts (1)

17-21: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover every explicit external package.

apps/server/vite.config.ts Lines 21-32 define five external packages, but this test covers only node-pty and @anthropic-ai/claude-agent-sdk. Add assertions for @effect/platform-bun, @effect/sql-sqlite-bun, and @ff-labs/fff-node. These packages are Bun-only or native and can break packaged WSL startup if bundling changes.

As per coding guidelines, backend behavior changes in apps/server/**/*.test.{ts,tsx} must include focused tests for that behavior.

Add the missing assertions
   it("keeps packages that need runtime files external", () => {
     assert.isFalse(shouldBundleCliDependency("node-pty"));
     assert.isFalse(shouldBundleCliDependency("`@anthropic-ai/claude-agent-sdk/cli.js`"));
     assert.isFalse(shouldBundleCliDependency("node-pty/lib/index.js"));
+    assert.isFalse(shouldBundleCliDependency("`@effect/platform-bun`"));
+    assert.isFalse(shouldBundleCliDependency("`@effect/sql-sqlite-bun`"));
+    assert.isFalse(shouldBundleCliDependency("`@ff-labs/fff-node`"));
   });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server/vite.config.test.ts` around lines 17 - 21, Add focused assertions
in the “keeps packages that need runtime files external” test to verify
shouldBundleCliDependency returns false for `@effect/platform-bun`,
`@effect/sql-sqlite-bun`, and `@ff-labs/fff-node`, covering every package explicitly
configured as external in vite.config.ts.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/server/vite.config.test.ts`:
- Around line 17-21: Add focused assertions in the “keeps packages that need
runtime files external” test to verify shouldBundleCliDependency returns false
for `@effect/platform-bun`, `@effect/sql-sqlite-bun`, and `@ff-labs/fff-node`,
covering every package explicitly configured as external in vite.config.ts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3455d711-a738-4c63-b0bf-40dcad224909

📥 Commits

Reviewing files that changed from the base of the PR and between e321667 and bc7f7f1.

📒 Files selected for processing (7)
  • apps/desktop/src/backend/DesktopBackendConfiguration.ts
  • apps/desktop/src/backend/DesktopBackendManager.ts
  • apps/desktop/src/wsl/DesktopWslEnvironment.ts
  • apps/server/src/persistence/Migrations.ts
  • apps/server/src/server.ts
  • apps/server/vite.config.test.ts
  • apps/server/vite.config.ts

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

2 participants