Skip to content

fix(shell): carry a WSL pane's shell across relay revive and stop forking to probe zsh emulation (STA-4682) - #15361

Merged
nwparker merged 2 commits into
mainfrom
neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation
Aug 18, 2026
Merged

nwparker merged 2 commits into
mainfrom
neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation

Conversation

@nwparker

@nwparker nwparker commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​253 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​237
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​135 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116

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)

  • SerializedPtyEntry gains optional shellOverride and terminalWindowsWslDistro; ManagedPty gains the fields behind them, and serialize() emits them.
  • reviveEntry() re-resolves the stored override through resolvePtyShellOverride — the same allowlist a fresh spawn applies, because revive state is untrusted — and falls back to resolveDefaultShell() when there is none.
  • The WSL history branch that spawn got in fix(relay): scope shell history for Windows -> WSL panes (STA-4682) #15236 is now mirrored on revive: guest-visible /mnt/<drive>/… HISTFILE plus HISTFILE on WSLENV. The distro reaches getRelayShellLaunchConfig and resolvePtyOwnerBackend, and the revived ManagedPty re-stores the fields so the second serialize/revive round trip does not lose them.
  • resolveRevivedShellOverride swallows the rejection rather than rethrowing: revive loops 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)

  • New 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 .zshrc epilogue invocation.
  • Nine generated lines change across all three transports (local, daemon, relay). Nothing else in any wrapper file moves.

Hardening from the readiness review (second commit)

  • 2>/dev/null on the option test. [[ -o <unknown> ]] prints no such option to 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.
  • terminalWindowsWslDistro is length-bounded on the revive read. It is the one field this PR newly routes from replayed, unvalidated state into an argv, and reviveEntry's stated job is re-applying fresh-spawn bounds.
  • A pane whose overridden shell can no longer spawn is skipped rather than allowed to throw out of the revive loop and cost every later entry its state. Skipped, not fallen back to the host default shell: substituting a shell is the defect the override exists to fix, and both the args (-d <distro>) and the history env (/mnt/<drive>/…) are built for the shell that is gone. The worktree-removal fence throws before this, outside reviveEntry, 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/.zprofile that 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 .zshrc probe — which runs after the user's whole .zshrc has loaded — is the most expensive line in the wrapper.

Why a hint in front of the exact probe rather than replacing it. emulate sh and emulate ksh both turn on KSH_ARRAYS, SH_WORD_SPLIT and SH_GLOB, so all-three-off rules emulation out for free. But those options say nothing about emulation, which is what zsh's sourcehome() 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 relaunches wsl.exe with ['-d','Ubuntu'] instead of the default shell; HISTFILE is worktree-scoped and WSLENV carries 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 on main; the fourth is a regression guard.

src/main/zsh-scoped-histfile.live-shell.test.ts (2 new, real zsh): a user .zshenv shadows emulate with a function that logs every arg-less call — the wrapper's probe, and not the epilogue's emulate -L zsh. An ordinary pane records zero probes and still ends with the scoped HISTFILE; a pane whose config runs setopt shwordsplit records more than zero, proving the exact probe still runs when the hint can't rule emulation out. The first fails on main (3 probes).

The pre-existing degrade matrix (emulate sh/emulate ksh from .zshenv, emulate sh from .zprofile, emulate sh from .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 + .zshrc present:

ms/run
unwrapped 9.97
wrapped, before 14.20
wrapped, after 12.27

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; distros Ubuntu-24.04, Sta4593-Federated). Reproduced the exact env the revive path now emits — HISTFILE=/mnt/c/Users/neil/.orca-remote/terminal-history/<name> with WSLENV=HISTFILE, launched as wsl.exe -d Ubuntu-24.04 --exec bash -lc …:

  • guest sees GUEST_HISTFILE=[/mnt/c/Users/neil/.orca-remote/terminal-history/…]
  • guest reads the host-created file (READ_OK) and appends to it (APPEND_OK)
  • the Windows side then reads back both lines — same file, so the existing host-side unlink remains the working deletion counterpart for a revived pane exactly as for a spawned one

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/ksh from .zshenv, .zprofile, .zshrc, plus setopt shwordsplit and setopt ksharrays as false-positive probes) was re-run against the generated wrappers and is byte-identical to main on every row.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Commands: npx tsc --noEmit -p config/tsconfig.node.json, npx oxlint, npx oxfmt --check, and npx vitest run src/main src/relay src/shared — 30,066 passed, 0 failed, 180 skipped.

One sweep also tripped updater.startup-scheduling and an 800-case fuzz in terminal-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

