Skip to content

Refresh Codex tokens without restarting running sessions - #155

Merged
devjiwonchoi merged 2 commits into
mainfrom
jiwon/refresh-codex-auth
Nov 8, 2026
Merged

devjiwonchoi merged 2 commits into
mainfrom
jiwon/refresh-codex-auth

Conversation

@devjiwonchoi

Copy link
Copy Markdown
Owner

Why?

Managed Codex sessions fail with 401 token_expired about an hour after they start. BusyBoy resolves the ChatGPT access token once when a session opens and passes it to the long-lived codex app-server as ACCESS_TOKEN (env_key). The process keeps that token for its whole life, so once it expires every request fails until the user restarts or signs in again. Long-running Codex tasks keep stalling on this.

Upstream T3 Code had the same bug and fixed it in pingdotgg/t3code#21786 and pingdotgg/t3code#21787, a few days after BusyBoy forked.

How?

This ports that fix:

  • The Codex provider now uses command auth: auth={command=<server binary>, args=["__managed-chatgpt-token", <socket>, <instance>, <environment>, <profile key>], refresh_interval_ms=0}. Codex runs it when it gets a 401 and retries the request once with the new token. No token is in Codex's env or argv any more.
  • CodexManagedTokenBroker listens on a private socket (a 0600 Unix socket in a fresh 0700 directory, or a random named pipe on Windows). For each request it calls auth.access, which renews the token with the refresh token when needed, and writes back the token. It drops requests from another environment, and expectedProfileKey refuses them after a different account signs in.
  • __managed-chatgpt-token is a lean CLI fast path in bin.ts that forwards the request to the broker and prints the token.
  • The session revision is the profile key, not the token, so a renewal does not restart the app-server or interrupt a running turn.
  • The model catalog check reads its token from auth.access instead of the env.

Keep refresh-token rotation owned by the server and bind helper requests to the launch profile so expiring sessions can renew safely.
Replace the expiring ACCESS_TOKEN environment with a self-invoked native auth command backed by the private server broker. Keep launch settings and the profile revision stable across refreshes, and fetch catalog tokens directly from auth.
@devjiwonchoi
devjiwonchoi marked this pull request as ready for review November 8, 2026 06:27
@devjiwonchoi
devjiwonchoi merged commit d8dce6b into main Nov 8, 2026
@devjiwonchoi
devjiwonchoi deleted the jiwon/refresh-codex-auth branch November 8, 2026 06:27
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.

1 participant