Skip to content

fix(mac): adapt app discovery & lifecycle to the Codex → ChatGPT.app merge - #51

Merged
Cmochance merged 4 commits into
mainfrom
fix/chatgpt-app-discovery
Jul 11, 2026
Merged

fix(mac): adapt app discovery & lifecycle to the Codex → ChatGPT.app merge#51
Cmochance merged 4 commits into
mainfrom
fix/chatgpt-app-discovery

Conversation

@Cmochance

Copy link
Copy Markdown
Owner

Summary

OpenAI folded the Codex desktop app into ChatGPT.app (bundle id still com.openai.codex, executable ChatGPT, CLI at Contents/Resources/codex). This app only probed Codex.app / pgrep -x Codex, so on merged installs:

  1. auto-detect / login / app-server fallback reported REAL_CODEX_NOT_FOUND with a healthy install, and
  2. profile switch skipped quitting the running desktop host, leaving its in-memory app-server on the old account (cross-contamination vector).

Changes (3 commits)

  1. Merge adaptation — discovery prefers ChatGPT.app with legacy Codex.app fallback; is-running / activate / open / quit key off the stable bundle id; new live_chatgpt_merge_check example for on-machine e2e probing.
  2. Review hardening (local multi-agent adaptive-review, 5 HIGH / 6 MEDIUM fixed):
    • polite AppleScript quit is fired without waiting — a quit-confirmation dialog or first-run Automation/TCC consent prompt can no longer hang the switch for minutes; TERM goes out immediately (pre-merge worst-case latency restored)
    • process-name signalling now resolves PIDs and verifies each one's bundle CFBundleIdentifier == com.openai.codex before trusting/killing — the consumer ChatGPT chat client (com.openai.chat, executable also named ChatGPT) is never killed as collateral; unverifiable PIDs fail safe
    • shell twin aligned with Rust is-running semantics (definitive osascript false is authoritative); osascript degradation logged once
    • open exit statuses are checked (spawn-and-forget hid app-not-found), display-name last resort restored, Rust/shell/CHANGELOG aligned on name-major candidate order, open/reopen candidates must embed the codex CLI
    • shell reopen chain can no longer abort the script via set -e after a completed switch; warns instead
    • comment corrections (host is not Electron; TERM/KILL timing per call site)
  3. Test round — new test pins PATH-walk-beats-app-bundle ordering end-to-end with a concrete fixture; live probe reports pgrep failures as SKIP instead of silently disarming its own cross-check.

Verification

  • cargo test --lib: 129 passed / 0 failed (10 new/updated cases)
  • cargo run --example live_chatgpt_merge_check on a merged install: 6/6 PASS, 0 failures (real /Applications/ChatGPT.app, codex-cli 0.144.0-alpha.4)
  • Bundle facts verified on-machine: CFBundleIdentifier=com.openai.codex, CFBundleExecutable=ChatGPT, CFBundleAlternateNames=["Codex"]
  • Shell: bash -n + function-level live test (definitive-false path, PID verification pipeline proven against a live process)

macOS-only; the Windows Store host needs a separate pass if it also renamed.

🤖 Generated with Claude Code

OpenAI now ships Codex inside ChatGPT.app (bundle id still
com.openai.codex, process name ChatGPT, CLI at Contents/Resources/codex).
Discovery, is-running, activate, open and quit previously keyed off
Codex.app / pgrep -x Codex only, so a healthy merged install reported
REAL_CODEX_NOT_FOUND and profile switch skipped quitting the running
desktop host. Prefer ChatGPT.app with legacy Codex.app fallback, key
lifecycle off the stable bundle id, and add a live e2e probe example.
…review

Fixes from the adaptive-review pass (5 HIGH / 6 MEDIUM):
- quit: fire the polite AppleScript quit without waiting (a
  quit-confirmation dialog or first-run Automation/TCC consent prompt
  could block the switch thread for minutes) and TERM immediately,
  restoring the pre-merge worst-case latency
