Skip to content

fix(daemon): resolve Unix shell fallback before node-pty spawn - #8306

Merged
AmethystLiang merged 2 commits into
mainfrom
fix/linux-daemon-shell-fallback
Jul 11, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
fix/linux-daemon-shell-fallback

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Linux, a failed exec inside node-pty's forked child does not throw — the child just dies, leaving a silently dead daemon terminal when the preferred shell (e.g. /bin/zsh default on hosts without zsh) is missing. This also hits SSH relay hosts, which run the same daemon spawn path.

  • Resolve the shell before spawning (resolveUnixShellPath): validate the preferred shell pre-fork and fall back through /bin/zsh → /bin/bash → /bin/sh, matching spawnShellWithFallback's local-provider chain. If nothing is executable, throw a clear error before node-pty forks (surfaced via the daemon RPC error path instead of a dead shell). Non-absolute shells are left untouched so execvp can resolve them against PATH/cwd. env.SHELL and the shell-ready launch config are derived from the resolved shell, matching LocalPtyProvider.
  • Reconcile the shell-ready barrier with the resolved shell: the caller computes shellReadySupported from the preferred shell before spawn. A fallback shell without the ready marker (e.g. /bin/sh) would otherwise queue startup commands until the shell-ready timeout and bracketed-paste-wrap them for a line editor without paste mode. The subprocess handle now reports the shell that actually spawned, and TerminalHost drops the stale flag when that shell can't emit the marker.

Testing

  • pnpm vitest run src/main/daemon src/main/providers (1223 passed)
  • pnpm typecheck, pnpm exec oxlint on touched files
  • New unit coverage: fallback resolution order/dedupe/no-shell error, launch-config derivation from the resolved shell, and TerminalHost barrier reconciliation (immediate delivery + no paste-wrap for /bin/sh, barrier kept for bash).

Made with Orca 🐋

Vitus213 and others added 2 commits July 11, 2026 01:09
… shell

The adapter computes shellReadySupported from the preferred shell before
spawn. When the daemon falls back (e.g. to /bin/sh), the session would
queue startup commands for the full 15s ready-marker timeout and wrap
multiline prompts in bracketed-paste markers the fallback shell cannot
parse. Expose the spawned shell on SubprocessHandle and downgrade the
barrier and paste wrapping in TerminalHost when the actual shell cannot
emit the marker.

Also apply the Unix shell fallback after the relay env scrub so a
scrubbed SHELL cannot drop the corrected value, and cover the resolve-
before-launch-config ordering, the no-shell throw, and candidate dedup
with tests.

Co-authored-by: Orca <[email protected]>
@AmethystLiang
AmethystLiang merged commit 9b3ed39 into main Jul 11, 2026
8 checks passed
@AmethystLiang
AmethystLiang deleted the fix/linux-daemon-shell-fallback branch July 11, 2026 17:45
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Unix shell paths are now resolved to executable fallback shells before PTY creation. The resolved path is propagated through subprocess handles and used to determine shell-ready barriers and bracketed-paste behavior. Shell-specific startup handling distinguishes Bash and Zsh from fallback shells such as /bin/sh. Tests cover resolution, fallback spawning, error propagation, subprocess metadata, readiness behavior, and command formatting.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers Summary and Testing, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including screenshots or "No visual change", AI review details, security audit summary, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: resolving Unix shell fallback before spawning node-pty.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

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

351-354: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a brief comment explaining the zsh/bash-only allowlist.

shellPathSupportsPtyStartupBarrier hardcodes support to only zsh/bash, which now gates both pre-spawn shellReadySupported computation and post-spawn reconciliation against the actual fallback shell. The reason (only these shells get the Orca shell-ready wrapper injection, e.g. ZDOTDIR) isn't obvious from this snippet — a one-line comment would help future readers avoid assuming sh/dash/fish support was simply forgotten.

📝 Suggested comment addition
+// Why zsh/bash only: these are the only shells the daemon injects the
+// shell-ready wrapper (ZDOTDIR/marker) into; other shells never emit it.
 export function shellPathSupportsPtyStartupBarrier(shellPath: string): boolean {
   const shellName = pathWin32.basename(basename(shellPath)).toLowerCase()
   return shellName === 'zsh' || shellName === 'bash'
 }
As per coding guidelines, "When code is driven by a design document or non-obvious constraint, add a brief one- or two-line comment explaining why it behaves that way, without restating the implementation."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e68fa8c7-9525-4208-89e9-2619d84d08ee

📥 Commits

Reviewing files that changed from the base of the PR and between ff8192a and 1c226a3.

📒 Files selected for processing (8)
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/daemon/session.ts
  • src/main/daemon/shell-ready.ts
  • src/main/daemon/terminal-host.test.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/local-pty-utils.test.ts
  • src/main/providers/local-pty-utils.ts

@AmethystLiang
AmethystLiang restored the fix/linux-daemon-shell-fallback branch July 11, 2026 23:47
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#8306)

* fix: resolve daemon shell before spawning

* fix(daemon): reconcile shell-ready barrier with the resolved fallback shell

The adapter computes shellReadySupported from the preferred shell before
spawn. When the daemon falls back (e.g. to /bin/sh), the session would
queue startup commands for the full 15s ready-marker timeout and wrap
multiline prompts in bracketed-paste markers the fallback shell cannot
parse. Expose the spawned shell on SubprocessHandle and downgrade the
barrier and paste wrapping in TerminalHost when the actual shell cannot
emit the marker.

Also apply the Unix shell fallback after the relay env scrub so a
scrubbed SHELL cannot drop the corrected value, and cover the resolve-
before-launch-config ordering, the no-shell throw, and candidate dedup
with tests.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Vitus Apollo <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

2 participants