The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): match the primary error on '401 unauthorized', not any bare 401 token
teknium1e132e69374e2
diff --git a/agent/transports/codex_app_server_session.py b/agent/transports/codex_app_server_session.pyindex d9f759a7fdb..6a340e4abbf 100644--- a/agent/transports/codex_app_server_session.py+++ b/agent/transports/codex_app_server_session.py@@ -12,7 +12,6 @@ from __future__ import annotationsimport contextlibimport loggingimport os-import reimport threadingimport timefrom dataclasses import dataclass, field@@ -128,7 +127,7 @@ _OAUTH_REFRESH_FAILURE_HINTS = (# Generic auth words are authoritative only in the primary error. codex writes# independent ChatGPT plugin prewarm failures ("HTTP 401 Unauthorized") to stderr,# so there they must not mask an unrelated RPC error or timeout (#75167).-_PRIMARY_ONLY_OAUTH_HINTS = ("unauthorized", "oauth", "auth profile")+_PRIMARY_ONLY_OAUTH_HINTS = ("401 unauthorized", "unauthorized", "oauth", "auth profile")_OAUTH_REAUTH_HINT = ("Codex authentication failed — your ChatGPT/Codex login looks expired or invalid. Run `codex login` to refresh, "@@ -140,7 +139,7 @@ def _classify_oauth_failure(primary: str = "", *, stderr: str = "") -> Optional["""Re-auth hint when ``primary`` (the operation's own error) or ``stderr`` proves the codex login is broken."""primary_l = (primary or "").lower()stderr_l = (stderr or "").lower()- if any(n in primary_l for n in _OAUTH_REFRESH_FAILURE_HINTS + _PRIMARY_ONLY_OAUTH_HINTS) or re.search(r"\b401\b", primary_l):+ if any(n in primary_l for n in _OAUTH_REFRESH_FAILURE_HINTS + _PRIMARY_ONLY_OAUTH_HINTS):return _OAUTH_REAUTH_HINTreturn _OAUTH_REAUTH_HINT if any(n in stderr_l for n in _OAUTH_REFRESH_FAILURE_HINTS) else Nonediff --git a/tests/agent/transports/test_codex_app_server_session.py b/tests/agent/transports/test_codex_app_server_session.pyindex 84836092be2..499b45c51a0 100644--- a/tests/agent/transports/test_codex_app_server_session.py+++ b/tests/agent/transports/test_codex_app_server_session.py@@ -953,13 +953,15 @@ class TestClassifyOAuthFailure:("internal error: workspace initialization failed", "ChatGPT plugin prewarm failed: HTTP 401 Unauthorized", False),("", "plugin discovery: oauth handshake returned 401 unauthorized", False),("HTTP 401 Unauthorized", "", True),+ ("request body exceeded limit by 401 bytes", "", False),("internal error", "token refresh failed: invalid_grant", True),],- ids=["plugin-401-stderr-keeps-rpc-error", "plugin-401-stderr-keeps-timeout", "primary-401", "strong-stderr-signal"],+ ids=["plugin-401-stderr-keeps-rpc-error", "plugin-401-stderr-keeps-timeout", "primary-401", "bare-401-token-is-not-auth", "strong-stderr-signal"],)def test_generic_auth_words_count_only_in_primary_error(self, primary, stderr, expected):"""#75167: ambient plugin 401/oauth stderr must not become the re-login hint; the- primary error's own 401 and strong stderr credential signals still do."""+ primary error's own 401 Unauthorized and strong stderr credential signals still do,+ while a bare `401` token in an unrelated primary error does not."""from agent.transports.codex_app_server_session import _classify_oauth_failureassert (_classify_oauth_failure(primary, stderr=stderr) is not None) is expected