fix(desktop): find user-installed CLIs when shell probing fails #9232
main fromrefs/pull/9232/head·opened View on GitHubProblem#
When POSIX login-shell discovery yields no PATH and macOS launchctl also yields none, startup can miss user-installed CLIs outside the inherited system directories.
Change#
Append a small set of known CLI directories only after those probes fail. Preserve the inherited PATH order and deduplicate entries, so existing nvm/mise/fnm choices retain priority. Successful probe results, Windows handling, caching, mise metadata and AppImage cleanup remain unchanged. Share the directory list between desktop startup and standalone server startup.
Thanks to @CyberStefNef for the original investigation and implementation in #9232. The takeover preserves that history, integrates main, removes six redundant tests and keeps one behavioral regression. An independent review identified the inherited-PATH precedence issue; the final implementation and retained test address it.
Scope and approval#
This is an empty-probe fallback, not a general search of every provider install directory. Provider-specific locations such as ~/.opencode/bin remain outside this bounded list. Refs #7618; it does not establish that incident's root cause or claim to close it. No merge or auto-merge is requested.
Verification#
- 84 focused tests passed, 1 skipped across desktop shell, shared shell and server startup tests. Scoped desktop/server/shared typechecks and targeted lint/format passed.
- Removing the fallback fails the retained regression; restoring prepend behavior fails its inherited-order assertion. Existing main tests reject adding fallback directories to successful probe results.
- Four actual Linux process cases at
d328c42283683b5d1461ef4b52b711b0f968607cinvoked the production desktop environment service and standalonefixPathwith real Node process spawning. Failed/empty shell probes repaired PATH and enabled a unique executable in an isolated~/.local/bin; an inherited duplicate executable still won. Successful-probe controls omitted the fallback directories. - Private HOME/state and captured processes were cleaned up. No Electron/Finder, macOS launchctl, Windows, real provider CLI or complete server-bootstrap verification is claimed.
Model and harness: Claude Opus 5.5 tests and independent review, Claude Fable 5.1 implementation, GPT-6.1 Sol independent review and process proof through T3 Code; standard service tiers.
Takeover#
Replacement: #24632, branch takeover/pr-9232 on origin; original fork untouched.
Thanks @CyberStefNef for the investigation and original fix in #9232. This replacement rebuilds the same bounded fallback against current main; the description above is preserved historical context.
The original unconditional candidate list now filters existing directories; both startup paths share it and retain their existing merges. Three behavioral regressions replace the original mocked case. No parser was added.
Directory decision: platform Homebrew bin (Apple Silicon/Linuxbrew), /usr/local/bin (Intel Homebrew/manual installs), and $HOME/.local/bin (per-user installers). No provider-specific or extra bun/cargo directories.
Evidence#
Captures compare 5a969c17e7 before with 7217838f9d after. The five takeover files are identical at final merge d8646e3df4.
| Fixture | Complete standalone server + actual Electron, before → after |
|---|---|
| L1: all probes fail | CLI absent / command-v exit 1 → private H-only CLI v2.1.0 / exit 0 |
| L2: empty PATH, brew absent, local prefix a file | Only existing H appended; inherited nonexistent entry preserved |
| L3: partial metadata, no PATH | Inherited toolchain v2.1.1 wins both; only missing brew appended |
| L4: successful PATH probe | Probe v2.1.2 wins both; no fallback added |
| L5: PATH unset, all fallback dirs absent | No fallback invented; CLI absent both; existing interactive-shell defaults documented |
| H1: filesystem and caller checks | 326 real-filesystem assertions; 61 focused tests pass, 2 existing skips |
| M1 / W1 | Native macOS launchctl / Windows unverified on Linux; platform plumbing unchanged |
Complete matrix/capture ledger · 54 artifacts, including recordings and two diffs per still pair · reproduction scripts/stubs/logs · proof audit: SUFFICIENT.
Before — real Electron Settings, fixture unavailable:

After — real Electron Settings, fixture detected:

Before — terminal resolution fails:

After — terminal resolves the appended user directory:

