Skip to content

fix(auth): actionable error message when Codex refresh token is reused by another client - #5612

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
tymrtn:fix/codex-refresh-token-reused-error-message
Apr 6, 2026
Merged

fix(auth): actionable error message when Codex refresh token is reused by another client#5612
teknium1 merged 1 commit into
NousResearch:mainfrom
tymrtn:fix/codex-refresh-token-reused-error-message

Conversation

@tymrtn

@tymrtn tymrtn commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Problem

When the Codex CLI or VS Code extension refreshes OAuth tokens, the shared refresh token is consumed. If Hermes then tries to refresh using the same (now-stale) token, the OpenAI OAuth endpoint returns `refresh_token_reused`. Hermes currently surfaces this as a generic 401 with advice to check your API key — which is confusing and unhelpful since the account is fine.

Changes

`hermes_cli/auth.py` — detect `refresh_token_reused` specifically in `refresh_codex_oauth_pure()` and raise an `AuthError` with an explanation and recovery steps:

"Codex refresh token was already consumed by another client (e.g. Codex CLI or VS Code extension). Run `codex` in your terminal to generate fresh tokens, then run `hermes login --provider openai-codex` to re-authenticate."

`run_agent.py` — when provider is `openai-codex` and HTTP 401 is received, show Codex-specific recovery steps instead of the generic "is your API key valid?" message.

Why only these cases

The `refresh_token_reused` branch in `auth.py` is gated on the exact error code from the OAuth endpoint. The `run_agent.py` change is gated on `_provider == "openai-codex" and status_code == 401` — all other providers and status codes are unchanged.

Reproduction

  1. Authenticate Hermes with `hermes login --provider openai-codex`
  2. Run `codex` from the terminal (or open VS Code with the Codex extension) — this consumes the shared refresh token
  3. Trigger a Hermes request — previously showed a generic 401; now shows actionable steps

When the Codex CLI (or VS Code extension) consumes a refresh token before
Hermes can use it, Hermes previously surfaced a generic 401 error with no
actionable guidance.

- In `refresh_codex_oauth_pure`: detect `refresh_token_reused` from the
  OAuth endpoint and raise an AuthError explaining the cause and the exact
  steps to recover (run `codex` to refresh, then `hermes login`).
- In `run_agent.py`: when provider is `openai-codex` and HTTP 401 is
  received, show Codex-specific recovery steps instead of the generic
  "check your API key" message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@teknium1
teknium1 merged commit 40527ff into NousResearch:main Apr 6, 2026
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.

2 participants