Repository navigation
fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) - #15361
Conversation
0e3c463 to
ac014b9
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 65a4e0b83f7d4d7770010fb95b61c879f6e78ba3 and d0048fa. 📒 Files selected for processing (9)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe zsh wrappers now check Bourne-compatible options before running the forked Merge Risk: ⚪ Minimal · up to The PR restores the pane's shell and scoped history across relay revive and avoids unnecessary zsh startup forks, with no actionable merge-blocking risk remaining after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/shell-templates.ts (1)
96-114: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the implementation comments.
Keep the invariant and move benchmark detail or repeated rationale to design documentation.
src/main/shell-templates.ts#L96-L114: reduce this comment to the option-hint invariant and the exact-probe fallback rule.src/main/zsh-startup-wrapper-builder.ts#L220-L225: keep only the precedence reason for the braces.src/main/zsh-scoped-histfile.live-shell.test.ts#L347-L354: keep only the reason that the test shadows argument-lessemulate.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 14f66984-2a1a-4feb-9ed1-bbefafd49b88
📒 Files selected for processing (16)
src/main/daemon/shell-ready.test.tssrc/main/providers/local-pty-shell-ready-wrapper-generation.test.tssrc/main/shell-templates.tssrc/main/shell-wrapper-snapshots/daemon-zsh-zprofile.txtsrc/main/shell-wrapper-snapshots/daemon-zsh-zshenv.txtsrc/main/shell-wrapper-snapshots/daemon-zsh-zshrc.txtsrc/main/shell-wrapper-snapshots/local-zsh-zprofile.txtsrc/main/shell-wrapper-snapshots/local-zsh-zshenv.txtsrc/main/shell-wrapper-snapshots/local-zsh-zshrc.txtsrc/main/shell-wrapper-snapshots/relay-zsh-zprofile.txtsrc/main/shell-wrapper-snapshots/relay-zsh-zshenv.txtsrc/main/shell-wrapper-snapshots/relay-zsh-zshrc.txtsrc/main/zsh-scoped-histfile.live-shell.test.tssrc/main/zsh-startup-wrapper-builder.tssrc/relay/pty-handler-revive.test.tssrc/relay/pty-handler.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| // All three probe sites are gated on having sourced the matching user | ||
| // file, so every one of them has to exist for this to mean anything. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the probe-site description.
The .zshrc probe does not require a user .zshrc. Its guard checks login state and the emulation hint. Replace this comment with one that only describes the per-file degradation probes.
ac014b9 to
65a4e0b
Compare
…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.
…obe 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.
65a4e0b to
d0048fa
Compare
…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.
…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.
…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
Two leftovers from the history-isolation work.
One. On a Windows remote host, opening a WSL terminal gets you that worktree's own shell history. Restart the relay and the pane comes back — but as PowerShell, not WSL, with the wrong history. Revive was re-launching the machine's default shell instead of the shell the pane was actually running. Now it remembers.
Two. Orca's zsh wrapper asks the shell "are you pretending to be
sh?" three times during startup. Asking costs a fork of a zsh that already has your whole config loaded — the most expensive thing the wrapper does, and since wrapping widened to every zsh pane, every pane pays it. There's a way to rule the answer out for free, so now Orca only asks when the free check can't settle it.What Changed
Relay revive keeps the pane's shell (
src/relay/pty-handler.ts)SerializedPtyEntrygains optionalshellOverrideandterminalWindowsWslDistro;ManagedPtygains the fields behind them, andserialize()emits them.reviveEntry()re-resolves the stored override throughresolvePtyShellOverride— the same allowlist a fresh spawn applies, because revive state is untrusted — and falls back toresolveDefaultShell()when there is none./mnt/<drive>/…HISTFILEplusHISTFILEonWSLENV. The distro reachesgetRelayShellLaunchConfigandresolvePtyOwnerBackend, and the revivedManagedPtyre-stores the fields so the second serialize/revive round trip does not lose them.resolveRevivedShellOverrideswallows the rejection rather than rethrowing:reviveloops over entries, so one stale override must not throw away every other pane's state.The emulation probe stops forking (
src/main/shell-templates.ts,src/main/zsh-startup-wrapper-builder.ts)ZSH_BOURNE_EMULATION_OPTION_HINT—[[ -o ksharrays || -o shwordsplit || -o shglob ]] 2>/dev/null— in front of all three$(emulate 2>/dev/null)sites: the two degrade blocks (.zshenv,.zprofile) and the.zshrcepilogue invocation.Hardening from the readiness review (second commit)
2>/dev/nullon the option test.[[ -o <unknown> ]]printsno such optionto stderr and returns false rather than aborting, so a zsh lacking one of these names would put that text in the user's pane. All three predate every supported zsh; the suppression costs nothing and deletes the class.terminalWindowsWslDistrois length-bounded on the revive read. It is the one field this PR newly routes from replayed, unvalidated state into an argv, andreviveEntry's stated job is re-applying fresh-spawn bounds.-d <distro>) and the history env (/mnt/<drive>/…) are built for the shell that is gone. The worktree-removal fence throws before this, outsidereviveEntry, so it stays a hard failure.Why
STA-4682's two continuous-readiness residuals — the ones the ticket's last comment says to reuse this tracker for.
Revive. #15236 scoped WSL history on spawn and said so explicitly in its own "Not covered" section: "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)." That is this. The user-visible defect is bigger than history: the pane silently changes shell class on a relay restart. Serializing the override fixes the shell, and fixing the shell is what makes the history injection correct — the env now matches the shell that actually launches, which is the property the old code preserved by not injecting.
The probe. #15258's own blast-radius section priced the change: "those panes now source four small generated files and run one function. A login zsh additionally forks once for
$(emulate)… and once more per user.zshenv/.zprofilethat actually exists." That was an acceptable price for a few percent of panes and a worse one for all of them.$( )forks the current zsh, so the.zshrcprobe — which runs after the user's whole.zshrchas loaded — is the most expensive line in the wrapper.Why a hint in front of the exact probe rather than replacing it.
emulate shandemulate kshboth turn onKSH_ARRAYS,SH_WORD_SPLITandSH_GLOB, so all-three-off rules emulation out for free. But those options say nothing aboutemulation, which is what zsh'ssourcehome()actually branches on — a config that sets one by hand is not in emulation and must still get the real answer. So the hint only ever skips the fork, never answers in its place. It is||, not&&: the only way past it is to enter emulation and then unset all three. A false positive costs exactly the fork this saves.Linked Issue
STA-4682 — https://linear.app/stably/issue/STA-4682
Fixes #
Visual Proof
N/A— no UI surface. Shell environment plumbing on the relay host and generated shell startup files.Testing
Automated —
src/relay/pty-handler-revive.test.ts(4 new, win32-simulated): revive relauncheswsl.exewith['-d','Ubuntu']instead of the default shell;HISTFILEis worktree-scoped andWSLENVcarries it; the override survives a second serialize round trip; one entry with a rejected override degrades without failing the batch. Three of the four fail onmain; the fourth is a regression guard.src/main/zsh-scoped-histfile.live-shell.test.ts(2 new, real zsh): a user.zshenvshadowsemulatewith a function that logs every arg-less call — the wrapper's probe, and not the epilogue'semulate -L zsh. An ordinary pane records zero probes and still ends with the scopedHISTFILE; a pane whose config runssetopt shwordsplitrecords more than zero, proving the exact probe still runs when the hint can't rule emulation out. The first fails onmain(3 probes).The pre-existing degrade matrix (
emulate sh/emulate kshfrom.zshenv,emulate shfrom.zprofile,emulate shfrom.zshrc) is the net for false negatives and is unchanged and green.Measured, zsh 5.9 / macOS, 150 login startups per arm against the real generated wrapper files, with a user
.zshenv+.zprofile+.zshrcpresent:Re-measured through a pty — what a pane actually is — median of 25 x 3 rounds, because
$( )forks the current shell and a pty-attached zsh is a heavier thing to fork: 13.2 unwrapped, 16.1 before, 14.6 after. Same shape, on the arm panes actually run in.Manual, real Windows + WSL (
awin, over the Orca remote server; distrosUbuntu-24.04,Sta4593-Federated). Reproduced the exact env the revive path now emits —HISTFILE=/mnt/c/Users/neil/.orca-remote/terminal-history/<name>withWSLENV=HISTFILE, launched aswsl.exe -d Ubuntu-24.04 --exec bash -lc …:GUEST_HISTFILE=[/mnt/c/Users/neil/.orca-remote/terminal-history/…]READ_OK) and appends to it (APPEND_OK)A separate assertion pins
toLinuxPath('C:\Users\neil\.orca-remote\…')to the byte-identical path proved above, so what the code generates is what was tested on the host.Two more revive tests cover the hardening: an over-long distro name is dropped rather than passed to
wsl.exe, and a pane whose shell fails to spawn is skipped while the rest of the batch revives. Both fail without their guard. The seven-case real-zsh behavior matrix (emulate sh/kshfrom.zshenv,.zprofile,.zshrc, plussetopt shwordsplitandsetopt ksharraysas false-positive probes) was re-run against the generated wrappers and is byte-identical tomainon every row.Commands:
npx tsc --noEmit -p config/tsconfig.node.json,npx oxlint,npx oxfmt --check, andnpx vitest run src/main src/relay src/shared— 30,066 passed, 0 failed, 180 skipped.One sweep also tripped
updater.startup-schedulingand an 800-case fuzz interminal-output-frame-chunks-equivalence; both pass 30/30 twice in isolation and neither is touched here.Not tested: a live relay restart on a Windows host with an open WSL pane. That needs a Windows relay reached over SSH from a second machine, and the revive path is unit-tested with a simulated platform instead.
AI Disclosure
Claude Opus.
Review
Remote wire compatibility
shellOverrideandterminalWindowsWslDistroare new optional fields on an existing JSON payload — Rule 1 ofdocs/reference/remote-wire-compatibility.md. No opcode, no RPC signature change, noRUNTIME_PROTOCOL_VERSIONbump.The reader treats both as optional and falls back to today's behavior, which is what Rule 1 requires: state serialized by a relay that predates the fields revives
resolveDefaultShell(), exactly as every relay does onmain. State written by a new relay and handed to an older one has the extra keys stripped, with the same result. Neither side ever requires the field.ORCA_SHELL_FEATURESand the wrapper files never cross the wire at all — the wrapper is regenerated on launch by whichever host runs the shell.Cross-platform
resolvePtyShellOverridereturns''for any non-win32 platform, so a POSIX relay revives the default shell as before.isRelayWslShellis already gated on win32.$(emulate).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.Follow-up filed
A prototype showed the wrapper can collapse from four generated files to a single
.zshenvthat handsZDOTDIRback immediately and defers Orca's work to aprecmdhook, taking the residual overhead to +0.2 ms and making the/etc/zshrcHISTFILE clobber structurally unreachable rather than something to repair. That is a large change to the highest-blast-radius path here and needs the live-shell suite ported to a pty harness first, so it is STA-4786, not this PR.Notes
ALLOWED_WINDOWS_SHELL_OVERRIDESgate as a fresh spawn, and the raw client token is stored rather than the resolved path, so Git Bash is re-resolved against this host instead of replaying a path a client supplied. The history file is created with the unchangedO_NOFOLLOW/lstat/fstatchecks; only the exported string differs for WSL.ifconditions and every other generated byte is identical (snapshot-proven across all three transports).[[ -o … ]]tests.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)