Skip to content

[Bug]: native main pool does not refresh expired auth.json tokens #2221

Description

@MarcTCruz

Client or integration

Codex CLI

Area

Authentication and account pool

Summary

When the native Codex __main__ account has an expired access token in ~/.codex/auth.json but still has a valid refresh token, OpenCodex can select that account and forward the expired bearer to /v1/responses. The request returns 401 instead of refreshing the native credential first. Stored account-pool credentials have a refresh path, but the native main credential does not pass through it.

Expected behavior: OpenCodex refreshes the native main credential before upstream I/O. If upstream rejects that bearer once with 401, OpenCodex refreshes and replays the request once with the new bearer.

Reproduction

  1. Use OpenCodex at commit caf20353fa87bf14c5fef078e5d8b0692dd7c92d on the dev branch.
  2. Configure the Codex native main account in ~/.codex/auth.json with an expired access token and a non-empty valid refresh token. Ensure no other account-pool credential is currently usable.
  3. Start the local proxy with ocx start --port 10100.
  4. Send a normal Codex CLI request through http://127.0.0.1:10100/v1/responses.
  5. Observe that the native __main__ account is selected, but its expired access token is forwarded without first using the refresh token.
  6. Observe the 401 response shown below. The request succeeds only after credentials are refreshed outside this native-main request path.

The same missing native credential substitution affects /v1/responses/compact.

Version

caf20353fa87bf14c5fef078e5d8b0692dd7c92d (dev, before PR #2222)

Operating system

Ubuntu 24.04.4 LTS

Provider and model

OpenAI Codex native account; model-independent

Logs or error output

unexpected status 401 Unauthorized: OpenAI account pool has no usable account credential, url: http://127.0.0.1:10100/v1/responses

Screenshots and supporting files

PR #2222 contains focused regression tests for pre-request refresh, one-time 401 recovery, compact routing, refresh-token rotation, and native/stored credential convergence.

Redacted configuration

{
  "native_main": {
    "access_token": "<expired-redacted>",
    "refresh_token": "<valid-redacted>"
  },
  "other_usable_pool_accounts": 0
}

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-poolOAuth, credentials, Codex pool, quota, failover, plansbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions