desktop: a timed-out shell env probe at launch leaves the whole session on the minimal PATH
Description
After a reboot, Desktop launched at login and its shell environment probe timed out. Desktop then ran the whole session with launchd's minimal environment, PATH=/usr/bin:/bin:/usr/sbin:/sbin. Every agent shell command lost Homebrew, nvm and other user paths, so gh, node and bun were "command not found" until I restarted the app. Plugins running in Desktop's main process could not find their CLIs either.
The same zsh -il -c 'env -0' takes about 2 s when the machine is idle. Under login load it took longer than the 5 s limit.
This is the V2 version of #49449, which was closed in the V1 triage. The code on dev still behaves the same way:
packages/desktop/src/main/service/shell-env.ts: when the-ilprobe returnsETIMEDOUT,loadShellEnvreturnsnullright away and never tries the-lfallback.packages/desktop/src/main/lifecycle/environment.ts:preferApplicationEnvironmentcopies the probed variables intoprocess.envonly when a probe succeeds, and nothing probes again later. One slow probe at launch decides the environment for the whole session, including the background service it starts.
Expected: a timeout falls back to -l, and a failed probe is retried later (for example in the background, then applied before the next service start), or at least reported in the UI. As it stands, the first sign is agents failing with "command not found".
Plugins
None needed to reproduce. Agent shell commands fail on their own.
OpenCode version
Desktop 2.2.6 (bundled CLI 2.2.6)
Steps to reproduce
- Have a login shell whose interactive startup takes more than 5 s. Launching Desktop at login right after a reboot did this for me. From the source, adding
sleep 6to~/.zshrcshould trigger it on demand; I have not tested that variant. - Launch Desktop from Finder or at login.
main.logshows[server] Interactive shell env probe timed out: /bin/zsh.- Ask an agent to run
echo $PATHorgh --version. The PATH is/usr/bin:/bin:/usr/sbin:/sbinand Homebrew binaries are not found. - Restart Desktop with an idle machine. The probe succeeds and the PATH is correct again.
Screenshot and/or share link
N/A
Operating System
macOS 27.0.1
Terminal
OpenCode Desktop
Thanks for the detailed report. I reproduced this by running Desktop's shell-environment loader directly. I don't have macOS here, but the loader has no macOS-specific code path, and shell-env.ts is identical between v2.2.6 and the latest dev (caf8d6a55).
Setup: a login profile that adds a Homebrew-like directory to PATH, plus an interactive rc that runs sleep 6, in a launchd-like environment (PATH=/usr/bin:/bin:/usr/sbin:/sbin).
bash -lon its own finishes quickly with the extra directory on PATH, so the-lfallback would have worked.loadShellEnvlogs[server] Interactive shell env probe timed out: /bin/bashand returnsnullwithout trying-l.- After the startup merge,
process.env.PATHstays/usr/bin:/bin:/usr/sbin:/sbin.preferApplicationEnvironmentruns only once at startup, so nothing probes again later in the session.
The script below reproduces it. Related:
- #49449: the same problem on v1, closed in the v1 cleanup rather than fixed
- #49268: an unmerged v1 pull request that added the
-lretry after a timeout - #62667: an open pull request that makes the probe async but keeps the same timeout behaviour
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Reproduces anomalyco/opencode#62732 against the desktop shell-env code.
# Usage: REPO=/path/to/opencode-checkout bash repro.sh
# A fake HOME whose login profile adds a "Homebrew" dir to PATH, and whose
# interactive rc takes 6 s (> the 5 s probe timeout), like a slow ~/.zshrc.
set -euo pipefail
REPO=${REPO:-/workspace/repo}
H=$(mktemp -d)
mkdir -p "$H/brew/bin"; printf '#!/bin/sh\necho gh fake\n' > "$H/brew/bin/gh"; chmod +x "$H/brew/bin/gh"
cat > "$H/.bash_profile" <<P
export PATH="$H/brew/bin:\$PATH"
case \$- in *i*) . "$H/.bashrc";; esac
P
echo 'sleep 6' > "$H/.bashrc"
cat > "$REPO/packages/desktop/repro-62732.ts" <<'T'
import { NodePath } from "@effect/platform-node"
import { Effect } from "effect"
import { loadShellEnv } from "./src/main/service/shell-env"
const t = Date.now()
const env = await Effect.runPromise(
loadShellEnv("/bin/bash").pipe(Effect.provide(NodePath.layer)) as any,
)
console.log(`loadShellEnv took ${Date.now() - t} ms, result:`, env === null ? "null" : `PATH=${(env as any).PATH}`)
// what preferApplicationEnvironment then does: Object.assign(process.env, { ...shellEnv })
Object.assign(process.env, { ...(env as any) })
console.log("process.env.PATH after preferApplicationEnvironment-style merge:", process.env.PATH)
T
cd "$REPO/packages/desktop"
echo "== bash -l alone (what the -l fallback would return):"
env -i HOME="$H" PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/bash -l -c 'echo PATH=$PATH; command -v gh'
echo "== loadShellEnv with a launchd-like minimal env:"
env -i HOME="$H" SHELL=/bin/bash PATH=/usr/bin:/bin:/usr/sbin:/sbin "$(command -v bun)" repro-62732.ts
rm -f repro-62732.ts
Run it: bash repro.sh
Root cause: in packages/desktop/src/main/service/shell-env.ts, loadShellEnv returns null as soon as the -il probe times out. The -l fallback only runs when -il fails outright, never on a timeout, so a slow login shell at launch leaves the session on launchd's minimal PATH.
Fix is up in #62736: on timeout, fall through to the -l probe. Added a regression test that fails on the old code and passes with the fix (bun test 4/4 in packages/desktop).
Hit this on Desktop 2.3.2 (macOS, arm64, zsh). The 2.4.1 bundle still has the same timeout path.
Desktop log:
[server] Interactive shell env probe timed out: /bin/zsh
The background service then started with PATH=/usr/bin:/bin:/usr/sbin:/sbin. The first visible symptom was the Claude Agent provider failing with "Install Claude Code and run claude auth login first", same as #61829.
Three things #62736 doesn't cover:
- The service outlives the app. Quitting and relaunching Desktop did not fix it. The service started on the minimal PATH kept running (reparented to launchd) and the relaunched app reused it. Only
opencode service restartfrom a terminal recovered. Seen on 2.3.2; not retested on 2.4.1. - No retry, no signal. If
-lalso times out, the session and the service still run on the minimal PATH with only a log line. A background retry applied before the next service start, or a UI warning, would close this. -lis a partial environment for anyone who sets PATH in.zshrc. Better than nothing, but still silent.
For what it's worth, the -l fallback alone would have fixed my case: from a launchd-like environment zsh -il -c 'env -0' takes ~1.1 s idle and zsh -l -c 'env -0' takes ~0.05 s, and the login files already set the full PATH.
#62736 now conflicts with dev after #63208, but the same change still applies to the async version.
Workaround until then: opencode service set env PATH "<login PATH>", or OPENCODE_CLAUDE_PATH for the Claude provider only.