Skip to content

Detect agents in the serve user's package-manager bins; don't pin empty remote-detect results - #6029

Merged
Jinwoo-H merged 5 commits into
stablyai:mainfrom
LesleyMurfin:fix/relay-detect-user-install-bins
Jun 23, 2026
Merged

Jinwoo-H merged 5 commits into
stablyai:mainfrom
LesleyMurfin:fix/relay-detect-user-install-bins

Conversation

@LesleyMurfin

@LesleyMurfin LesleyMurfin commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes two independent defects that prevent the desktop client from detecting agents installed on a remote orca serve (Fixes #6028):

  • 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, while the user's real PTY sessions are interactive and DO source ~/.bashrc. Agents whose bin is on PATH only via ~/.bashrc (common for per-user package managers) are therefore invisible to detection even though the user can run them, and the POSIX fallback list didn't cover those bins. Fix: 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) and honor a relocated npm prefix via npm_config_prefix, appended to the fallback set and deduped against the inherited PATH via the existing Set semantics. win32 path unchanged.

  • D2 — src/renderer/src/store/slices/detected-agents.ts: an empty detection result ([], which is 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 both detection paths: ensureRemoteDetectedAgents (SSH, kind: 'ssh') and ensureRuntimeDetectedAgents (orca serve, kind: 'runtime'). The runtime path is the one that serves the headline remote-orca serve scenario, so patching only the SSH path would have left the primary case broken. Non-empty results still short-circuit; the in-flight dedup still prevents concurrent re-detect storms; failed requests remain uncached.

No new transport, no PowerShell/bash bridge. This is the minimal change covering the common package-manager prefixes; a fuller fix (sourcing the interactive shell config so the probe sees the exact PTY PATH) would cover the whole login-vs-interactive class but is a larger surface — noted as follow-up, not bundled here.

Screenshots

No visual change. (D1 is relay-side PATH resolution; D2 is a store cache-guard. No UI was touched.)

Testing

  • pnpm lint — pass (oxlint + switch-exhaustiveness + styled-scrollbars + localization catalog/coverage)
  • pnpm typecheck — pass (all 3 tsgo configs)
  • pnpm test — the 3 touched test files pass, 25/25 (full-suite not run locally due to unrelated pre-existing env noise on the dev box — node-pty/fakeredis; clean-env CI is authoritative)
  • pnpm build — not run locally (Electron multi-platform build); relying on CI
  • Added high-quality regression tests: relay-command-env.test.ts (POSIX $HOME-resolved bins; npm_config_prefix honored; dedup against inherited PATH; homedir() fallback on empty HOME; win32 env unchanged with no POSIX bins leaking in), detected-agents.test.ts (empty result re-detects on both the remote/SSH and runtime/serve paths; non-empty short-circuits; in-flight dedup; failure stays uncached — each empty-redetect test was confirmed to fail on the pre-fix if (existing) guard), useDetectedAgents.test.tsx (ssh call site fires once on mount, no re-detect loop on a zero-agent host)

D1 was also validated with a live end-to-end probe on a WSL orca serve: an executable placed in ~/.npm-global/bin (bashrc-only PATH) is invisible to the login-shell probe and to the old POSIX fallback, but detected with the patched buildRelayCommandEnv.

AI Review Report

An independent review pass covered the axes CONTRIBUTING requires:

  • Cross-platform (macOS/Linux/Windows) — PASS. The new user-bin logic is gated behind the win32 early-return in getFallbackSegments; win32 returns WINDOWS_RELAY_PATH_FALLBACKS unchanged. Paths use posix.join (not path.join), so segments are always /-joined — correct, since these are POSIX remote targets. A test explicitly asserts POSIX user bins do not leak into a win32 relay env.
  • SSH / remote / local — PASS. buildRelayCommandEnv is the shared env builder for every relay handler; the change is purely additive (extra PATH segments appended after the inherited PATH). $HOME resolves on the relay host where the probe runs, with a homedir() fallback. Other consumers (git/fs handlers) only get a richer PATH — no behavioral regression. This is exactly the remote-serve path the fix targets.
  • Agent / integration neutrality — PASS. The bin list is package-manager-generic (npm/cargo/bun/go/deno/pnpm), not tied to any agent vendor. D2 is agent-agnostic.
  • Performance — PASS with one by-design note. D1 adds a small bounded set of string joins per probe (not a hot path). D2 intentionally drops the empty-result pin, so a genuinely zero-agent remote re-probes when a launch surface re-invokes detection (dialog open-cycle, repo re-select). This is not an unbounded storm: the auto-firing effect guards on detectedIds === null (and [] ≠ null, so no effect loop), and in-flight dedup collapses concurrent calls. The only added cost is a bounded command -v probe per user-initiated menu re-open on zero-agent hosts — the deliberate trade-off that lets a newly installed agent appear without a reconnect.
  • UI quality — N/A. No UI changes; the isDetectingRemoteAgents spinner state is still set/cleared correctly around the re-detect.

Security Audit

  • Command execution / injection — PASS. The new bins are built with posix.join from HOME / npm_config_prefix and passed as discrete env PATH entries, never interpolated into a shell string. The probe passes the agent name as a positional $1 arg to command -v (unchanged), so the broadened PATH introduces no injection surface.
  • Path handling — PASS (minor nit). Inputs come from the relay user's own environment — the same trust boundary as PATH itself; no privilege boundary is crossed and detection only runs command -v (it never executes the found binary). Non-blocking nit: npm_config_prefix is not asserted absolute, but hasAbsoluteCommandPath only accepts absolute command -v output, so a relative prefix cannot cause a false-positive — harmless. An absolute-path guard is a possible follow-up for PATH hygiene.
  • Secrets / auth / IPC / dependencies — PASS. No secrets read or logged, no new IPC, no new network, no new dependencies (only os.homedir / path.posix from the standard library).

Notes

  • Platform-specific: D1 changes the POSIX relay PATH only; the Windows fallback list is untouched and test-locked.
  • Remote/SSH-specific: this is fundamentally a remote-serve fix; both defects only manifest when the desktop client is paired to a remote orca serve. Local detection is unaffected.
  • Follow-ups (non-blocking): (a) a fuller probe that sources the interactive shell config to capture the exact PTY PATH; (b) an absolute-path guard on npm_config_prefix.

Credit: reported and diagnosed by @hufeide (#5899). This PR corrects the original diagnosis: the -lc / command -v mechanism is already in main; the actual fixes are the login-vs-interactive PATH gap in the relay fallback (D1) and the truthy-[] cache pin (D2).

Contributor: @lesleymurfin on X.

…ty 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) <noreply@anthropic.com>
@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 Resolve package-manager bins in POSIX relay environment
2 Prevent pinning of empty agent detection results
3 Verify detection stability in SSH call sites
Open in Stage

Chapters generated by Stage for commit e63fd39 on Jun 22, 2026 2:24am UTC.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 558e43e6-71ff-4da7-a1ae-2eca128dd0be

📥 Commits

Reviewing files that changed from the base of the PR and between 30dde78 and 0155b91.

📒 Files selected for processing (4)
  • src/relay/relay-command-env.test.ts
  • src/relay/relay-command-env.ts
  • src/renderer/src/hooks/useDetectedAgents.test.tsx
  • src/renderer/src/hooks/useDetectedAgents.ts

📝 Walkthrough

Walkthrough

Two independent changes improve agent detection and relay command environment setup. First, relay-command-env.ts adds per-user install bin directory resolution for both POSIX and Windows platforms: getPosixUserInstallBinFallbacks derives paths from HOME or os.homedir() with tool-specific environment variable overrides (npm_config_prefix, CARGO_HOME, BUN_INSTALL, DENO_INSTALL, GOBIN/GOPATH, PNPM_HOME/XDG_DATA_HOME), while getWindowsUserInstallBinFallbacks handles Windows-specific user bins. These are threaded through the refactored getFallbackSegments and integrated into buildRelayCommandEnv. Test coverage mocks os.homedir() and validates PATH construction across POSIX/Windows isolation, deduplication, fallback chains, and ordering. Second, ensureRemoteDetectedAgents and ensureRuntimeDetectedAgents in the detected-agents store change their cache short-circuits from any truthy value to non-empty array checks, enabling re-detection after empty results. The useDetectedAgents hook adds retry logic via retriedEmptyTargetRef to trigger a one-time re-probe when mounting with an empty prior result, with comprehensive hook tests verifying detection caching, empty-result non-caching, and successful retry after unmount/remount for both SSH and runtime targets.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the two main defects: detecting agents in package-manager bins and not caching empty remote-detect results.
Description check ✅ Passed The description covers all required template sections: Summary (clear user-visible changes), Screenshots (no visual change), Testing (comprehensive test coverage documented), AI Review Report (cross-platform, security, performance validated), and Notes (platform-specific behavior called out).
Linked Issues check ✅ Passed The PR fully addresses both defects in #6028: D1 resolves package-manager bins from $HOME with env-var relocation support and deduplication; D2 changes cache guard from truthy to length-check, enabling re-detection on both SSH and runtime paths.
Out of Scope Changes check ✅ Passed All changes are scoped to the two identified defects: relay-command-env.ts and relay-command-env.test.ts (D1 fix and validation), detected-agents.ts and detected-agents.test.ts (D2 fix and validation), and useDetectedAgents.test.tsx (regression test for the SSH call site).

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

…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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
@LesleyMurfin

Copy link
Copy Markdown
Contributor Author

This PR has both a direct precedent and a companion already in main:

  • Precedent — Fix remote Node.js detection for nvm, mise, asdf, and volta #6037 ("Fix remote Node.js detection for nvm, mise, asdf, and volta"): same root cause as this PR — per-user tooling directories are invisible to a non-interactive shell that skips the user's init files — solved on the SSH path by probing the known per-user install dirs directly (HOME-relative globs, joined so a missing dir doesn't mask the others) rather than relying on the shell to surface them. This PR applies the same "probe what the user actually installed" approach to the relay detection path.
  • Companion — Put the orca CLI on PATH at install time for headless hosts #5842 (@Jinwoo-H, "Put the orca CLI on PATH at install time for headless hosts"): makes the orca binary itself discoverable on a headless host. This PR covers the next layer — detecting the agent CLIs (claude, etc.) the serve user installed into per-user package-manager bins (~/.local/bin, ~/.npm-global/bin, ~/.cargo/bin, ~/.bun/bin, ~/go/bin, ~/.deno/bin, and the pnpm global bin). The relay's login-shell probe (/bin/sh -lc) sources ~/.profile but not the interactive ~/.bashrc, so those bins are on PATH in a normal session yet invisible to detection. Together the two PRs close the headless-host gap end to end.

If useful, I can align the bin resolution here to #6037's structure and add a clean-room Debian + Fedora container matrix to match the bar those PRs set.

(@brennanb2025 — you're the assigned reviewer; flagging the #6037 / #5842 links purely for context.)

@Jinwoo-H
Jinwoo-H requested review from Jinwoo-H and removed request for brennanb2025 June 23, 2026 01:17
@LesleyMurfin

Copy link
Copy Markdown
Contributor Author

Pushed an alignment commit (30dde78) that extends the existing npm_config_prefix precedence to the other per-user package managers — each tool's documented relocation env var now takes precedence over its $HOME default:

  • CARGO_HOME → $CARGO_HOME/bin
  • BUN_INSTALL → $BUN_INSTALL/bin
  • DENO_INSTALL → $DENO_INSTALL/bin
  • GOBIN (else $GOPATH/bin, default ~/go/bin) for Go
  • PNPM_HOME (else $XDG_DATA_HOME/pnpm, default ~/.local/share/pnpm) for pnpm

This mirrors how the remote-node probe honors NVM_DIR before $HOME/.nvm (#6037), so relocated installs stay covered rather than silently falling back to the home-relative path. Added one unit test per env var asserting the relocated bin dir lands on PATH and the $HOME default does not. Full relay-env suite is green (18 tests), typecheck and lint clean.

Jinwoo-H and others added 2 commits June 22, 2026 18:43
Co-authored-by: Orca <help@stably.ai>
…all-bins' into fix/relay-detect-user-install-bins

# Conflicts:
#	src/relay/relay-command-env.test.ts
#	src/relay/relay-command-env.ts

@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, this fixes the right remote detection path.\n\nI added a maintainer follow-up before landing:\n- covered relocation env vars plus common macOS/Linux/Windows user package-manager bins in the relay PATH fallback\n- made hook-owned remote/runtime launch surfaces retry a cached empty result once when reopened, without creating a same-surface detection loop\n- added regression tests for SSH/runtime empty-result retries and the additional platform PATH fallbacks\n\nValidated with targeted tests, full typecheck/lint, and Electron dev runtime checks.

@Jinwoo-H
Jinwoo-H merged commit 0b52d59 into stablyai:main Jun 23, 2026
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
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) <noreply@anthropic.com>

* 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) <noreply@anthropic.com>

* 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) <noreply@anthropic.com>

* Tighten remote agent detection retries

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: LesleyMurfin <260182349+LesleyMurfin@users.noreply.github.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote serve: agents installed in the serve user's package-manager bins aren't detected, and an empty detection result is pinned

4 participants