fix(pm2): 避免 Homebrew keg-only Node 被误判为 nvm 版本导致 daemon 无法启动 - #737
Merged
deepcoldy merged 1 commit intoAug 7, 2026
Merged
Conversation
pm2 (>=6, lib/Common.js) treats any interpreter path containing the
substring `node@` as an nvm version handle and runs `nvm install <suffix>`.
When botmux is installed under a Homebrew keg-only Node, process.execPath is
e.g. /home/linuxbrew/.linuxbrew/Cellar/node@22/22.23.1/bin/node, so pm2
misreads it as version "22/22.23.1/bin/node" and every `botmux start`/
`restart` fails with:
[PM2] Installing Node v22/22.23.1/bin/node
Version '22/22.23.1/bin/node' not found
The keg-only formula has no `@`-free path to hand pm2 (Cellar/, opt/, and a
non-default bin/ symlink all contain `node@`), so instead of pointing at a
different binary we materialize a stable `@`-free symlink under ~/.botmux
(node-interpreter) that resolves to the exact same Node, and pass that as the
pm2 interpreter. The symlink is refreshed when execPath changes (e.g. a
Homebrew patch bump) and we fall back to the raw execPath on any fs error.
Non-Homebrew installs are unaffected — execPath is returned verbatim.
Co-authored-by: TRAE CLI <noreply@bytedance.com>
Owner
|
PR准备好的话记得点:Ready for review |
BoYanZh
marked this pull request as ready for review
August 7, 2026 05:10
deepcoldy
approved these changes
Aug 7, 2026
deepcoldy
left a comment
Owner
There was a problem hiding this comment.
代码复核通过:pm2 keg-only node@ 误判 nvm 的修复定位准确,软链方案版本一致且 fallback 保守,影响面限于 pm2 启动层。合并态 build + test 绿,隔离环境真跑 pm2 验证 dashboard online。合并时用中文标题+正文。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pm2(>=6, lib/Common.js)会把任何包含子串
node@的 interpreter 路径当作 nvm 版本句柄,尝试nvm install <后缀>。当 botmux 装在 Homebrew keg-only Node 下时,process.execPath 形如/home/linuxbrew/.linuxbrew/Cellar/node@22/22.23.1/bin/node,pm2 会把它误读成版本号22/22.23.1/bin/node,于是每次botmux start/restart都失败:keg-only formula 没有不带
@的可用路径可交给 pm2(Cellar/、opt/、以及非默认的 bin/ 软链都含node@)。因此本 PR 不改指向别的二进制,而是在 ~/.botmux 下物化一条不带@的稳定软链(node-interpreter),它解析到的仍是启动本 CLI 的同一个 Node(版本一致 → node-pty 等原生模块照常),再把这条软链作为 pm2 interpreter 传入。execPath 变化时(如 Homebrew 补丁升级)软链会刷新,任何 fs 错误则回退到原始 execPath。非 Homebrew 安装不受影响 —— execPath 原样返回。影响面
仅改 pm2 启动层(src/cli.ts 的 ecosystem 生成)。daemon 每个 bot app 与 dashboard 共用同一安全 interpreter,start/restart/start-bot 三条生成 ecosystem 的路径均覆盖;PTY/Tmux、普通/话题/adopt/restore 会话逻辑及各 CLI 适配器均未改动。Windows 普通路径走 no-op(不触发需权限的 symlink)。
验证
Common.js:470的node@判定 +resolveNodeInterpreter的split('@')[1]取版本,触发链属实。execPath=.../Cellar/node@22/…/bin/node,跑实际 pm2@6.0.14,dashboard 成功 online,ecosystem 与 PM2 jlist 里的 interpreter 都是无node@的~/.botmux/node-interpreter,软链 realpath 回到同一 Node。src/cli.ts+47/-3)pnpm build通过;pnpm test13232 passed / 24 skipped(唯一失败为无关既有 flaky,单文件重跑通过)。