Skip to content

Fix remote Node.js detection for nvm, mise, asdf, and volta - #6037

Merged
Jinwoo-H merged 3 commits into
stablyai:mainfrom
thekvn:fix/remote-node-version-manager-detection
Jun 22, 2026
Merged

Jinwoo-H merged 3 commits into
stablyai:mainfrom
thekvn:fix/remote-node-version-manager-detection

Conversation

@thekvn

@thekvn thekvn commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. 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 hardcoded bash -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.

  2. The fixed-path probe missed most version managers and had no version gate:

    • nvm was hardcoded to ~/.nvm (broke custom $NVM_DIR, a common dotfiles pattern).
    • mise, asdf, volta, and n had no probes at all.
    • nvm's "highest version" glob used sort -V but there was no node --version check, 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:

  • Strategy 1 — path probes (first). Probe well-known install directories for every common version manager: nvm (respecting $NVM_DIR), fnm, mise, asdf, volta, n, plus system locations. Probes are joined with newlines, not || — an empty ls | sort -V | tail -1 exits 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.
  • Strategy 2 — login shell (fallback). Resolve $SHELL and run command -v node through it as a login shell, bypassing wrapRemoteCommandForPosixShell. Catches custom PATH setups in ~/.profile / ~/.bash_profile. Short 8s timeout. Note: this is the fallback, not the primary path, because bash -lc skips ~/.bashrc and zsh -lc skips ~/.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:

  • Path-probe resolution for system node, mise, asdf, volta, and NVM_DIR-overridden nvm.
  • Newline-joined probes (no || short-circuit) and candidate deduplication.
  • Version-sort and version-gate edges (Node 18 accepted; Node 10 rejected; mixed candidates select the first valid one).
  • Login-shell fallback: custom $SHELL (fish), empty $SHELL probe, fallback after empty probes, fallback after all-too-old probes.
  • Failure cases: no node anywhere; path-probe exec failure; every candidate below minimum.

Full existing src/main/ssh/ suite stays green (454 passed, 1 skipped live-host).

Code review summary

  • Cross-platform: POSIX path affects Linux + macOS remotes; Windows path (resolveRemoteWindowsNodePath) is unchanged. No new platform assumptions introduced.
  • SSH/remote/local: Change is remote-only by design; local relay install is unaffected.
  • Performance: Path probes run in a single exec round-trip (one script, newline-joined); the version gate adds one exec per candidate but stops at the first valid one. The login-shell fallback only runs when probes find nothing, capped at 8s. Negligible vs. the relay deploy that follows.
  • Security: No new shell interpolation; $SHELL and node paths are passed through the existing shellEscape. No user input reaches the probe strings.
  • Agent/integration/git-provider: N/A.

X

@thekvnxyz

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.
@ghost

ghost commented Jun 22, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Define Node.js version requirements and constants
2 Implement robust Node.js path probing and version gating
3 Verify remote Node.js resolution logic
Open in Stage

Chapters generated by Stage for commit cd497a0 on Jun 22, 2026 11:43pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

ssh-remote-node-resolution.ts is reworked to enforce a Node.js 18+ minimum version and introduce a two-strategy resolution sequence. resolveRemoteNodePath now calls tryResolveViaLoginShell first, which runs command -v node under the remote user's $SHELL with -lc and an 8-second timeout, falling back to /bin/sh with -c when $SHELL is unset. If that strategy returns no valid candidate, tryResolveViaKnownPaths executes a generated probe script covering system paths and common version-manager directories (nvm, fnm, mise, asdf, volta, n). Every candidate path is validated by the new nodeMeetsVersionRequirement helper before acceptance. A new Vitest file covers all these behaviors, including fallthrough scenarios, version gating, and failure-mode error propagation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the What, Why, and The fix sections, includes a comprehensive explanation with examples, and notes no visual change. However, it lacks several required template sections: Screenshots (partially addressed), Testing checklist (not present), AI Review Report (missing cross-platform verification), Security Audit (missing), and Notes (partially present). Add the missing template sections: explicit Testing checklist with checkbox status, detailed AI Review Report with cross-platform verification for macOS/Linux/Windows, Security Audit summary addressing input/command/path handling, and expanded Notes section for platform-specific concerns.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 accurately and concisely describes the main change: fixing remote Node.js detection for multiple version managers (nvm, mise, asdf, volta).
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.

✏️ 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.

❤️ 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: 3

🧹 Nitpick comments (1)
src/main/ssh/ssh-remote-node-resolution.test.ts (1)

55-62: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Misleading test name and comment.

The test name claims "when $SHELL is unset", but the mock returns '' for echo "${SHELL:-/bin/sh}". If $SHELL is 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

📥 Commits

Reviewing files that changed from the base of the PR and between a8feafe and 1bfe3bb.

📒 Files selected for processing (2)
  • src/main/ssh/ssh-remote-node-resolution.test.ts
  • src/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.

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cf7ccfb8-c226-4a29-9046-aa427a017854

📥 Commits

Reviewing files that changed from the base of the PR and between 1bfe3bb and aa87cb8.

📒 Files selected for processing (2)
  • src/main/ssh/ssh-remote-node-resolution.test.ts
  • src/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'

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
'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'

@Jinwoo-H Jinwoo-H 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.

Thanks. I found a few portability gaps during review and added fixes before landing:

  • Removed the GNU-only sort -V dependency from POSIX remote probes.
  • Quoted version-manager paths so homes/custom dirs with spaces work.
  • Added safe NVM_DIR dotfile detection without sourcing shell startup files.
  • Fixed /bin/sh fallback 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.

@Jinwoo-H
Jinwoo-H merged commit 44935d4 into stablyai:main Jun 22, 2026
LesleyMurfin added a commit to LesleyMurfin/orca that referenced this pull request Jun 23, 2026
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]>
Jinwoo-H added a commit that referenced this pull request Jun 23, 2026
…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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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