Repository navigation
fix(relay): scope shell history for Windows -> WSL panes (STA-4682) - #15236
Conversation
`injectRelayHistoryEnv` matched only bash*/zsh*, so a relay pane launched through `wsl.exe` got no HISTFILE at all and every WSL worktree shared one global history. The history file stays on the relay host under the existing flat root, so `deleteRelayHistory` remains the deletion counterpart unchanged; only the exported path is translated to drvfs for the guest, and WSLENV carries it across the boundary. Guest fish stays out of scope on purpose: its history file lives inside the distro, where the relay has no deletion path.
📝 WalkthroughWalkthroughThe relay now shares Merge Risk: ⚪ Minimal · up to The change is merge-ready after normal checks; no actionable merge-blocking risk remains. The only follow-up is non-functional comment cleanup. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/wsl-paths.ts (1)
23-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the new implementation comments.
Keep only the non-obvious rationale. Prefer one concise line per site.
src/shared/wsl-paths.ts#L23-L31: reduce the path-conversion explanation to the WSL-specific reason.src/relay/terminal-history.ts#L88-L95: reduce the host-file andORCA_HISTFILEexplanation to the cleanup and guest-path contract.As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d4427171-d744-4060-88b5-96cf0af55063
📒 Files selected for processing (8)
src/main/wsl.tssrc/relay/pty-handler-spawn-environment.test.tssrc/relay/pty-handler.tssrc/relay/pty-shell-launch.test.tssrc/relay/pty-shell-launch.tssrc/relay/terminal-history-wsl.test.tssrc/relay/terminal-history.tssrc/shared/wsl-paths.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.
…king to probe zsh emulation (STA-4682) Two residuals left behind by #15236 and #15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one #15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost.
…king to probe zsh emulation (STA-4682) Two residuals left behind by #15236 and #15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one #15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost.
…king to probe zsh emulation (STA-4682) (#15361) * fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) Two residuals left behind by #15236 and #15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one #15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost. * fix(shell): harden the revive override path and silence the option probe on an exotic zsh Readiness-review follow-ups on this branch. - `[[ -o <name> ]]` prints "no such option" to stderr and returns false rather than aborting, so a zsh lacking one of the three Bourne option names would put that text in the user's pane. All three predate every supported zsh, so `2>/dev/null` is belt and braces -- but the belt costs nothing. - Bound the WSL distro name revive replays into `wsl.exe -d <name>`. It is the one field this branch newly routes from untrusted serialized state into argv, and reviveEntry's stated job is to re-apply fresh-spawn bounds. - Skip a pane whose overridden shell can no longer spawn instead of letting the throw escape the revive loop and cost every later entry its state. Skipping, not falling back to the host default shell: substituting a different shell is the defect the override exists to fix, and the args and history env are built for the shell that is gone. The worktree-removal fence throws before this, outside reviveEntry, so it stays a hard failure.
…tablyai#15236) `injectRelayHistoryEnv` matched only bash*/zsh*, so a relay pane launched through `wsl.exe` got no HISTFILE at all and every WSL worktree shared one global history. The history file stays on the relay host under the existing flat root, so `deleteRelayHistory` remains the deletion counterpart unchanged; only the exported path is translated to drvfs for the guest, and WSLENV carries it across the boundary. Guest fish stays out of scope on purpose: its history file lives inside the distro, where the relay has no deletion path.
…king to probe zsh emulation (STA-4682) (stablyai#15361) * fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) Two residuals left behind by stablyai#15236 and stablyai#15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one stablyai#15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost. * fix(shell): harden the revive override path and silence the option probe on an exotic zsh Readiness-review follow-ups on this branch. - `[[ -o <name> ]]` prints "no such option" to stderr and returns false rather than aborting, so a zsh lacking one of the three Bourne option names would put that text in the user's pane. All three predate every supported zsh, so `2>/dev/null` is belt and braces -- but the belt costs nothing. - Bound the WSL distro name revive replays into `wsl.exe -d <name>`. It is the one field this branch newly routes from untrusted serialized state into argv, and reviveEntry's stated job is to re-apply fresh-spawn bounds. - Skip a pane whose overridden shell can no longer spawn instead of letting the throw escape the revive loop and cost every later entry its state. Skipping, not falling back to the host default shell: substituting a different shell is the defect the override exists to fix, and the args and history env are built for the shell that is gone. The worktree-removal fence throws before this, outside reviveEntry, so it stays a hard failure.
…tablyai#15236) `injectRelayHistoryEnv` matched only bash*/zsh*, so a relay pane launched through `wsl.exe` got no HISTFILE at all and every WSL worktree shared one global history. The history file stays on the relay host under the existing flat root, so `deleteRelayHistory` remains the deletion counterpart unchanged; only the exported path is translated to drvfs for the guest, and WSLENV carries it across the boundary. Guest fish stays out of scope on purpose: its history file lives inside the distro, where the relay has no deletion path.
…king to probe zsh emulation (STA-4682) (stablyai#15361) * fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) Two residuals left behind by stablyai#15236 and stablyai#15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one stablyai#15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost. * fix(shell): harden the revive override path and silence the option probe on an exotic zsh Readiness-review follow-ups on this branch. - `[[ -o <name> ]]` prints "no such option" to stderr and returns false rather than aborting, so a zsh lacking one of the three Bourne option names would put that text in the user's pane. All three predate every supported zsh, so `2>/dev/null` is belt and braces -- but the belt costs nothing. - Bound the WSL distro name revive replays into `wsl.exe -d <name>`. It is the one field this branch newly routes from untrusted serialized state into argv, and reviveEntry's stated job is to re-apply fresh-spawn bounds. - Skip a pane whose overridden shell can no longer spawn instead of letting the throw escape the revive loop and cost every later entry its state. Skipping, not falling back to the host default shell: substituting a different shell is the defect the override exists to fix, and the args and history env are built for the shell that is gone. The worktree-removal fence throws before this, outside reviveEntry, so it stays a hard failure.
…tablyai#15236) `injectRelayHistoryEnv` matched only bash*/zsh*, so a relay pane launched through `wsl.exe` got no HISTFILE at all and every WSL worktree shared one global history. The history file stays on the relay host under the existing flat root, so `deleteRelayHistory` remains the deletion counterpart unchanged; only the exported path is translated to drvfs for the guest, and WSLENV carries it across the boundary. Guest fish stays out of scope on purpose: its history file lives inside the distro, where the relay has no deletion path.
…king to probe zsh emulation (STA-4682) (stablyai#15361) * fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) Two residuals left behind by stablyai#15236 and stablyai#15258. Relay revive called resolveDefaultShell() and ignored the entry's shell override, so a restarted relay handed the user a PowerShell pane where a WSL one had been -- and with it the host default shell's history rather than the worktree-scoped one stablyai#15236 injects on spawn. The override and the requested distro are now serialized (optional fields; state from an older relay still revives the default shell) and re-resolved through the same allowlist a fresh spawn uses, so revive re-launches the same shell with the same guest-visible HISTFILE and the same WSLENV carrier. A bad override degrades that one pane instead of failing the whole batch. The wrapper's three `$(emulate)` probes each fork a zsh carrying everything the user's config has loaded, and since wrapping widened to every zsh pane every pane pays for them. Each probe now sits behind a fork-free option test that is true whenever `emulate sh`/`emulate ksh` has run; the exact probe still runs when that test passes, so no answer changes. Measured on zsh 5.9 / macOS: 9.97 ms/run unwrapped, 14.20 ms/run wrapped, 12.27 ms/run wrapped after -- about half the wrapper's cost. * fix(shell): harden the revive override path and silence the option probe on an exotic zsh Readiness-review follow-ups on this branch. - `[[ -o <name> ]]` prints "no such option" to stderr and returns false rather than aborting, so a zsh lacking one of the three Bourne option names would put that text in the user's pane. All three predate every supported zsh, so `2>/dev/null` is belt and braces -- but the belt costs nothing. - Bound the WSL distro name revive replays into `wsl.exe -d <name>`. It is the one field this branch newly routes from untrusted serialized state into argv, and reviveEntry's stated job is to re-apply fresh-spawn bounds. - Skip a pane whose overridden shell can no longer spawn instead of letting the throw escape the revive loop and cost every later entry its state. Skipping, not falling back to the host default shell: substituting a different shell is the defect the override exists to fix, and the args and history env are built for the shell that is gone. The worktree-removal fence throws before this, outside reviveEntry, so it stays a hard failure.
ELI5
On a Windows remote host, opening a terminal that runs WSL gave you the global shell history — every worktree mixed together — while every other shell got its own per-worktree history. This teaches the relay that
wsl.exeis a wrapper around a Linux shell, gives that shell a per-worktreeHISTFILE, and hands it a path the Linux side can actually open.What Changed
src/relay/terminal-history.ts:injectRelayHistoryEnvtakes an optional{ wsl }flag. When set, it resolves the history filename as if the shell werebash(the outer exe iswsl.exe, which matches no shell name) and exports the guest-visible/mnt/<drive>/...form of the host path.src/relay/pty-handler.ts(spawn): detects a WSL launch and, when injection succeeded, addsHISTFILEtoWSLENV— the only channel that carries a host env var into the distro.src/relay/pty-shell-launch.ts: newisRelayWslShell(shellPath, platform), next to the existingwsl.exearg handling.src/shared/wsl-paths.ts/src/main/wsl.ts:toLinuxPathmoved to the pure shared path module and re-exported frommain/wsl, so the relay bundle gets the conversion withoutmain/wsl's distro-probing subprocess graph. No behavior change; thewin32-only UNC branch is preserved inline.Why
STA-4682 claim 2.
historyFilenameonly matchedbash*/zsh*, sowsl.exe— an allowed shell override the client already ships along withhistoryIsolationEnabledandterminalWindowsWslDistro— fell through with noHISTFILE. The desktop already handles exactly this case inlocal-pty-provider.tsby mapping the effective shell tobashand adding WSLENV keys; the relay had no equivalent.Deletion is the reason this is shaped the way it is. Injecting history that nothing can delete is worse than today's no-op, so the injected file deliberately stays on the relay host under the existing flat
~/.orca-remote/terminal-historyroot — the guest reaches it over drvfs, and only the path representation differs. That meansdeleteRelayHistoryis already the working deletion counterpart and needed no change at all: no distro-scoped roots, no metadata sidecar, nowsl.exe-based cleanup. A test asserts the round trip (spawn creates the file,pty.deleteWorktreeHistoryremoves it).Trade-off accepted: a Git-Bash pane and a WSL pane in the same worktree share one
bash_historyfile, where the desktop would separate them by distro. Cross-worktree isolation — the point of the feature — holds either way, and it buys a deletion path that provably works.Not covered (deliberate)
injectWslFishHistoryEnvfor WSL panes because the guest login shell may be fish. Not done here: a fish history file minted into WSL lands at$XDG_DATA_HOME/fish/<session>_historyinside the distro, anddeleteRelayFishHistoryresolves that directory from the relay's own Windows environment, so it would never delete it. Doing it properly needs the desktop's machinery (per-worktree metadata recording the distro, plus awsl.exe --exec fishcleanup likewsl-fish-history-cleanup.ts), which is a larger change than this. Guest fish therefore keeps shared history, exactly as today — no regression, no orphan files. There is a comment at the injection site and a test pinning the behavior.reviveEntry) is left as-is and is not inconsistent with the spawn path: it callsresolveDefaultShell()and ignores the entry's stored shell override, so it re-spawns the host default shell and its history env matches the shell it actually launches. A revived "WSL pane" is not running WSL at all today — that is a separate, larger bug (it would need the shell override serialized into the revive state) and is out of scope here. Noted in a code comment so the divergence is explicit.Linked Issue
STA-4682 (claim 2)
Fixes #
Visual Proof
N/A— no UI surface. The change is shell environment plumbing on the relay host.Testing
Automated, measured on macOS (WSL cannot run here, so every WSL path is unit-tested with a mocked platform/homedir rather than a live distro):
src/relay/terminal-history-wsl.test.ts(new): mocksnode:oshomedir toC:\Users\relayandnode:fsso the drive-letter root is reachable off Windows, and asserts the guest gets/mnt/c/.../<hash>-bash_history. Also pins that a host shell keeps the untranslated path and thatwsl.exewithout the flag still scopes nothing.src/relay/pty-handler-spawn-environment.test.ts: awin32-simulated spawn withshellOverride: 'wsl.exe'asserts (1)HISTFILEis worktree-scoped, (2)WSLENVcarriesHISTFILE, (3)pty.deleteWorktreeHistoryremoves the created file, (4) no fish session is minted.src/relay/pty-shell-launch.test.ts:isRelayWslShellpositive/negative cases including a POSIX remote.Every new assertion was verified to fail without the fix: stashing the source changes and re-running produced 3 failures (
hands the guest a drvfs path...,scopes HISTFILE past the wsl.exe wrapper...,deletes the injected file...); the remaining new cases are regression guards for behavior this PR must not change.Commands run:
npx oxlint <changed files>— cleannpx tsc --noEmit -p config/tsconfig.node.json— cleannpx vitest run --config config/vitest.config.tsover the relay pty/history suites plussrc/main/terminal-history.test.ts,src/main/wsl.test.ts,src/shared/wsl-paths.test.tsand thetoLinuxPathconsumers touched by the move — all passingI manually tested these changes locally
Automated tests added/updated, or explained why not below
Not manually tested: reproducing it needs a Windows relay host with WSL, reached over SSH from a second machine.
AI Disclosure
Claude Opus.
Review
Remote wire compatibility
No wire change.
historyIsolationEnabled,shellOverride, andterminalWindowsWslDistroare all already sent bybuildSshPtySpawnRequest; this only changes what the host does with them. An old host paired with a new client keeps today's behavior (no WSL history scoping); a new host paired with an old client gets scoping as soon as the client sendshistoryIsolationEnabled, which it already does. The serialized revive state is untouched.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
O_NOFOLLOW/lstat/fstatsymlink checks as before; the WSL branch only changes the string exported to the child. No new path is accepted from the client.platform === 'win32'insideisRelayWslShell, so POSIX relays are untouched even if a binary is literally namedwsl.HISTFILEnames an unreachable path and that pane saves no history. The desktop path has the identical exposure, so this sets no new precedent.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)