Skip to content

[bugfix] desktop: inherit user shell PATH for Host and gate minimal-PATH launches - #690

Merged
FayeSpica merged 3 commits into
ThinkFlowLab:mainfrom
FayeSpica:fix/desktop-inherit-user-path
Dec 4, 2026
Merged

FayeSpica merged 3 commits into
ThinkFlowLab:mainfrom
FayeSpica:fix/desktop-inherit-user-path

Conversation

@FayeSpica

@FayeSpica FayeSpica commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Resolve the user's POSIX login shell PATH once when starting the desktop Host (apps/desktop/src/environment.mjs, wired in apps/desktop/src/main.mjs), keeping bundled runtime/bin first, deduplicating entries, avoiding literal undefined concatenation, and falling back cleanly on timeout/failure (Windows skips shell probing and normalizes Path/PATH casing).
  • Capture and log the first non-empty line of stderr on non-zero pi probe exits in packages/core/src/opendirector/agent/pi.py so exit-127 missing-interpreter failures are diagnosable in desktop.log.
  • Add three-layer gates to prevent regressions:
    1. Desktop unit and real-shell tests (apps/desktop/tests/environment.test.mjs) verifying Finder-like minimal PATH=/usr/bin:/bin:/usr/sbin:/sbin with a split-directory #!/usr/bin/env CLI fixture.
    2. Packaged POSIX smoke gate (apps/desktop/scripts/smoke.mjs, apps/desktop/scripts/smoke-window.mjs) launching the packaged app under /usr/bin:/bin:/usr/sbin:/sbin with a split-directory pi shebang fixture (-I -B on bundled Python so the sealed macOS .app bundle is not mutated) exported from an isolated user shell profile and asserting /assistant/runtimes/pi/status (ready) and /models.
    3. Python pi runtime test (tests/test_pi_runtime.py) verifying split-directory shebang behavior under minimal vs inherited PATH and stderr warning logging.
  • Record the lesson in docs/development/lessons.md.

Linked issue

No GitHub issue is linked; this addresses an observed macOS 0.1.7 Finder-launch failure where pi (#!/usr/bin/env node) exited 127 because /opt/homebrew/bin was absent from launchd's PATH.

  • Fixes #N or Refs #N is included, or no issue applies

Labels

  • type:bug

  • area:desktop

  • area:agent

  • Labels applied

Test plan

  • Local (ec0d447d64cadf17e90ae26e5b32822b176f3bba):
    • npm test --prefix apps/desktop -> 13 passed, 0 failed, 1 skipped (packaged-host.test.mjs requires OPENDIRECTOR_DESKTOP_RUNTIME).
  • Local (prior identical production code 82aef5965ea63f94e75a8417682f87471924dcba):
    • pytest -v tests/test_pi_runtime.py tests/test_cli_discovery.py -> 71 passed, 0 failed.
    • Live macOS /bin/zsh receipt via resolveHostEnv under PATH=/usr/bin:/bin:/usr/sbin:/sbin -> RESOLVED_HAS_HOMEBREW: true, FIRST_ENTRY: /app/runtime/bin.
  • Left to CI on ec0d447d64cadf17e90ae26e5b32822b176f3bba:
    • Release checks (.github/workflows/ci.yml, including checks / desktop / macos post-smoke codesign --verify --deep --strict, checks / desktop / windows, checks / python, checks / browser, checks / frontend) and Desktop checks (.github/workflows/desktop.yml).
  • Independent AI pre-review:
    • Score: 83/100 (no blocking findings)
    • Reviewed base: 83b142f02f03cf670dab65ebef12772550f550df
    • Reviewed head: ec0d447d64cadf17e90ae26e5b32822b176f3bba
    • Material validation gaps: full packaged Electron build + smoke.mjs + codesign --verify --deep --strict on ec0d447d and Release checks are pending CI.

Evidence that it works

Visual evidence is N/A because this change modifies no UI layout, copy, or visual components; it fixes desktop Host PATH inheritance and backend probe diagnostics.

Non-visual runtime receipts:

  • apps/desktop/tests/environment.test.mjs on ec0d447d64cadf17e90ae26e5b32822b176f3bba: reproduces exit 127 when running a split-directory #!/usr/bin/env od-fake-node CLI under runtimeBin:/usr/bin:/bin:/usr/sbin:/sbin, then verifies resolveHostEnv inherits both directories from the real shell profile with runtimeBin first and exits 0.

  • tests/test_pi_runtime.py::test_shebang_cli_requires_interpreter_on_path_and_logs_stderr: verifies exit 127 + stderr warning logging under /usr/bin:/bin:/usr/sbin:/sbin, and ready + 3 parsed models once the interpreter directory is on PATH.

  • Prior CI run on 82aef596 (identical production code): checks / desktop / macos passed smoke.mjs (including the Finder-minimal PATH + split-directory pi shebang gate), checks / desktop / windows passed, and checks / python passed; ec0d447d adds -I -B to od-smoke-node so bundled Python does not write .pyc files into the sealed .app bundle before codesign --verify --deep --strict.

  • Applicable evidence attached and any visual N/A explained

Provider verification

No real model provider calls were made. All pi runtime tests use local executable doubles.

  • Real-provider calls are described honestly, or none were made

Bilingual UI

No user-facing copy changed.

  • Both locales are updated, or no user-facing copy changed

@FayeSpica FayeSpica added type:bug Something is broken area:agent Agent runtime, assistant chat and tools area:desktop Desktop integration / 桌面集成 labels Dec 4, 2026

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST CHANGES 82aef59 No linked issue supplied

Finder 下从用户 shell 补 PATH 的方向对,bundled runtime 仍排在首位,Windows 不跑 shell probe。上线前希望处理两点:Host 启动前最多串行等待 4 次 × 3 秒;另外 Pi probe 把外部进程首行 stderr 原样写进 desktop.log,截短不会清理敏感内容。两处已标在代码上。

Ran: 走查启动链、fixture 测试和 GitHub 状态;未启动 macOS 应用。作者报告真实 zsh 命中 Homebrew,完整安装包 smoke 仍待 Release。当前 75/100(非批准):范围 3、正确性 2、验证 2、证据 2、简洁性 3。

English: Bound the total startup probe time and sanitize Pi diagnostics before writing them to desktop.log.

Dot,代表 @david6666666。

for (const shell of candidateShells(platform, env)) {
for (const args of [['-ilc', PROBE_COMMAND], ['-lc', PROBE_COMMAND]]) {
try {
const output = await probe(shell, args, env, timeoutMs);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 3 秒是每次 probe 的上限。自定义 shell 和 fallback 各试两种模式,Host 启动前最坏会阻塞约 12 秒。建议共用一个总 deadline,到点直接走原 PATH,并加一个连续超时仍能及时启动的测试。 (Use one total startup deadline.)

output, err = await asyncio.wait_for(process.communicate(), timeout)
if process.returncode:
detail = next((line.strip() for line in err.decode('utf-8', 'replace').splitlines() if line.strip()), '')[:200]
logger.warning('pi probe %s exited with %s%s', args, process.returncode, f': {detail}' if detail else '')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr 是子进程输出,截到 200 字符仍可能把敏感内容写进长期保留的 desktop.log。exit 127 这个场景可以只记录退出码和归类后的「找不到解释器」;其他诊断要写日志前先脱敏。 (Log a classified, sanitized diagnostic.)

@FayeSpica
FayeSpica merged commit 121365f into ThinkFlowLab:main Dec 4, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent runtime, assistant chat and tools area:desktop Desktop integration / 桌面集成 type:bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants