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
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
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.

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