shellOverride and terminalWindowsWslDistro are new optional fields on an existing JSON payload — Rule 1 of docs/reference/remote-wire-compatibility.md. No opcode, no RPC signature change, no RUNTIME_PROTOCOL_VERSION bump.

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 on main. 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_FEATURES and the wrapper files never cross the wire at all — the wrapper is regenerated on launch by whichever host runs the shell.

Cross-platform

  • The revive change is inert off win32: resolvePtyShellOverride returns '' for any non-win32 platform, so a POSIX relay revives the default shell as before. isRelayWslShell is already gated on win32.
  • The wrapper change is zsh-only and platform-independent; bash and fish generation is untouched, and the bash rcfile has no $(emulate).
  • Windows/PowerShell panes are unaffected.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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 .zshenv that hands ZDOTDIR back immediately and defers Orca's work to a precmd hook, taking the residual overhead to +0.2 ms and making the /etc/zshrc HISTFILE 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

  • Security — the revived shell is not taken on trust: it goes through the same ALLOWED_WINDOWS_SHELL_OVERRIDES gate 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 unchanged O_NOFOLLOW/lstat/fstat checks; only the exported string differs for WSL.
  • Backwards compatibility — a wrapper dir written by an older build keeps working; the hint is a pure addition to three if conditions and every other generated byte is identical (snapshot-proven across all three transports).
  • Degradation — a user who sets one of the three Bourne options by hand pays exactly the fork they pay today and gets the identical answer; there is no behavior difference, only a cost difference.
  • Performance — the revive path adds one regex and one env write for WSL panes only. The wrapper change removes up to three forks per zsh pane and adds up to three [[ -o … ]] tests.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker force-pushed the neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation branch from 0e3c463 to ac014b9 Compare August 18, 2026 20:29
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f394121a-ff69-4446-acfc-306e0a166b44

📥 Commits

Reviewing files that changed from the base of the PR and between 65a4e0b83f7d4d7770010fb95b61c879f6e78ba3 and d0048fa.

📒 Files selected for processing (9)
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-zsh-zprofile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-zsh-zshenv.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-zsh-zshrc.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zprofile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshrc.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/relay-zsh-zprofile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/relay-zsh-zshenv.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/relay-zsh-zshrc.txt

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The zsh wrappers now check Bourne-compatible options before running the forked emulate probe. Wrapper snapshots and tests reflect the updated epilogue and startup-file conditions. PTY serialization and revival now preserve shell overrides and WSL distro metadata, restore WSL history configuration, bound distro names, and isolate failures from unsupported or unspawnable overridden shells.

Merge Risk: ⚪ Minimal · up to d0048

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)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary changes: WSL shell restoration during relay revive and reduced zsh emulation probes.
Description check ✅ Passed The description covers the required sections with detailed scope, rationale, testing, compatibility, security, and checklist information.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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.

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/shell-templates.ts (1)

96-114: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten 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-less emulate.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3edabc and ac014b9.

📒 Files selected for processing (16)
  • src/main/daemon/shell-ready.test.ts
  • src/main/providers/local-pty-shell-ready-wrapper-generation.test.ts
  • src/main/shell-templates.ts
  • src/main/shell-wrapper-snapshots/daemon-zsh-zprofile.txt
  • src/main/shell-wrapper-snapshots/daemon-zsh-zshenv.txt
  • src/main/shell-wrapper-snapshots/daemon-zsh-zshrc.txt
  • src/main/shell-wrapper-snapshots/local-zsh-zprofile.txt
  • src/main/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/shell-wrapper-snapshots/local-zsh-zshrc.txt
  • src/main/shell-wrapper-snapshots/relay-zsh-zprofile.txt
  • src/main/shell-wrapper-snapshots/relay-zsh-zshenv.txt
  • src/main/shell-wrapper-snapshots/relay-zsh-zshrc.txt
  • src/main/zsh-scoped-histfile.live-shell.test.ts
  • src/main/zsh-startup-wrapper-builder.ts
  • src/relay/pty-handler-revive.test.ts
  • src/relay/pty-handler.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment thread src/main/shell-templates.ts Resolved
Comment on lines +373 to +374
// 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.

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.

📐 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.

@nwparker
nwparker force-pushed the neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation branch from ac014b9 to 65a4e0b Compare August 18, 2026 20:57
…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.
@nwparker
nwparker force-pushed the neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation branch from 65a4e0b to d0048fa Compare August 18, 2026 21:12
@nwparker
nwparker merged commit 1be6a03 into main Aug 18, 2026
101 of 103 checks passed
@nwparker
nwparker deleted the neil/sta-4682-p2continuous-reland-leftovers-fishwslzsh-history-isolation branch August 18, 2026 21:24
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant