fix(codex): bind-mount host auth.json so refreshed tokens reach future spawns#2534
Open
IamAdamJowett wants to merge 1 commit into
Open
fix(codex): bind-mount host auth.json so refreshed tokens reach future spawns#2534IamAdamJowett wants to merge 1 commit into
IamAdamJowett wants to merge 1 commit into
Conversation
…e spawns Codex previously copied ~/.codex/auth.json into each session at spawn time. ChatGPT OAuth uses single-use rotating refresh tokens — once one session refreshed, the host file went stale and every subsequent codex spawn copied a dead token, failing silently with refresh_token_reused (messages_in marked completed, no outbound row). Bind-mount the file instead so in-place refreshes propagate back to the host. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
What
Changes
src/providers/codex.tsto bind-mount the host's~/.codex/auth.jsondirectly into each container instead of copying it at spawn time. The per-session codex dir is still mounted (forconfig.toml); the auth.json file mount sits on top of it.Why
ChatGPT OAuth uses single-use rotating refresh tokens. With the previous copy-based approach, once any codex session refreshed its token, the host's
auth.jsonwas left untouched — so every subsequent codex spawn copied a dead token and failed withrefresh_token_reused. The failure is silent at the user level:messages_inget markedcompleted, no outbound row is written, and the operator just sees "the agent went quiet."Hit in practice this week — a fresh codex agent spawned ~2.5h after the first one of the day stayed silent through three consecutive operator check-ins. Container logs showed the auth manager retrying
refresh_token_reusedon every poll.How it works
The container sees the same inode as the host. When codex refreshes its access token in-place, the new tokens are written back through the bind mount to the host file, and the next codex spawn picks them up.
The existing per-session codex dir mount is preserved so
config.tomlrewrites stay session-local (the container rewrites this on every wake with container-appropriate MCP server paths). The file mount overlays cleanly on top.If the user hasn't run
codex loginyet (no hostauth.json), the file mount is skipped and codex falls back toOPENAI_API_KEY— same behaviour as before for that case.How it was tested
/proc/mountsinside the container shows both the dir mount and the file mount forauth.jsonstat -c '%i' /home/adam/.codex/auth.jsonvsdocker exec … stat -c '%i' /home/node/.codex/auth.json)refresh_token_reused/token_expiredentries in logsCaveat I haven't been able to verify in a short test: a real token refresh propagating back to the host file requires waiting for the access token to expire (~1h). If codex ever switches to atomic-rename writes for
auth.json, the file bind mount would silently regress to leaving the host file stale. Worth keeping an eye on ifrefresh_token_reusedre-appears.Usage
No user-facing changes. Applies automatically to any agent group using
provider: codex.