perf(desktop): run packaged WSL backend from Linux filesystem #5042
ClosedReyJ94(GitHub profile, opens in a new tab)wants to merge 10 commits into
main fromrefs/pull/5042/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 471OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -388,0 +451,21 @@451+ 'rm -rf -- "$staging_dir" "$previous_dir"',452+ "restore_previous() {",453+ ' rm -rf -- "$staging_dir"',454+ ' if [ -d "$previous_dir" ]; then',455+ ' if [ ! -e "$current_dir" ]; then',456+ ' mv -- "$previous_dir" "$current_dir"',457+ " else",458+ ' rm -rf -- "$previous_dir"',459+ " fi",460+ " fi",461+ "}",462+ "trap restore_previous EXIT",463+ "trap 'exit 1' HUP INT TERM",464+ 'mkdir "$staging_dir"',465+ 'cp -a "$source_root/." "$staging_dir/"',466+ 'printf "%s\\n" "$runtime_id" > "$staging_dir/.t3code-runtime-id"',467+ 'if [ ! -f "$staging_dir/apps/server/dist/bin.mjs" ]; then',468+ ' printf "staged WSL server entry is missing\\n" >&2',469+ " exit 4",470+ "fi",471+ 'if [ -e "$current_dir" ]; then mv -- "$current_dir" "$previous_dir"; fi',
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 523OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -400,7 +505,19 @@400505 return {401506 ok: false,402- reason: `wslpath conversion failed for ${windowsRepoRoot}`,507+ reason: `WSL packaged runtime preparation ${action}. Retry, or check that the distro is healthy.`,403508 fatal: false,509+ retryLimit: PACKAGED_RUNTIME_TRANSPORT_RETRY_LIMIT,404510 } as const;405511 }406- const linuxRepoRoot = linuxRepoRootOption.value;512+513+ const linuxRepoRoot = parsePackagedRuntimeRoot(stage.stdout);514+ if (stage.exitCode === 0 && linuxRepoRoot !== null) {515+ return { ok: true, linuxRepoRoot } as const;516+ }517+518+ const outputTail = `${stage.stdout}${stage.stderr}`.trim().slice(-500);519+ return {520+ ok: false,521+ reason: `Failed to prepare the packaged WSL runtime (exit ${stage.exitCode}): ${outputTail || "no output captured"}`,522+ fatal: true,523+ } as const;
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 439Resolvedby ReyJ94(GitHub profile, opens in a new tab)@@ -387,2 +414,20 @@387414388-const ensureNodePtyImpl = (415+export const buildPackagedRuntimeStageScript = (416+ windowsRepoRoot: string,417+ runtimeId: string,418+): string => {419+ const normalizedWindowsRepoRoot = windowsRepoRoot.replaceAll("\\", "/");420+ const cacheHitScript = [421+ 'if [ "$(cat "$manifest_path" 2>/dev/null || true)" = "$runtime_id" ] && [ -f "$entry_path" ]; then',422+ ` printf 'runtimeRoot:%s\\n' "$current_dir"`,423+ " exit 0",424+ "fi",425+ ];426+ return [427+ "set -eu",428+ `runtime_id=${shellQuote(runtimeId)}`,429+ `windows_repo_root=${shellQuote(normalizedWindowsRepoRoot)}`,430+ 'case "${XDG_CACHE_HOME:-}" in',431+ ' /*) cache_home="$XDG_CACHE_HOME" ;;',432+ ' *) cache_home="${HOME:?WSL home directory is unavailable}/.cache" ;;',433+ "esac",
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 436OutdatedResolvedby ReyJ94(GitHub profile, opens in a new tab)@@ -388,0 +416,21 @@416+ windowsRepoRoot: string,417+ runtimeId: string,418+): string => {419+ const normalizedWindowsRepoRoot = windowsRepoRoot.replaceAll("\\", "/");420+ const cacheHitScript = [421+ 'if [ "$(cat "$manifest_path" 2>/dev/null || true)" = "$runtime_id" ] && [ -f "$entry_path" ]; then',422+ ` printf 'runtimeRoot:%s\\n' "$current_dir"`,423+ " exit 0",424+ "fi",425+ ];426+ return [427+ "set -eu",428+ `runtime_id=${shellQuote(runtimeId)}`,429+ `windows_repo_root=${shellQuote(normalizedWindowsRepoRoot)}`,430+ 'case "${XDG_CACHE_HOME:-}" in',431+ " /*)",432+ ' cache_home="$XDG_CACHE_HOME"',433+ ' mkdir -p "$cache_home"',434+ ' cache_filesystem=$(findmnt -T "$cache_home" -n -o FSTYPE 2>/dev/null || true)',435+ ' case "$cache_filesystem" in',436+ ' 9p|drvfs|"") cache_home="${HOME:?WSL home directory is unavailable}/.cache" ;;',
- scripts/build-desktop-artifact.ts line 1788Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1718,0 +1755,21 @@1755+ WSL_RUNTIME_ARCHIVE_FILENAME,1756+ );1757+ yield* fs.makeDirectory(path.dirname(archivePath), { recursive: true });1758+ yield* runCommand(ChildProcess.make("tar", buildWslRuntimeArchiveArgs(), { cwd: stageAppDir }), {1759+ label: "tar WSL runtime",1760+ verbose: false,1761+ });1762+1763+ const hash = NodeCrypto.createHash("sha256");1764+ yield* fs1765+ .stream(archivePath)1766+ .pipe(Stream.runForEach((chunk) => Effect.sync(() => hash.update(chunk))));1767+ const digest = hash.digest("hex");1768+ const hashPath = path.join(1769+ stageAppDir,1770+ WSL_RUNTIME_ARCHIVE_STAGE_DIRECTORY,1771+ WSL_RUNTIME_ARCHIVE_HASH_FILENAME,1772+ );1773+ yield* fs.writeFileString(hashPath, `${digest}\n`);1774+ yield* Effect.log(`[desktop-artifact] Staged compressed WSL runtime (${digest}).`);1775+});
ReyJ94(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


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:
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