Skip to content

fix(macos): detect Codex desktop by executable path - #2098

Merged
BigPizzaV3 merged 2 commits into
BigPizzaV3:mainfrom
a328153009-droid:codex/macos-chatgpt-process-detection
Sep 9, 2026
Merged

fix(macos): detect Codex desktop by executable path#2098
BigPizzaV3 merged 2 commits into
BigPizzaV3:mainfrom
a328153009-droid:codex/macos-chatgpt-process-detection

Conversation

@a328153009-droid

Copy link
Copy Markdown
Contributor

背景

#2056 已修复重复 Launcher 再次绑定 helper 的主要路径,但 macOS 的运行中 App 探测仍依赖 pgrep -x Codex/ChatGPT。在真实 ChatGPT 桌面版上,这个名称探测可能漏掉主进程,使 stale recovery 把仍在运行的 App 误判为不存在。

改动

  • 改为解析 ps -axo pid=,args= 的主程序可执行路径。
  • 精确识别 CodexCodex DevChatGPTChatGPT Dev
  • 排除 Electron helper、Codex++ 自身,以及只在 shell/open 参数中出现 App 路径的假阳性。
  • debug-port 探测复用同一套主进程判定。

验证

  • macOS 进程解析单测通过。
  • watcher 集成测试 13/13 通过。
  • Apple Silicon 实机冷启动后再次启动 Codex++:Launcher PID 保持不变,57320/57321 仍由同一进程监听,helper /backend/status 返回正常,未改写 live config/auth。

这是 #2056 的补充修复,关联 #2052#2076

@BigPizzaV3 BigPizzaV3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

实现方向基本合理:按完整可执行路径识别 Codex/ChatGPT 主进程,并排除 helper、Codex++ 和 shell/open 参数中的假阳性;新增 macOS 解析单测也覆盖了主要边界。\n\n但当前 PR 没有任何 GitHub CI,测试仅在 macOS 条件下编译,无法确认其他平台构建未受影响,也无法核验 launcher 的真实重复启动/57321 端口场景。请补跑主仓三平台 artifact CI,并附 macOS 冷启动、重复启动和 debug-port 探测结果;通过后再合并。

@a328153009-droid

a328153009-droid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

已补充验证,并追加 9daf00d 修正一个与现有 macOS 重试逻辑不一致的测试预期:macOS 浮动 helper 端口使用 6,000 ms / 200 ms 的重试预算(31 次尝试),其他平台仍为 1 次。测试同时断言绑定失败时不启动 Codex;生产重试行为未改动。

本地 macOS arm64 验证:

  • launcher integration:83 passed。
  • watcher integration:13 passed;本次完整可执行路径解析单测:1 passed。
  • launcher binary tests:10 passed;当前分支 launcher 构建通过。
  • 实際运行当前分支 launcher,配合隔离的 CodexHotfixFixture.app 做了 3 轮冷启动 → debug-port 探测 → 重复启动。每轮 helper /backend/statusok、debug /json 返回有效 Codex target,重复启动退出码为 0,guard/helper 仍由原 launcher 持有,debug 仍由同一个 fixture 进程持有;各轮结束后测试端口释放,无 helper bind 错误。
  • 测试使用独立数据目录和空闲端口;正在使用的真实 57321 listener 在测试前后保持同一 PID。这里的冷启动是原生测试应用 fixture,并非真实 Electron renderer / 对话的端到端验证,也不是在真实 57321 上另起第二个实例。

主仓对应当前 head 的 artifact CI run 已生成,但状态是 action_required,需要维护者批准。我没有主仓 workflow 管理权限,烦请批准该 run。

同一个 9daf00d 的 fork PR build artifacts 已结束,使用仓库原有 workflow,结果如下:

  • Windows:前端测试、TypeScript、前端构建、Rust workspace tests、release 构建和 NSIS 打包全部通过;binaries / installer artifacts 已上传。
  • macOS arm64:release 构建、DMG 打包、bundle 结构验证全部通过;DMG artifact 已上传。
  • macOS x64:release 编译通过(9m22s),但 DMG 打包失败。日志先报告 hdiutil: couldn't eject "disk2" - Resource busy,之后 5 次 convert 均为 Resource temporarily unavailable。没有产出 x64 DMG,不声称三个目标全绿。

Provider PR #2110 的独立分支也在相同的 x64 打包步骤出现同类错误,两个 PR 都未改动 scripts/installer/macos/package-dmg.sh.github/workflows/pr-build.yml。证据定位到镜像卸载/转换阶段,未确定底层占用进程,也没有另跑 main 基线来证明其必然复现;本 PR 不混入独立打包修复。

主仓审批及真实 Electron 端到端验证的边界仍如上所述。没有修改 CI 脚本或取消主仓审批要求。

@BigPizzaV3

Copy link
Copy Markdown
Owner

修复已核实:你把那个在干净 main 上本就失败的 a_busy_floating_helper_port_fails_immediately_without_waiting 改名为按平台重试预算的版本(macOS 31 次 / 其他 1 次),并声明绑定失败时不启动 Codex。我本机在干净 main 上复现了原测试失败(左31/右1),确认你的改法是修正既有基线而非规避。请让三平台 workflow 跑出绿(当前分支尚未有 GitHub check),我即可通过。

@BigPizzaV3 BigPizzaV3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

复审通过。已核实:本地 launcher 集成 83/83 通过(与你声称一致);被你改名的 a_busy_floating_helper_port_respects_the_platform_retry_budget 恰恰是干净 main 上本就失败(左31/右1)的测试——你的改法是按 macOS 6s/200ms 重试预算修正既有基线,而非规避;含绑定失败不启动 Codex 的断言。与最新 main 三-way merge 无冲突。之前我担心的‘macOS 浮动端口行为’已由实机三轮冷启动验证覆盖。予以合并。

@BigPizzaV3
BigPizzaV3 merged commit 48ac5f7 into BigPizzaV3:main Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants