macOS: rotation reset-runtime rewrites LaunchAgent plist without reloading launchd job, leaving a stale-token router that cannot be stopped
Summary
On macOS, codex-multi-auth rotation reset-runtime rewrites the LaunchAgent plist (~/Library/LaunchAgents/com.ndycode.codex-multi-auth.runtime-router.plist) with a new --identity-token, but it does not reload the job in launchd. Because the job has KeepAlive=true, launchd respawns the router it has loaded in memory, and that copy carries the previous token. The command still prints Codex app bind restarted.
You end up with two routers:
- The launchd-respawned router. It holds the configured port and has a stale identity token.
- A second router spawned by reset-runtime. It starts with
--port 0, gets an ephemeral port, and its token matchesruntime-rotation-app-bind.json.
On the next reset or unbind, stopRuntimeRotationRouterProcess rejects the stale-token router (identity mismatch), so the router cannot be stopped. The rejection is logged only through options.log (app-bind.js ~L1235), so the CLI user sees no warning.
Environment
- codex-multi-auth 2.23.0 (upgraded from 2.19.0 via
npm install -g) - macOS (Darwin 27.0.0), Node 26.3.1, router run by LaunchAgent with
RunAtLoad+KeepAlive
Reproduction (observed twice, 2026-10-19)
- Start from a clean state: one router, its
--identity-tokenequal toruntime-rotation-app-bind.json.identityToken, and the launchd job loaded from the current plist. - Run
codex-multi-auth rotation reset-runtime. Output:Runtime rotation volatile state reset. Codex app bind restarted. - Observe:
pgrep -lf codex-app-routershows two routers: one parented by launchd (ppid 1) on the configured port, and one with--port 0.- The launchd one's
--identity-token≠ the state file token. The--port 0one's token = the state file token. - The plist token = the state file token, but
launchctl print gui/$UID/com.ndycode.codex-multi-auth.runtime-routershows the job args still carry the old token (it matches the launchd-spawned process).
- Run
reset-runtimeagain. The launchd router is not stopped (identity check fails), and the pattern repeats.
On the second run, the state file, plist and ~/.codex/config.toml base_url were also rewritten to the ephemeral port of the --port 0 router. The launchd router kept listening on the old port until the job was reloaded.
Workaround
launchctl bootout gui/$UID/com.ndycode.codex-multi-auth.runtime-router
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.ndycode.codex-multi-auth.runtime-router.plist
kill <pid of the --port 0 router>
After this, one router runs, its token matches the state file, and check accounts passes.
Suggested fix
- When the plist is rewritten on darwin, reload the job (
launchctl bootout+bootstrap, orkickstart -kafter re-bootstrapping) instead of spawning a detached router alongside it. - When
stopRouterreturns false, or the PID is still alive after unbind, report it to the CLI user instead of printingCodex app bind restarted.unconditionally.
Filed by Yarinda Oracle (an AI assistant) on behalf of the reporter, from a local debugging session.