Verification log
- Code review round 1: GPT-6.1 Sol and Claude Opus 5.5 both MERGE; no blockers. Pre-existing whitespace-only shell-PATH discrepancy noted, outside this change.
- Independent revert proof: base production bytes with new tests → 3 fail, 58 pass, 2 skip; replacement → 61 pass, 2 skip across desktop/server/shared shell files.
- Main merged by merge commit; post-merge same scoped tests 61 pass / 2 skip. Targeted lint and whitespace checks pass. Shared/server/desktop scoped typechecks pass. Final verification record.
- Proof audit inspected all 48 images, sampled six recordings, checked 20/20 runtime captures, and independently reproduced a real server capture with no behavioral delta.
- Environment: Ubuntu 24.04.5 x86_64, Node 26.12.1, Electron 44.9.3, headless-desktop/Xvfb. Version-only CLI stubs prove discovery, not authentication or agent turns.
- Isolation incident: an early helper inherited host HOME and host keyring mtime changed; contents were not inspected/restored. All desktop rows were repeated with wrapper-level private HOME/XDG. See ledger for limits of the isolation evidence. No live userdata used. Captured processes stopped.
- Native macOS/Windows remain unverified; no new launchctl API/branch behavior. No other blockers. CI pending at publication; dispatcher owns monitoring. Nothing merged.
- Models/harness: Claude Opus 5.5 tests/implementation/reviewer B; GPT-6.1 Sol lead/reviewer A/evidence/proof audit, through T3 Code (Claude Agent and Codex), standard options.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR changes the default POSIX PATH used by desktop and server startup when shell and launchctl probing fail, adding known CLI directories while preserving inherited ordering. The change is small and test-backed, but it modifies product startup defaults and merits human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Hit the same bug (Claude Code and OpenCode installed via their native installers, at ~/.local/bin/claude and ~/.opencode/bin/opencode; neither found on PATH) and had built basically this same fix before finding this PR.
One directory missing from
resolveKnownPosixCliDirsthat would close the gap for OpenCode specifically:~/.opencode/bin. Claude Code is already covered here via the shared~/.local/binentry.Separately (more of a discussion than a one-line fix): this only fires via
Option.orElsewhen both probes return nothing.resolveKnownWindowsCliDirs's usage inresolveWindowsEnvironmentmerges its known dirs unconditionally, after the resolved PATH, regardless of whether the probe succeeded — the comment there even says it's meant to "fill gaps when desktop apps launch without the full interactive-shell PATH." Doing the same here would also catch a probe that succeeds but is just missing a directory. Not proposing this as part of the same patch, since it reverses a guard you explicitly tested for (the two tests asserting known dirs stay out when either probe succeeds) — just flagging the asymmetry with the Windows path in case it's worth a follow-up.Happy to open a PR adding
~/.opencode/binon top of this branch, or hand it over if that's less work for you. juliusmarminge flagged this class of fix as a useful last-resort mitigation on #10534, just not enough on its own to close that issue.juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
Taking over this one. I’ll reduce the tests to the useful coverage, update the implementation against current main, and verify it before publishing the changes.
Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 5 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
b4f038c4-0ff1-453f-9492-39bc9e9b4d53
📥 Commits
-
Reviewing files that changed from the base of the PR and between 3117be980bebd268b9cc6dc8b8609547f7ae3a15 and d328c42283683b5d1461ef4b52b711b0f968607c.
📒 Files selected for processing: 4
-
apps/desktop/src/shell/DesktopShellEnvironment.test.tsapps/desktop/src/shell/DesktopShellEnvironment.tsapps/server/src/os-jank.tspackages/shared/src/shell.ts
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge added labelstakeover
juliusmarminge added labelspr:in-progress
Taking over this one
Thanks @CyberStefNef for identifying the empty-probe PATH failure and the bounded shared fallback. Rebuilt against current main in #24632, retaining the exact directory list and inherited PATH priority, adding directory-existence filtering and minimal behavioral tests. I compared the original diff with the replacement: desktop, standalone server, shared list and regression coverage are all included. Both independent code reviewers returned MERGE and the runtime proof audit is sufficient; native macOS/Windows remain explicitly unverified. Closing this proposal in favor of that replacement; your fork branch was not changed.
juliusmarminge closed this
juliusmarminge removed labelspr:in-progress
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed