Repository navigation
fix: restart the Codex app-server daemon after a credential switch - #105
Merged
Merged
Conversation
Codex CLI 0.157 (2026-09-25) attaches interactive sessions to a shared local app-server daemon. The daemon loads auth.json once and re-reads it only for the account it already holds (the 401 recovery reloads on a matching account id and nothing watches the file), so `use` and `login` replaced the file while every new `codex` session kept the previous account. `use`, the TUI switch, and the login paths that activate credentials now run `codex app-server daemon restart` when the live file changed and `codex app-server daemon version` reports a running daemon. A stopped daemon or an older Codex is left alone, a failed restart is a warning because the switch itself has happened, and re-selecting the profile that is already live skips the restart so a scheduled `use` does not interrupt sessions on every run. `launch` keeps its temporary staging: a ChatGPT launch adds `--no-daemon` when the installed Codex lists it, so the launched session reads the staged file instead of joining the daemon. An argv that already picks `--no-daemon`, `--remote`, or `agents` is passed through unchanged.
xjoker
added a commit
that referenced
this pull request
Sep 30, 2026
fix: restart the Codex app-server daemon after a credential switch
Owner
|
Thanks for the thorough fix and write-up! Merged into I added a follow-up on top (815a2e8):
Full |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Codex CLI 0.157 (released 2026-09-25, "automatic background-server startup for eligible interactive sessions") attaches every interactive
codexsession to a shared local app-server daemon (codex app-server --listen unix:// --managed-daemon). That daemon builds oneAuthManagerat startup and cachesauth.jsonin memory. Nothing watches the file;reload()runs only after an in-app login, and the 401 recovery path reloads from disk only when the account id matches (reload_if_account_id_matchesincodex-rs/login/src/auth/manager.rs).So after
codex-switch use other, the liveauth.jsonchanges but every newcodexsession still runs on the previous account until the daemon is restarted.codex-switch launchis broken the same way: the launched session joins the daemon and never reads the staged file.codex execandcodex --no-daemonrun in process and are unaffected.Behavior
use <alias>,use(auto-select), the TUIuswitch, and theloginpaths that activate credentials (login,login <alias>re-auth when that profile is current, TUI add/re-login) now runcodex app-server daemon restartafter the live file is written.codex app-server daemon versionreports{"status":"running"}. A stopped daemon or a Codex without thedaemonsubcommand is left alone, becauserestartwould otherwise start a daemon nobody asked for.use) skips the restart, so sessions are not interrupted on every run.--jsonstdout is unchanged (the message goes to stderr).launchkeeps its temporary staging instead of touching the daemon: a ChatGPT launch prepends--no-daemonwhencodex --helplists it (0.156+). An argv that already contains--no-daemon,--remote, oragentsis passed through unchanged. Provider launches are untouched.Boundary and trade-offs
src/app_server.rsowns the probe/restart pair;profile.rsstays free of process spawning. The command and TUI layers call it after each live-auth write.replace_profile_auth_and_live_if_currentnow returns whether the live file was replaced so re-login only restarts when it actually changed the live account.launchnow spawnscodex --helponce before staging (support probe). Launched sessions run embedded, so they do not appear incodex agents.CODEX_HOME, where a 0.157+ Codex may auto-start its own managed daemon per run home. Separate concern; noted for follow-up.Tests
Failing before the fix, passing after:
tests/test_launch_passthrough.rs(fakecodexon PATH records argv):use_restarts_a_running_app_server_daemon,use_leaves_a_stopped_app_server_daemon_alone,use_does_not_restart_the_daemon_when_the_live_auth_is_unchanged,use_reports_a_failed_daemon_restart_without_failing_the_switch,json_use_keeps_the_daemon_report_off_stdout,launch_chatgpt_runs_codex_without_the_shared_daemon_when_supported,launch_chatgpt_keeps_argv_for_a_codex_without_no_daemon,launch_chatgpt_leaves_an_explicit_server_choice_alone.src/app_server.rs(scriptedversion/restartoutputs, exit codes, spawn errors, messages, unchanged-file gate) andsrc/launch.rs(embedded_codex_argv).Verification run (macOS, Rust 1.97.0)
cargo clippy --all-targets -- -D warningsfails on currentdevbefore this change:clippy::question_markatsrc/tui/app.rs:913(provider launch picker) under Rust 1.97. Not touched here.cargo auditis not installed on this machine; not run.codex app-server daemon version→{"status":"running",…}; the TUI processes hold sockets to the daemon and the daemon holds their rollout files), andcodex --no-daemon exec …/codex --no-daemon resume …parse whilecodex exec --no-daemondoes not, which is why the flag is prepended.Docs
Feature-Guide,Command-Reference(automation contract),Configurationunchanged,FAQ,Getting-Started,Troubleshooting(new section with the manual command),Architecture-Overview,Chinese-Guide, andCHANGELOG(Unreleased).