Repository navigation
Fix remote Node.js detection for nvm, mise, asdf, and volta - #6037
Conversation
Remote Node resolution failed when node was installed via a version manager (nvm with custom NVM_DIR, mise, asdf, volta) or when the user's login shell was zsh/fish rather than bash. Root cause: the SSH exec transport runs every command under /bin/sh, which never sources shell init files. The only init-aware path was a hardcoded `bash -lc` fallback that missed zsh/fish users and was never reached for the newer version managers. nvm was handled by guessing ~/.nvm (breaking custom NVM_DIR), and mise/asdf/volta had no probes at all. There was also no version gate, so nvm's highest-version glob could return Node 8/10/12 and crash the relay on launch. Fix: resolve via the user's own $SHELL as a login shell first (the only path that runs nvm.sh / mise activate / asdf.sh init hooks), then fall back to direct path probes for all major managers (nvm respecting $NVM_DIR, fnm, mise, asdf, volta, n) plus system locations. Every candidate is version-checked against the relay's Node 18+ requirement before being accepted.
|
Ready to review this PR? Stage has broken it down into 3 individual chapters for you:
Chapters generated by Stage for commit cd497a0 on Jun 22, 2026 11:43pm UTC. |
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 3
🧹 Nitpick comments (1)
src/main/ssh/ssh-remote-node-resolution.test.ts (1)
55-62: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winMisleading test name and comment.
The test name claims "when $SHELL is unset", but the mock returns
''forecho "${SHELL:-/bin/sh}". If$SHELLis actually unset on the remote system, the Bash parameter expansion${SHELL:-/bin/sh}would output"/bin/sh", not an empty string.The test is correctly verifying fallthrough behavior when the shell probe returns empty output, but the name and comment (line 57) incorrectly describe the scenario as "$SHELL is unset". Consider renaming to something like "falls through to path probes when $SHELL probe returns empty" to accurately reflect what the mock simulates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6d98e304-9313-46f2-82bb-0c1141f3a5ca
📒 Files selected for processing (2)
src/main/ssh/ssh-remote-node-resolution.test.tssrc/main/ssh/ssh-remote-node-resolution.ts
- Reorder to path-probes first (deterministic, doesn't depend on shell rc-file semantics where bash -lc skips .bashrc and zsh -lc skips .zshrc — exactly where nvm/mise/asdf hooks live). - Join probes with newlines instead of || so an empty `ls | sort -V | tail -1` (exit 0) doesn't mask later probes. - Deduplicate candidate paths before version-checking. - Drop unreachable mock and fix misleading $SHELL-unset test name. - Login shell is now a fallback for custom ~/.profile PATH setups.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: cf7ccfb8-c226-4a29-9046-aa427a017854
📒 Files selected for processing (2)
src/main/ssh/ssh-remote-node-resolution.test.tssrc/main/ssh/ssh-remote-node-resolution.ts
| // volta: single bin dir with the active version symlinked in. | ||
| 'command -v $HOME/.volta/bin/node 2>/dev/null', | ||
| // n: installs into /usr/local or a user-local prefix. | ||
| 'command -v /usr/local/n/versions/node/*/bin/node 2>/dev/null' |
There was a problem hiding this comment.
Use ls ... | sort -V | tail -1 for the n version manager to ensure highest version selection.
The n probe uses command -v with a glob pattern, which expands in lexicographic order (e.g., v10, v18, v2, v20) rather than version-aware order. This is inconsistent with the nvm, fnm, mise, and asdf probes (lines 65, 68, 71, 74), which all use ls ... | sort -V | tail -1 to explicitly select the highest installed version. If multiple n versions are present, this probe might return a lower version that happens to come first lexicographically.
🔧 Proposed fix to align with other version manager probes
- 'command -v /usr/local/n/versions/node/*/bin/node 2>/dev/null'
+ 'ls -1 /usr/local/n/versions/node/*/bin/node 2>/dev/null | sort -V | tail -1'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 'command -v /usr/local/n/versions/node/*/bin/node 2>/dev/null' | |
| 'ls -1 /usr/local/n/versions/node/*/bin/node 2>/dev/null | sort -V | tail -1' |
Co-authored-by: Orca <[email protected]>
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks. I found a few portability gaps during review and added fixes before landing:
- Removed the GNU-only
sort -Vdependency from POSIX remote probes. - Quoted version-manager paths so homes/custom dirs with spaces work.
- Added safe
NVM_DIRdotfile detection without sourcing shell startup files. - Fixed
/bin/shfallback to avoid non-portable-l. - Added regression coverage, including executing the generated probe script under
/bin/sh.
Validated with the SSH unit suite, typecheck/lint, relay build, and Docker-backed Electron SSH e2e using a custom NVM_DIR path with spaces.
Extend the existing npm_config_prefix precedence to cargo, bun, deno, go, and pnpm so relocated installs (CARGO_HOME, BUN_INSTALL, DENO_INSTALL, GOBIN/GOPATH, PNPM_HOME/XDG_DATA_HOME) are detected, falling back to the $HOME defaults. Mirrors the remote-node probe's NVM_DIR handling (stablyai#6037). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ty remote-detect results (#6029) * Detect agents in the serve user's package-manager bins; don't pin empty remote-detect results Two defects prevent the desktop client from detecting agents installed on a remote `orca serve`: D1 (src/relay/relay-command-env.ts): the relay probes agents with a login shell (`/bin/sh -lc`), which sources ~/.profile but not the interactive ~/.bashrc that real PTY sessions source. Per-user package-manager bins added to PATH only in ~/.bashrc are therefore invisible to detection. Resolve the serve user's package-manager bins from $HOME (.local/bin, .npm-global/bin, .cargo/bin, .bun/bin, go/bin, .deno/bin, .local/share/pnpm), honor npm_config_prefix, append to the POSIX fallback set, dedupe against inherited PATH; win32 unchanged. D2 (src/renderer/src/store/slices/detected-agents.ts): an empty detection result ([], truthy in JS) was pinned by the `if (existing)` short-circuit, so detection never retried after the server env was fixed. Changed to `if (existing?.length)`; in-flight dedup still prevents re-detect storms; failures stay uncached. No new transport, no PowerShell/bash bridge. D1 and D2 are independent. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Also patch the runtime (orca serve) detection path against the empty-pin bug The D2 fix guarded only ensureRemoteDetectedAgents (the SSH path). The desktop client's headline scenario — pairing to a remote `orca serve` — routes through ensureRuntimeDetectedAgents (kind: 'runtime'), which had the identical bug: an empty detection result ([], truthy in JS) was pinned by the `if (existing)` short-circuit, so a later install / PATH fix was never picked up without a reconnect. Change the runtime guard to `if (existing?.length)`, mirroring the remote path. In-flight dedup still collapses concurrent re-detects; failed requests stay uncached. Add a runtime regression test proving detection re-runs after an empty result (fails on the pre-fix guard). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Honor package-manager relocation env vars in relay PATH detection Extend the existing npm_config_prefix precedence to cargo, bun, deno, go, and pnpm so relocated installs (CARGO_HOME, BUN_INSTALL, DENO_INSTALL, GOBIN/GOPATH, PNPM_HOME/XDG_DATA_HOME) are detected, falling back to the $HOME defaults. Mirrors the remote-node probe's NVM_DIR handling (#6037). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Tighten remote agent detection retries Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: LesleyMurfin <[email protected]> Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
…#6037) * Fix remote Node.js detection for nvm, mise, asdf, and volta Remote Node resolution failed when node was installed via a version manager (nvm with custom NVM_DIR, mise, asdf, volta) or when the user's login shell was zsh/fish rather than bash. Root cause: the SSH exec transport runs every command under /bin/sh, which never sources shell init files. The only init-aware path was a hardcoded `bash -lc` fallback that missed zsh/fish users and was never reached for the newer version managers. nvm was handled by guessing ~/.nvm (breaking custom NVM_DIR), and mise/asdf/volta had no probes at all. There was also no version gate, so nvm's highest-version glob could return Node 8/10/12 and crash the relay on launch. Fix: resolve via the user's own $SHELL as a login shell first (the only path that runs nvm.sh / mise activate / asdf.sh init hooks), then fall back to direct path probes for all major managers (nvm respecting $NVM_DIR, fnm, mise, asdf, volta, n) plus system locations. Every candidate is version-checked against the relay's Node 18+ requirement before being accepted. * Address CodeRabbit review: probes-first, no || short-circuit - Reorder to path-probes first (deterministic, doesn't depend on shell rc-file semantics where bash -lc skips .bashrc and zsh -lc skips .zshrc — exactly where nvm/mise/asdf hooks live). - Join probes with newlines instead of || so an empty `ls | sort -V | tail -1` (exit 0) doesn't mask later probes. - Deduplicate candidate paths before version-checking. - Drop unreachable mock and fix misleading $SHELL-unset test name. - Login shell is now a fallback for custom ~/.profile PATH setups. * Fix remote Node path probing portability Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
…ty remote-detect results (stablyai#6029) * Detect agents in the serve user's package-manager bins; don't pin empty remote-detect results Two defects prevent the desktop client from detecting agents installed on a remote `orca serve`: D1 (src/relay/relay-command-env.ts): the relay probes agents with a login shell (`/bin/sh -lc`), which sources ~/.profile but not the interactive ~/.bashrc that real PTY sessions source. Per-user package-manager bins added to PATH only in ~/.bashrc are therefore invisible to detection. Resolve the serve user's package-manager bins from $HOME (.local/bin, .npm-global/bin, .cargo/bin, .bun/bin, go/bin, .deno/bin, .local/share/pnpm), honor npm_config_prefix, append to the POSIX fallback set, dedupe against inherited PATH; win32 unchanged. D2 (src/renderer/src/store/slices/detected-agents.ts): an empty detection result ([], truthy in JS) was pinned by the `if (existing)` short-circuit, so detection never retried after the server env was fixed. Changed to `if (existing?.length)`; in-flight dedup still prevents re-detect storms; failures stay uncached. No new transport, no PowerShell/bash bridge. D1 and D2 are independent. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Also patch the runtime (orca serve) detection path against the empty-pin bug The D2 fix guarded only ensureRemoteDetectedAgents (the SSH path). The desktop client's headline scenario — pairing to a remote `orca serve` — routes through ensureRuntimeDetectedAgents (kind: 'runtime'), which had the identical bug: an empty detection result ([], truthy in JS) was pinned by the `if (existing)` short-circuit, so a later install / PATH fix was never picked up without a reconnect. Change the runtime guard to `if (existing?.length)`, mirroring the remote path. In-flight dedup still collapses concurrent re-detects; failed requests stay uncached. Add a runtime regression test proving detection re-runs after an empty result (fails on the pre-fix guard). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Honor package-manager relocation env vars in relay PATH detection Extend the existing npm_config_prefix precedence to cargo, bun, deno, go, and pnpm so relocated installs (CARGO_HOME, BUN_INSTALL, DENO_INSTALL, GOBIN/GOPATH, PNPM_HOME/XDG_DATA_HOME) are detected, falling back to the $HOME defaults. Mirrors the remote-node probe's NVM_DIR handling (stablyai#6037). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * Tighten remote agent detection retries Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: LesleyMurfin <[email protected]> Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
What
Fixes remote Node.js detection failing when node is installed via a version manager (nvm with a custom $NVM_DIR, mise, asdf, volta) or when the user's login shell is zsh/fish rather than bash.
Why it was broken
Remote Node resolution (
resolveRemoteNodePath) had two compounding bugs:The SSH exec transport runs every command under
/bin/sh, which never sources shell init files (.bashrc/.zshrc/nvm.sh/mise activate). The only init-aware path was a hardcodedbash -lc 'command -v node'fallback — which misses zsh/fish users (their hooks live in~/.zshrc, not sourced by bash) and can hang on interactive configs (conda prompts) until the 30s exec timeout.The fixed-path probe missed most version managers and had no version gate:
~/.nvm(broke custom $NVM_DIR, a common dotfiles pattern).sort -Vbut there was nonode --versioncheck, so it could return Node 8/10/12 and crash the relay on launch (relay requires Node 18+).The fix
Two strategies, tried in order, each version-gating every candidate against the relay's Node 18+ requirement:
||— an emptyls | sort -V | tail -1exits 0, so||would short-circuit and mask later probes (fnm/mise/asdf/volta behind a missing nvm dir). Candidates are deduplicated before the version gate.command -v nodethrough it as a login shell, bypassingwrapRemoteCommandForPosixShell. Catches custom PATH setups in~/.profile/~/.bash_profile. Short 8s timeout. Note: this is the fallback, not the primary path, becausebash -lcskips~/.bashrcandzsh -lcskips~/.zshrc— exactly where nvm/mise/asdf hooks commonly live — so the deterministic path probes are more reliable.Screenshots
No visual change. This is a backend SSH-layer fix; no UI or interaction behavior changes.
Tests
New test file
ssh-remote-node-resolution.test.ts(17 cases) covering:NVM_DIR-overridden nvm.||short-circuit) and candidate deduplication.Full existing
src/main/ssh/suite stays green (454 passed, 1 skipped live-host).Code review summary
resolveRemoteWindowsNodePath) is unchanged. No new platform assumptions introduced.shellEscape. No user input reaches the probe strings.X
@thekvnxyz