Skip to content

The agent that grows with you

fix: goal loop names the Nous auth failure instead of an opaque judge error

teknium11539a1a9dabd
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 8c09d193fda..354636f0796 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -110,6 +110,9 @@ from agent.credential_pool import load_pool
from agent.model_metadata import MINIMUM_CONTEXT_LENGTH, get_model_context_length
from hermes_cli.config import get_hermes_home
from agent.auxiliary_health import _custom_health_base_url, _unhealthy_cache_key
+from agent.auxiliary_unavailable import (
+ AuxiliaryClientUnavailable, clear_nous_credential_failure, nous_credential_failure_detail,
+ record_nous_credential_failure)
from hermes_constants import OPENROUTER_BASE_URL, hermes_home_key
from utils import base_url_host_matches, base_url_hostname, base_url_origin, env_float, is_truthy_value, model_forces_max_completion_tokens, normalize_proxy_env_vars
@@ -1966,8 +1969,11 @@ def _resolve_nous_runtime_api(
stale_access_token=stale_access_token or None,
)
except Exception as exc:
- logger.debug("Auxiliary Nous runtime credential resolution failed: %s", exc)
+ # Kept at WARNING (once per message) and remembered: the ladder falls back silently, and
+ # without this the goal judge only ever saw "judge error: RuntimeError" (#42177).
+ record_nous_credential_failure(exc)
return None
+ clear_nous_credential_failure()
return _creds_pair(creds)
@@ -6896,10 +6902,11 @@ def _resolve_call_client(
fb_client, fb_model, fb_label = _try_configured_fallback_for_unavailable_client(
task, _explicit)
if fb_client is None:
- raise RuntimeError(
+ nous_detail = nous_credential_failure_detail() if _explicit == "nous" else None
+ raise AuxiliaryClientUnavailable(nous_detail or (
f"Provider '{_explicit}' is set in config.yaml but no API key was found. "
f"Set the {_explicit.upper()}_API_KEY environment variable, or switch to "
- f"a different provider with `hermes model`.")
+ f"a different provider with `hermes model`."))
client, final_model = fb_client, fb_model
if async_mode:
client, final_model = _to_async_client(
@@ -6915,8 +6922,8 @@ def _resolve_call_client(
"auto", async_mode=async_mode, main_runtime=main_runtime, task=task)
effective_provider = _effective_provider_for_client(client, "auto")
if client is None:
- raise RuntimeError(f"No LLM provider configured for task={task} "
- f"provider={resolved_provider}. Run: hermes setup")
+ raise AuxiliaryClientUnavailable(f"No LLM provider configured for task={task} "
+ f"provider={resolved_provider}. Run: hermes setup")
return _ResolvedAuxRoute(client, final_model, resolved_provider, effective_provider)
diff --git a/agent/auxiliary_unavailable.py b/agent/auxiliary_unavailable.py
new file mode 100644
index 00000000000..9455f2dc55b
--- /dev/null
+++ b/agent/auxiliary_unavailable.py
@@ -0,0 +1,74 @@
+"""Why an auxiliary client could not be built — and the Nous credential failure behind it.
+
+``_resolve_nous_runtime_api`` must swallow the resolver's ``AuthError`` and return None so the
+ladder can still fall back (stored token, fallback_chain). Swallowing it at DEBUG left the goal
+loop reporting ``judge error: RuntimeError`` while the real cause was an ``invalid_grant`` refresh
+(#42177). This module remembers the latest failure so the ladder's raise and the goal judge can
+name it, and warns ONCE per distinct message so operators see it without debug logging.
+"""
+
+import contextlib
+import logging
+import threading
+from typing import Optional
+
+logger = logging.getLogger(__name__)
+
+
+class AuxiliaryClientUnavailable(RuntimeError):
+ """No auxiliary client could be built for the task (missing credentials / provider)."""
+
+
+_lock = threading.Lock()
+_last_nous_detail: Optional[str] = None
+_warned_nous_details: set[str] = set()
+
+
+def _quarantined_nous_error(exc: BaseException) -> BaseException:
+ """Prefer the persisted terminal quarantine marker over *exc*.
+
+ The pool rung swallows the real ``invalid_grant`` and wipes the dead tokens, so by the time the
+ auth-store resolver runs it can only say "No access token found"; the marker it wrote still
+ carries the message and code the user needs (#42177).
+ """
+ from hermes_cli.auth import AuthError, get_provider_auth_state
+ from hermes_cli.auth_nous import _terminal_quarantine_marker
+
+ with contextlib.suppress(Exception):
+ marker = _terminal_quarantine_marker(get_provider_auth_state("nous") or {})
+ if marker and marker.get("message"):
+ return AuthError(str(marker["message"]).rstrip(".") + ".", provider="nous", code=marker.get("code"),
+ relogin_required=True)
+ return exc
+
+
+def record_nous_credential_failure(exc: BaseException) -> str:
+ """Remember *exc* as the latest Nous credential failure; WARN the first time each message is seen."""
+ from hermes_cli.auth import format_auth_error
+
+ exc = _quarantined_nous_error(exc)
+ message = format_auth_error(exc) if isinstance(exc, Exception) else str(exc)
+ code = getattr(exc, "code", None)
+ if code and str(code) not in message:
+ message = f"{message} (code: {code})"
+ detail = f"Nous Portal runtime credentials unavailable: {message.strip() or type(exc).__name__}"
+ global _last_nous_detail
+ with _lock:
+ _last_nous_detail = detail
+ first_time = detail not in _warned_nous_details
+ _warned_nous_details.add(detail)
+ if first_time:
+ logger.warning("Auxiliary Nous client unavailable: %s", detail)
+ return detail
+
+
+def clear_nous_credential_failure() -> None:
+ global _last_nous_detail
+ with _lock:
+ _last_nous_detail = None
+
+
+def nous_credential_failure_detail() -> Optional[str]:
+ """The latest recorded Nous credential failure, or None when the last resolution succeeded."""
+ with _lock:
+ return _last_nous_detail
diff --git a/hermes_cli/goals.py b/hermes_cli/goals.py
index 176e4cf0a85..361f5f201df 100644
--- a/hermes_cli/goals.py
+++ b/hermes_cli/goals.py
@@ -886,6 +886,7 @@ def judge_goal(
try:
from agent.auxiliary_client import call_llm
+ from agent.auxiliary_unavailable import AuxiliaryClientUnavailable
except Exception as exc:
logger.debug("goal judge: auxiliary client import failed: %s", exc)
return "continue", "auxiliary client unavailable", False, None, False
@@ -913,6 +914,11 @@ def judge_goal(
try:
raw = _call_goal_judge_llm(call_llm, JUDGE_SYSTEM_PROMPT, prompt, timeout)
+ except AuxiliaryClientUnavailable as exc:
+ # No client at all (e.g. a dead Nous refresh token): name the cause so the user is sent to
+ # re-authenticate, not to context-length / model debugging (#42177). Still fails open.
+ logger.info("goal judge: auxiliary client unavailable (%s) — falling through to continue", exc)
+ return "continue", f"goal_judge auxiliary client unavailable: {exc}", False, None, True
except Exception as exc:
logger.info("goal judge: API call failed (%s) — falling through to continue", exc)
return "continue", f"judge error: {type(exc).__name__}", False, None, True
diff --git a/tests/agent/test_auxiliary_unavailable_nous_reason.py b/tests/agent/test_auxiliary_unavailable_nous_reason.py
new file mode 100644
index 00000000000..cd3042a1c99
--- /dev/null
+++ b/tests/agent/test_auxiliary_unavailable_nous_reason.py
@@ -0,0 +1,50 @@
+"""The goal judge names a Nous auxiliary auth failure instead of an opaque judge error (#42177).
+
+``_resolve_nous_runtime_api`` swallows the Nous resolver's ``AuthError`` so the ladder can fall
+back; the failure must still reach the operator (one WARNING) and the goal-loop status line.
+"""
+import logging
+
+import yaml
+
+import agent.auxiliary_unavailable as unavailable
+from hermes_cli.auth_constants import AuthError
+
+
+def _reset(monkeypatch):
+ monkeypatch.setattr(unavailable, "_last_nous_detail", None)
+ monkeypatch.setattr(unavailable, "_warned_nous_details", set())
+
+
+def test_goal_judge_reason_names_nous_auth_failure_and_still_fails_open(tmp_path, monkeypatch):
+ """Real judge_goal → call_llm → ladder with goal_judge pinned to nous and no Nous login."""
+ _reset(monkeypatch)
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ (tmp_path / "config.yaml").write_text(yaml.safe_dump({
+ "model": {"provider": "nous", "default": "test-model"},
+ "auxiliary": {"goal_judge": {"provider": "nous", "model": "test-model"}},
+ }), encoding="utf-8")
+ from hermes_cli.goals import judge_goal
+
+ verdict, reason, parse_failed, wait_directive, judge_errored = judge_goal(
+ "ship the fix", "edited the file and ran the tests", timeout=5)
+
+ assert (verdict, parse_failed, wait_directive, judge_errored) == ("continue", False, None, True)
+ assert reason.startswith("goal_judge auxiliary client unavailable: Nous Portal runtime credentials unavailable:")
+ assert "hermes model" in reason, reason
+ assert "judge error" not in reason
+
+
+def test_nous_credential_failure_is_remembered_and_warned_once(caplog, monkeypatch):
+ _reset(monkeypatch)
+ exc = AuthError("Invalid refresh token", provider="nous", code="invalid_grant", relogin_required=True)
+ with caplog.at_level(logging.WARNING, logger="agent.auxiliary_unavailable"):
+ detail = unavailable.record_nous_credential_failure(exc)
+ unavailable.record_nous_credential_failure(exc)
+
+ assert detail == ("Nous Portal runtime credentials unavailable: Invalid refresh token "
+ "Run `hermes model` to re-authenticate. (code: invalid_grant)")
+ assert unavailable.nous_credential_failure_detail() == detail
+ assert sum(detail in rec.getMessage() for rec in caplog.records) == 1
+ unavailable.clear_nous_credential_failure()
+ assert unavailable.nous_credential_failure_detail() is None