Skip to content

Prompt and gracefully restart Codex during account switches#13

Open
thatdaveguy1 wants to merge 1 commit intoLampese:mainfrom
thatdaveguy1:codex/graceful-codex-restart
Open

Prompt and gracefully restart Codex during account switches#13
thatdaveguy1 wants to merge 1 commit intoLampese:mainfrom
thatdaveguy1:codex/graceful-codex-restart

Conversation

@thatdaveguy1
Copy link
Copy Markdown
Contributor

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

  • add a confirmation prompt in src/App.tsx when Codex appears to be running
  • update the switch flow to pass restart intent to the backend
  • add process capture and graceful restart handling in process.rs
  • update switch orchestration in account.rs to coordinate the stop and restart sequence

Reviewer notes

  • this PR is intentionally limited to switch UX and process lifecycle handling
  • backup security onboarding and storage persistence hardening are handled in separate PRs

Verification

  • cargo check in src-tauri passes on this branch

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>
@thatdaveguy1 thatdaveguy1 force-pushed the codex/graceful-codex-restart branch from d4850ef to 9a2e41d Compare March 6, 2026 21:00
@Lampese
Copy link
Copy Markdown
Owner

Lampese commented Mar 7, 2026

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.

Copy link
Copy Markdown
Owner

@Lampese Lampese left a comment

Choose a reason for hiding this comment

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

Requesting changes for two behavioral issues:

  1. 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 ps command line through detached nohup sh -lc ... & on Unix or start /B on Windows, which drops the original TTY, stdin/stdout, working directory, and shell environment. For an interactive terminal codex session, 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.

  2. The stop flow still returns success after timeout even if processes are still alive, so switch_account can proceed and then launch duplicates. If a foreground Codex process does not exit within the wait window, the code continues, rewrites auth.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.

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