The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): a revoked Codex grant names openai-codex, the failing profile and the raw error
teknium16b457953f61c
diff --git a/agent/turn_failure_copy.py b/agent/turn_failure_copy.pyindex 1b1e894d75c..b3307204bad 100644--- a/agent/turn_failure_copy.py+++ b/agent/turn_failure_copy.py@@ -144,10 +144,7 @@ _NONRETRYABLE_DEFAULT_COPY = ("or check the details in `{home}/logs/agent.log`.")_AUTH_COPY: Dict[str, str] = {- "oauth": (- "{label} rejected your sign-in, so the model can't be reached. Sign in again: "- "`hermes portal` for Nous, `hermes auth add <provider> --type oauth` for other accounts."- ),+ "oauth": "{label} rejected your sign-in, so the model can't be reached. Sign in again: `{relogin}`.","api_key": ("{label} rejected your API key, so the model can't be reached. Update it in ""Settings β Providers, or run `hermes setup` in a terminal."@@ -272,6 +269,19 @@ def exhausted_copy(reason: str, *, label: str, attempts: int, summary: str) -> s)+def oauth_relogin_command(provider: Any) -> str:+ """The exact re-login command for a rejected OAuth grant, naming the provider slug and the active+ named profile: a profile's credentials are its own (93889b770da), so a bare ``hermes auth`` from+ the root profile re-signs the wrong store and the goal judge, reading a bare 401, guesses which+ service revoked the token (#114012)."""+ from hermes_constants import profile_cli_selector++ slug = str(provider or "").strip().lower()+ if slug == "nous":+ return f"hermes {profile_cli_selector()}portal"+ return f"hermes {profile_cli_selector()}auth add {slug} --type oauth"++def nonretryable_copy(classified: Any, *, provider: Any, model: Any, summary: str, prefix_suggestion: Optional[str] = None,) -> str:@@ -288,7 +298,8 @@ def nonretryable_copy(f"'{prefix_suggestion}'?"if prefix_suggestion else "")- body = template.format(label=label, model=model, home=display_hermes_home(), prefix_hint=prefix_hint)+ body = template.format(label=label, model=model, home=display_hermes_home(), prefix_hint=prefix_hint,+ relogin=oauth_relogin_command(provider))return f"{body}\n\nProvider said: {summary}"diff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex e0e5451e4a2..e5a912a2246 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -677,12 +677,13 @@ def _print_nonretryable_auth_guidance(returnif provider in {"openai-codex", "xai-oauth", "nous"} and status_code == 401:if provider == "openai-codex":+ from agent.turn_failure_copy import oauth_relogin_command+_vlines(agent," π‘ Codex OAuth token was rejected (HTTP 401). Your token may have been",- " refreshed by another client (Codex CLI, VS Code). To fix:",- " 1. Run `codex` in your terminal to generate fresh tokens.",- " 2. Then run `hermes auth` to re-authenticate.",+ " refreshed by another client (Codex CLI, VS Code) or another Hermes profile.",+ f" Sign this profile in again: `{oauth_relogin_command(provider)}`",)elif provider == "xai-oauth":_vlines(diff --git a/hermes_cli/goals.py b/hermes_cli/goals.pyindex 2047c81c544..878df174fda 100644--- a/hermes_cli/goals.py+++ b/hermes_cli/goals.py@@ -128,7 +128,13 @@ JUDGE_SYSTEM_PROMPT = ("user input to proceed.\n""Return BLOCKED with the reason describing what is blocking. BLOCKED is ""a refusal, not a completion β never return BLOCKED for a goal that "- "was achieved.\n\n"+ "was achieved.\n"+ "When the block is an error the agent hit (an HTTP status, an API, "+ "sign-in or token failure), quote the error text verbatim in the reason "+ "and attribute it only to a provider, service or credential the response "+ "itself names. Never infer one the response does not name β an unnamed "+ "401 belongs to the model provider the agent was calling, not to some "+ "other service's token.\n\n""WAIT β the goal is NOT done, but the next step is to wait for async ""work to finish rather than act again. Choose this ONLY when the agent's ""progress is genuinely gated on something running on its own:\n"diff --git a/tests/agent/test_failed_turn_chat_copy.py b/tests/agent/test_failed_turn_chat_copy.pyindex d99ef570d88..30cda47fbcf 100644--- a/tests/agent/test_failed_turn_chat_copy.py+++ b/tests/agent/test_failed_turn_chat_copy.py@@ -80,6 +80,23 @@ def test_api_key_rejection_chat_text_names_the_fix_and_the_provider_label():assert text.index("hermes setup") < text.index("Provider said:")+def test_oauth_rejection_chat_text_names_the_provider_slug_and_the_failing_profile(tmp_path, monkeypatch):+ """A revoked Codex grant must send the user to THAT profile's own sign-in (profiles are+ islands, 93889b770da) and put the provider slug in the text the goal judge reads (#114012)."""+ profile_home = tmp_path / ".hermes" / "profiles" / "codex"+ profile_home.mkdir(parents=True)+ monkeypatch.setenv("HOME", str(tmp_path))+ monkeypatch.setenv("HERMES_HOME", str(profile_home))+ result = _nonretryable(+ 401, "HTTP 401: Encountered invalidated oauth token for user, failing request (code: token_revoked)",+ provider="openai-codex", model="gpt-5.6-sol",+ )+ text = result["final_response"]+ assert "`hermes -p codex auth add openai-codex --type oauth`" in text+ assert "<provider>" not in text+ assert "token_revoked" in text # the raw error survives for the judge to quote++def test_max_retries_exhausted_chat_text_has_next_step_and_no_mechanism_lead():error = _Http(503, "HTTP 503: upstream unavailable")classified = classify_api_error(error, provider="openrouter", model="m")diff --git a/tests/hermes_cli/test_goals.py b/tests/hermes_cli/test_goals.pyindex 8dbc1b7d19e..7fc8f790b75 100644--- a/tests/hermes_cli/test_goals.py+++ b/tests/hermes_cli/test_goals.py@@ -96,6 +96,23 @@ class TestJudgeGoal:assert verdict == "done"assert reason == "achieved"+ def test_judge_is_told_to_quote_errors_verbatim_and_never_infer_a_service(self):+ """A bare provider 401 in the response must not become 'the GitHub token is invalidated' in+ the block reason (#114012): the system prompt the judge actually receives carries the rule."""+ from hermes_cli import goals++ seen = {}++ def fake_call_llm(*a, **kw):+ seen["messages"] = kw.get("messages") or a+ return MagicMock(choices=[MagicMock(message=MagicMock(content='{"verdict": "blocked", "reason": "x"}'))])++ with patch("agent.auxiliary_client.call_llm", side_effect=fake_call_llm):+ goals.judge_goal("ship it", "HTTP 401: invalidated oauth token (code: token_revoked)")+ system_text = str(seen["messages"])+ assert "quote the error text verbatim" in system_text+ assert "Never infer one the response does not name" in system_text+# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ# GoalManager lifecycle + persistence