Repository navigation
[bugfix] desktop: inherit user shell PATH for Host and gate minimal-PATH launches - #690
Conversation
david6666666
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
这里的 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 '') |
There was a problem hiding this comment.
stderr 是子进程输出,截到 200 字符仍可能把敏感内容写进长期保留的 desktop.log。exit 127 这个场景可以只记录退出码和归类后的「找不到解释器」;其他诊断要写日志前先脱敏。 (Log a classified, sanitized diagnostic.)
Summary
PATHonce when starting the desktop Host (apps/desktop/src/environment.mjs, wired inapps/desktop/src/main.mjs), keeping bundledruntime/binfirst, deduplicating entries, avoiding literalundefinedconcatenation, and falling back cleanly on timeout/failure (Windows skips shell probing and normalizesPath/PATHcasing).stderron non-zeropiprobe exits inpackages/core/src/opendirector/agent/pi.pyso exit-127 missing-interpreter failures are diagnosable indesktop.log.apps/desktop/tests/environment.test.mjs) verifying Finder-like minimalPATH=/usr/bin:/bin:/usr/sbin:/sbinwith a split-directory#!/usr/bin/envCLI fixture.apps/desktop/scripts/smoke.mjs,apps/desktop/scripts/smoke-window.mjs) launching the packaged app under/usr/bin:/bin:/usr/sbin:/sbinwith a split-directorypishebang fixture (-I -Bon bundled Python so the sealed macOS.appbundle is not mutated) exported from an isolated user shell profile and asserting/assistant/runtimes/pi/status(ready) and/models.piruntime test (tests/test_pi_runtime.py) verifying split-directory shebang behavior under minimal vs inheritedPATHandstderrwarning logging.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/binwas absent fromlaunchd'sPATH.Fixes #NorRefs #Nis included, or no issue appliesLabels
type:bugarea:desktoparea:agentLabels applied
Test plan
ec0d447d64cadf17e90ae26e5b32822b176f3bba):npm test --prefix apps/desktop-> 13 passed, 0 failed, 1 skipped (packaged-host.test.mjsrequiresOPENDIRECTOR_DESKTOP_RUNTIME).82aef5965ea63f94e75a8417682f87471924dcba):pytest -v tests/test_pi_runtime.py tests/test_cli_discovery.py-> 71 passed, 0 failed./bin/zshreceipt viaresolveHostEnvunderPATH=/usr/bin:/bin:/usr/sbin:/sbin->RESOLVED_HAS_HOMEBREW: true,FIRST_ENTRY: /app/runtime/bin.ec0d447d64cadf17e90ae26e5b32822b176f3bba:Release checks(.github/workflows/ci.yml, includingchecks / desktop / macospost-smokecodesign --verify --deep --strict,checks / desktop / windows,checks / python,checks / browser,checks / frontend) andDesktop checks(.github/workflows/desktop.yml).83b142f02f03cf670dab65ebef12772550f550dfec0d447d64cadf17e90ae26e5b32822b176f3bbasmoke.mjs+codesign --verify --deep --strictonec0d447dandRelease checksare 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
PATHinheritance and backend probe diagnostics.Non-visual runtime receipts:
apps/desktop/tests/environment.test.mjsonec0d447d64cadf17e90ae26e5b32822b176f3bba: reproduces exit127when running a split-directory#!/usr/bin/env od-fake-nodeCLI underruntimeBin:/usr/bin:/bin:/usr/sbin:/sbin, then verifiesresolveHostEnvinherits both directories from the real shell profile withruntimeBinfirst and exits0.tests/test_pi_runtime.py::test_shebang_cli_requires_interpreter_on_path_and_logs_stderr: verifies exit127+stderrwarning logging under/usr/bin:/bin:/usr/sbin:/sbin, andready+ 3 parsed models once the interpreter directory is onPATH.Prior CI run on
82aef596(identical production code):checks / desktop / macospassedsmoke.mjs(including the Finder-minimalPATH+ split-directorypishebang gate),checks / desktop / windowspassed, andchecks / pythonpassed;ec0d447dadds-I -Btood-smoke-nodeso bundled Python does not write.pycfiles into the sealed.appbundle beforecodesign --verify --deep --strict.Applicable evidence attached and any visual N/A explained
Provider verification
No real model provider calls were made. All
piruntime tests use local executable doubles.Bilingual UI
No user-facing copy changed.