Prompt and gracefully restart Codex during account switches#13
Prompt and gracefully restart Codex during account switches#13thatdaveguy1 wants to merge 1 commit intoLampese:mainfrom
Conversation
Detect running Codex desktop app and CLI processes before switching accounts. If foreground processes are found, prompt the user via a native Tauri dialog and restart Codex after writing the new auth.json. Process detection: - Classify processes as DesktopApp, Cli, or Background using CodexProcessKind - Match the Electron GUI at /MacOS/Codex (capital C), not just lowercase codex - Ignore codex app-server processes (managed by the app bundle, often orphaned) - Never stop background IDE extension processes (Antigravity, VSCode, ChatGPT) Stop/restart logic: - macOS: SIGKILL the GUI PID (Codex ignores AppleScript quit and SIGTERM), poll until /MacOS/Codex is gone, then `open -a Codex` - Windows: taskkill /IM Codex.exe /F, poll, then `start Codex` - CLI processes: SIGTERM with 3s timeout on Unix, taskkill on Windows Frontend: - Use Tauri native `ask()` dialog instead of unreliable `window.confirm()` - Only count foreground processes for the restart prompt (exclude background) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d4850ef to
9a2e41d
Compare
|
Is it really possible to reopen and restore the previous session and work? It seems there's no relevant logic in the code. I designed this feature because switching accounts could have side effects if your Codex is working. |
Lampese
left a comment
There was a problem hiding this comment.
Requesting changes for two behavioral issues:
-
The PR promises to close and reopen running Codex, but the CLI restart path does not actually restore the user's original session. It relaunches the raw
pscommand line through detachednohup sh -lc ... &on Unix orstart /Bon Windows, which drops the original TTY, stdin/stdout, working directory, and shell environment. For an interactive terminalcodexsession, that is not a true restart of the existing session, while the UI prompt currently tells the user that Codex will be closed and reopened. -
The stop flow still returns success after timeout even if processes are still alive, so
switch_accountcan proceed and then launch duplicates. If a foreground Codex process does not exit within the wait window, the code continues, rewritesauth.json, and then restarts from the saved process list anyway. That can leave the old process running while also starting a new one.
I think both issues should be addressed before merging, because they make the restart behavior materially different from what the UI promises.
Why
Account switching currently force-stops Codex-related processes without an explicit user confirmation step. That can be surprising and can interrupt active work more harshly than necessary.
This PR changes the switch flow so users confirm the restart and the backend attempts a graceful close and reopen instead of using an unconditional force-kill path.
What changed
src/App.tsxwhen Codex appears to be runningprocess.rsaccount.rsto coordinate the stop and restart sequenceReviewer notes
Verification
cargo checkinsrc-tauripasses on this branch