- signalling: resolve PIDs via pgrep and verify each one's bundle
  CFBundleIdentifier == com.openai.codex before trusting or killing it,
  so the consumer ChatGPT chat client (com.openai.chat, executable also
  named ChatGPT) is never killed as collateral; unverifiable PIDs fail
  safe (quit times out and aborts the switch instead)
- is-running: shell twin now matches Rust semantics — a definitive
  osascript false is authoritative, process names only probed when
  osascript is unavailable; degradation is logged once
- open: verify each open exit status (open reports app-not-found after
  a successful spawn), add the display-name last resort the comment
  promised, and align Rust/shell/CHANGELOG on name-major candidate
  order (ChatGPT.app wins across both Applications dirs); open/reopen
  candidates must embed the codex CLI so a chat-only ChatGPT.app is
  never selected
- shell reopen: a fully failed open chain no longer aborts the script
  via set -e after the switch already succeeded — it warns instead
- comments: drop the incorrect Electron/renderer architecture claims,
  describe TERM/KILL timing per call site, distinguish the two
  APP_EXIT_FAILED causes
…-reporting

- new discover_real_codex_cli_path_prefers_path_walk_over_app_bundle
  test asserts against a concrete PATH fixture (not recomputed via
  codex_app_candidates), so a discovery block-ordering regression goes
  red on any machine, including ones with a real /Applications install
- live e2e probe: pgrep spawn failures are reported as SKIP with their
  own counter instead of being folded into "not running" (which
  silently disarmed the [1] cross-check); probe-dir cleanup failures
  now warn instead of vanishing
@Cmochance

Copy link
Copy Markdown
Owner Author

手动测试清单(本地 .app 已构建,open dist/codex_switch.app)

前置:本机为已合并安装(/Applications/ChatGPT.app,bundle id com.openai.codex)。

  1. 发现:Settings → Codex CLI path → Auto-detect,应命中 /Applications/ChatGPT.app/Contents/Resources/codex 并带版本号
  2. is-running + quit(核心):打开 ChatGPT.app → 在 codex_switch 里切换 profile → ChatGPT 应被退出、切换完成后自动重启,前端全程不卡(此前 TCC 弹窗/退出确认可能挂起数分钟)
  3. 首次 Automation 授权:若弹出「codex_switch 想要控制 ChatGPT」,允许/拒绝都不应卡住切换(拒绝时走 PID 信号路径)
  4. open/activate:主界面 Open Codex 按钮 → ChatGPT.app 打开或前置激活
  5. 切换后账号正确性:切换 A→B 后,在 ChatGPT.app 里确认登录账号确实是 B(串号回归验证)
  6. (可选)cargo run --manifest-path src-tauri/Cargo.toml --example live_chatgpt_merge_check → 预期 0 failure(s), 0 skipped check(s)

注意:legacy Codex.app + 消费级 ChatGPT 并存、以及旧 chat-only ChatGPT.app 的场景本机无法覆盖,代码路径靠单测 + PID 归属校验兜底。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6d384cb05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/mac/runtime/process.rs Outdated
Comment thread src-tauri/mac/runtime/process.rs
Comment thread src-tauri/mac/runtime/process.rs Outdated
- drop the ambiguous `open -a ChatGPT` last resort (Rust + shell):
  LaunchServices could resolve the bare name to the consumer chat
  client (com.openai.chat) and report "opened Codex" for an unrelated
  app; the unambiguous legacy `Codex` alternate name stays
- classify name-matched PIDs as ours/other/unknown instead of a binary
  verified/skip: POSIX only guarantees `ps -o comm=` returns a command
  name, so an unverifiable PID now still counts for is-running (the
  switch aborts instead of proceeding over a possibly-live host) while
  remaining excluded from TERM/KILL
- keep the detached osascript quit's child handle and cancel it on
  every quit exit path: an Apple event still queued behind the TCC
  consent prompt would otherwise be delivered to — and close — the
  relaunched host once consent is granted later
@Cmochance
Cmochance merged commit 6751dd3 into main Jul 11, 2026
3 checks passed
@Cmochance
Cmochance deleted the fix/chatgpt-app-discovery branch July 11, 2026 00:54
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.

1 participant