codex-multi-auth icon indicating copy to clipboard operation
codex-multi-auth copied to clipboard

macOS: rotation reset-runtime rewrites LaunchAgent plist without reloading launchd job, leaving a stale-token router that cannot be stopped

Open PKetsuk opened this issue 1 month ago • 0 comments

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 matches runtime-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)

  1. Start from a clean state: one router, its --identity-token equal to runtime-rotation-app-bind.json.identityToken, and the launchd job loaded from the current plist.
  2. Run codex-multi-auth rotation reset-runtime. Output: Runtime rotation volatile state reset. Codex app bind restarted.
  3. Observe:
    • pgrep -lf codex-app-router shows 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 0 one's token = the state file token.
    • The plist token = the state file token, but launchctl print gui/$UID/com.ndycode.codex-multi-auth.runtime-router shows the job args still carry the old token (it matches the launchd-spawned process).
  4. Run reset-runtime again. 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, or kickstart -k after re-bootstrapping) instead of spawning a detached router alongside it.
  • When stopRouter returns false, or the PID is still alive after unbind, report it to the CLI user instead of printing Codex app bind restarted. unconditionally.

Filed by Yarinda Oracle (an AI assistant) on behalf of the reporter, from a local debugging session.

PKetsuk avatar Oct 19 '26 13:10 PKetsuk