perf(desktop): run packaged WSL backend from Linux filesystem
What Changed
Packaged Windows builds now materialize the WSL server runtime into a distro-native cache under ${XDG_CACHE_HOME:-$HOME/.cache}/t3code/desktop-wsl-runtime/current and launch it from there. Windows-mounted XDG cache paths fall back to $HOME/.cache.
A matching version/architecture cache returns before wslpath or the mounted source is touched. Cache misses copy into a staging directory, validate the server entry, atomically promote it, and retain only the current runtime. Development checkouts continue to run in place.
The global backend readiness timeout and provider auth timeout are unchanged. The first launch of a packaged version still pays the one-time copy cost; normal launches use the Linux-native cache.
Why
The packaged desktop currently starts the WSL backend from app.asar.unpacked under /mnt/c. Because the server externalizes its dependencies, startup performs tens of thousands of module reads across the Windows/WSL filesystem bridge; #4535 reports 73–81 second boots against the 60-second readiness window.
This fixes the underlying filesystem placement rather than extending the readiness deadline.
Fixes #4535.
Verification
vp test run apps/desktop/src/wsl/DesktopWslEnvironment.test.ts apps/desktop/src/backend/DesktopBackendConfiguration.test.ts(53 passed)pnpm --filter @t3tools/desktop typecheck- targeted
vp lint --deny-warnings - targeted
vp fmt --check - shell-level proofs that a warm cache succeeds with
wslpathdisabled, two concurrent cold-cache preflights perform exactly one copy, and WSL Windows-share cache types (9p/DrvFS/Plan 9/virtiofs) fall back to ext4 while a native XDG cache remains selected
Checklist
- [x] This PR is small and focused
- [x] I explained what changed and why
- [x] Before/after screenshots are not applicable; there are no UI changes
- [x] Video is not applicable; there are no animation or interaction changes
Generated with GPT-5.6 Sol using Codex in T3 Code.
[!NOTE] Medium Risk Changes WSL backend launch paths and first-launch staging (copy, flock, cache); failures are mostly classified with retries, but a bad staging or cache state could still block packaged WSL startup until retry or manual cache clear.
Overview Packaged Windows builds no longer launch the WSL server from
app.asar.unpackedon/mnt/c. WSL preflight now callspreparePackagedRuntimeto stage resources into a distro-native cache (~/.cache/t3code/desktop-wsl-runtime/current, with XDG paths on Windows mounts falling back to$HOME/.cache), then runsnode-ptychecks and the server entry from that Linux root. Warm caches keyed by version/arch skipwslpathand reads from the Windows mount; cold misses copy underflock, validate the entry, and promote atomically.Dev checkouts still run in place: preflight converts the repo root with
windowsToWslPathand buildslinuxEntryPathas{root}/apps/server/dist/bin.mjs.ensureNodePtynow takes a LinuxlinuxRepoRootfrom the caller instead of converting Windows paths internally.The staging bash script and
formatPackagedRuntimeStageFailureclassifywslpathfailures (exit 5) as retryable during WSL startup. Tests cover packaged preflight wiring and script ordering (cache-before-mount, mount fallback, lock + double cache check).Reviewed by Cursor Bugbot for commit 2fc6ba15f50b46ef7aa7ed2342d341b74834cbf4. Bugbot is set up for automated code reviews on this repo. Configure here.
[!NOTE]
Run packaged WSL backend from the Linux filesystem instead of Windows-mounted paths
- For packaged builds,
preparePackagedRuntimestages app resources onto the distro's native Linux filesystem (under~/.cache) before launch, avoiding slow Windows-mounted filesystem reads at runtime.- For dev builds, the repo root is now converted via
windowsToWslPath(instead of the entry file path), andlinuxEntryPathis derived by appending the relative server path to that root.ensureNodePtyImplnow accepts a Linux-nativelinuxRepoRootprovided by the caller rather than converting a Windows path internally.- The staging script uses
flockfor safe concurrent cache writes, checks for a cached runtime before any conversion, and defines specific exit codes (e.g.wslpathfailure = 5) for retry classification.- Behavioral Change: packaged WSL launches now run the server from a Linux-native path;
ensureNodePtycallers must supply a Linux root rather than a Windows path.Macroscope summarized 2fc6ba1.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
11095731-efa5-4f27-a9e0-38ac08e3c0a4You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
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.
Comment @coderabbitai help to get the list of available commands.
Approvability
Verdict: Needs human review
This PR adds a new WSL runtime staging system that extracts the backend to Linux's native filesystem on first launch for performance. The changes introduce significant new shell scripting, content-addressed caching, archive extraction, and lock-based synchronization - a substantial new capability warranting human review.
You can customize Macroscope's approvability policy. Learn more.
I found a correctness race in the mutable current cache at 3aaab8e.
The flock correctly serializes extraction/promotion, but every archive still returns the same path:
/home/t3review/.cache/t3code/desktop-wsl-runtime/current
I reproduced this on Ubuntu/WSL with the PR's actual generated buildPackagedRuntimeStageScript and two valid minimal runtime archives (different SHA-256 hashes, each containing the required server entry and Effect package):
A completed: 833.569 ms -> runtimeRoot:.../current
B completed: 871.645 ms -> runtimeRoot:.../current
final current entry: version B
cache version directories: current
The sequential form is deterministic too: after A stages and returns .../current, staging B makes A's previously returned path read B's code immediately. Because the lock is released before the caller launches Node, a second version can replace current in that gap, causing the first caller to launch the second version's runtime. If the first backend is already running, promotion renames and immediately deletes its old tree, which can also break later/lazy module loads.
The desktop single-instance lock reduces how often this can happen, but it doesn't make the staging helper's cross-process/version contract safe for relaunch/update or side-by-side builds.
Could you make the returned runtime root content-addressed by version/arch/archive hash (and prune old roots separately) rather than returning a mutable current alias? That keeps each caller pinned to the archive it validated and extracted.
Sol here — I reproduced the mutable-current race and addressed it in 29f1958e.
The prepared runtime root is now content-addressed as sha256-<archive hash>. A launch for archive B no longer replaces or deletes the root previously returned to a still-running launch for archive A. Extraction happens in a unique staging directory; promotion only replaces an incomplete/corrupt directory for that exact hash. Concurrent callers for the same hash still serialize and extract once, while distinct archives can stage concurrently into distinct immutable roots.
I deliberately did not add eager "current + previous" pruning here. This staging boundary has no lease/liveness information for already-running backends, so pruning another hash could recreate the same lazy-load failure under a different policy. Cleanup should be a separate lease-aware or age-based owner rather than part of promotion.
I added deterministic sequential and concurrent distinct-archive regressions, and retained the same-hash concurrency coverage. The focused affected suites pass: 98/98, with targeted format/lint plus desktop and scripts typechecks also passing.
The related Windows packaging footgun raised on #5769 is separately fixed in 0411cf9f: a Windows artifact now fails when its Linux node-pty prebuild is missing instead of shipping a WSL backend that restart-loops.
— GPT-5.6 Sol (coding agent, posting through @ReyJ94's account)
Closing this as superseded by #6169 and the bundled server topology now on main.
I benchmarked the current materialized server payload in WSL (1,223 files) from both ext4 and /mnt/c. Fresh backend readiness was 5.85–7.49s on ext4 versus 6.23–6.50s on DrvFS; repeated --version startup was 1.31–1.63s versus 2.08–2.48s. The former 60–98s small-file penalty is gone, so this PR's extra runtime archive, hashing, extraction, locking, fallback, and cache lifecycle no longer earn their complexity.
The cache-race and missing-prebuild findings on this branch were real, but after #6169 this architecture is no longer the right direction.
— GPT-5.6 Sol (coding agent, posting through @ReyJ94's account)