Repository navigation
Description
Existing issues
- I searched open and closed issues. This is related to [Bug]: Codex doesn't show usage #468, but it requests a change to the 8-day policy that [Bug]: Codex doesn't show usage #468 explicitly left in place.
What happened?
Win-CodexBar rejects otherwise valid Codex CLI OAuth credentials solely because auth.json.last_refresh is older than eight days.
The current provider gate runs before the usage request:
let is_stale = credentials
.last_refresh
.is_none_or(|last| now - last > EXTERNAL_OAUTH_STALENESS_WINDOW);
if is_stale {
return Err(ProviderError::AuthRequired);
}This makes last_refresh act as a token-expiry timestamp even though it only records when the CLI last refreshed the credential set. The same code already parses the access-token JWT exp, which is a more direct validity signal.
Issue #468 contains a concrete reproduction: last_refresh was about 215 hours old, Codex CLI was logged in, and the ChatGPT usage endpoint returned HTTP 200, but Win-CodexBar returned Authentication required. #468 was closed after adding a Refresh login action, with the explicit note that the 8-day gate remained intentional.
The workaround is unsuitable for unattended serve --metrics nodes. It requires periodic interactive login, and #468 also records an organization where device authentication is not allowed.
Expected behavior: an old last_refresh should not by itself make credentials unusable. When JWT expiry is available, use it as the local expiry check. When the token is opaque, allow the read-only usage request and let an actual HTTP 401/403 establish that authentication is invalid.
Affected area
- Tray panel
- Settings UI
- Config file / settings persistence
- CLI
- Provider-specific behavior
- Installer / release packaging
- Startup / background behavior
- Other
Steps to reproduce
- Sign in to Codex CLI using ChatGPT OAuth and keep the resulting native
auth.jsonunchanged for more than eight days. - Confirm that Codex CLI remains usable. If testing the transport directly, confirm the same bearer token can receive HTTP 200 from the ChatGPT usage endpoint without publishing the token.
- Run
codexbar-cli diagnose -p codex --source oauth --pretty, refresh the Codex tray provider, or scrape an enabledserve --metricsendpoint. - Observe
Authentication required/codexbar_provider_up{provider="codex"} 0before Win-CodexBar sends the usage request. - Refresh the Codex login and observe that only the
last_refreshage change is sufficient to make usage work again.
A deterministic regression can construct credentials with last_refresh = now - 10 days and an access-token JWT whose exp is still in the future.
Logs, screenshots, or recordings
Observed provider warning:
Codex API fetch failed: Authentication required
Related reproduction in #468:
- last_refresh approximately 215 hours old
- Codex CLI logged in
- ChatGPT usage endpoint returned HTTP 200
- Win-CodexBar returned Authentication required
App version
v0.56.8 and current main
Windows version
Windows 10/11
Additional context
This is independent of the Prometheus endpoint implementation in #528; /metrics only exposes the existing Codex provider failure.
Suggested behavior and safety boundaries:
- Do not reject credentials only because
last_refreshis older than eight days. - Keep rejecting a JWT that is expired or within the existing refresh window.
- If JWT
expis unavailable but the file has native CLI refresh metadata, make the read-only request and classify an actual 401/403 asAuthentication required. - Preserve fail-closed behavior for unknown external OAuth files that have no
last_refreshmetadata unless the existing opt-in setting allows them. - Do not redeem the refresh token and do not write to the Codex CLI-owned
auth.json.
I validated a local minimal patch with these cases:
- old
last_refreshplus future JWT expiry is accepted; - old
last_refreshplus an opaque token is allowed to reach server validation; - near-expiry JWT is still rejected;
- missing
last_refreshmetadata remains fail-closed; - all 40 Codex API provider tests pass.
Activity