Skip to content

fix(agent): improve Codex OAuth 401 error message to cover server-side token invalidation (#65346) - #65396

Open
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-65346
Open

fix(agent): improve Codex OAuth 401 error message to cover server-side token invalidation (#65346)#65396
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-65346

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Problem

OpenAI Codex OAuth tokens are invalidated server-side after ~2.5 days despite a 10-day declared expiration. When Hermes receives HTTP 401 token_invalidated, the error message only says the token 'may have been refreshed by another client (Codex CLI, VS Code)' — this is misleading when the actual cause is server-side invalidation.

Root Cause

The Codex OAuth provider revokes access tokens before their natural expiration. Hermes correctly attempts a credential refresh but the refresh token is also invalidated, making recovery impossible without manual re-authentication. The existing error message did not mention server-side invalidation as a possibility.

Fix

Improved the HTTP 401 error message for Codex OAuth to:

  1. Mention both possible causes (server-side invalidation *or* another client consuming the token)
  2. Add an explicit To fix: label
  3. Use the more targeted hermes auth openai-codex re-auth command

Closes #65346

Testing

  • Syntax check of changed file passed (python -m py_compile agent/conversation_loop.py)
  • Change is error-message-only, no logic change

…e token invalidation (NousResearch#65346)

The existing error message told users their Codex OAuth token might have been
'refreshed by another client' but OpenAI Codex also invalidates tokens
server-side (verified: tokens with 10-day declarations fail after ~2.5 days
with 'token_invalidated'). The message now covers both causes and uses the
explicit  command for a more targeted re-auth path.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists needs-repro Bug needs reproduction steps labels Jul 16, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving the misleading Codex OAuth recovery guidance. The current-main handler still emits the older client-refresh-only wording at agent/conversation_loop.py:3894-3897, so the message update remains useful.

Problems

  • agent/conversation_loop.py:3898 changes the instruction to hermes auth openai-codex, but the CLI parser defines openai-codex as the provider argument under hermes auth add (hermes_cli/subcommands/auth.py:18-23). The documented supported form is hermes auth add openai-codex (website/docs/user-guide/skills/bundled/autonomous-ai-agents/autonomous-ai-agents-hermes-agent.md:121).

Suggested changes

  • Replace the new command with hermes auth add openai-codex.
  • Add a focused regression test for this provider-specific 401 guidance path.

Automated hermes-sweeper review.

agent._vprint(f"{agent.log_prefix} To fix:", force=True)
agent._vprint(f"{agent.log_prefix} 1. Run `codex` in your terminal to generate fresh tokens.", force=True)
agent._vprint(f"{agent.log_prefix} 2. Then run `hermes auth` to re-authenticate.", force=True)
agent._vprint(f"{agent.log_prefix} 2. Then run `hermes auth openai-codex` to re-authenticate.", force=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openai-codex is accepted as the provider argument only under hermes auth add (hermes_cli/subcommands/auth.py:18-23). Please use hermes auth add openai-codex; the current command form is not registered.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 16, 2026
@GottZ

GottZ commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Summary

Of the 33 listed PRs, only #65396 directly addresses #65346; its diff improves Codex OAuth 401 guidance but does not change token refresh, persistence, or recovery, so it is the recorded best available yet partial fix. The other 32 PRs cover separate Anthropic, Nous, MiniMax, or diagnostic paths rather than the reported Codex credential lifecycle.

Related pull requests

Duplicates

Anthropic refresh: #2741 and #2968 were superseded by merged #3246. Anthropic login endpoint cluster: #45254, #45339, #45441, #46251, #46769, #47333, #47474, #47765, #48704, #48706, #48957, #49356, #50982, and #53971 substantially overlap, with #51723 as the merged canonical implementation; #47989 and #47992 are rejected endpoint/redirect variants. Anthropic UA cluster: #48580, #48687, and #51948 were superseded by #56263, while #57922 was salvaged into merged #58178. Diagnostics: #55552 overlaps the Anthropic portion of #54221.

Suggested consolidation

Keep #65396 open with a salvage path: correct the re-authentication command to hermes auth add openai-codex and add the focused provider-specific 401 guidance test requested by the contributor review; even then, describe it as a messaging-only partial fix because its diff does not repair the token invalidation or failed refresh reported in #65346. No other listed open PR is a duplicate of #65396: retain #54221, #55552, and #55587 only for their separately documented salvage work, while the closed and merged PRs require no reopening.

Complex graph

flowchart LR
    classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
    classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
    classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
    classDef best stroke-width:3px,stroke:#b45309
    classDef target stroke-width:3px,stroke:#4338ca
    I65346(["issue #65346 (open)"])
    P65396["PR #65396 (open)"]
    P65396 -->|best fix| I65346
    class I65346 open
    class P65396 open
    class P65396 best
    class P65396 target
    click I65346 "https://github.com/NousResearch/hermes-agent/issues/65346"
    click P65396 "https://github.com/NousResearch/hermes-agent/pull/65396"
Loading

Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).

Cross-PR triage: Reviewed 33 pull requests and 15 issues in this complex. Each diff was read against this issue; Assessment working set: 202 kB of PR diffs, 172 kB of issue/PR text, 66 kB of discussion (93 comments), 48 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-repro Bug needs reproduction steps P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI Codex OAuth token repeatedly invalidated after 2–3 days despite later expiration

4 participants