Skip to content

The agent that grows with you

fix: only WARN about an unavailable Nous auxiliary client when a Nous credential actually failed

teknium178756858b784
diff --git a/agent/auxiliary_unavailable.py b/agent/auxiliary_unavailable.py
index 9455f2dc55b..6243ea459b7 100644
--- a/agent/auxiliary_unavailable.py
+++ b/agent/auxiliary_unavailable.py
@@ -25,11 +25,12 @@ _warned_nous_details: set[str] = set()
def _quarantined_nous_error(exc: BaseException) -> BaseException:
- """Prefer the persisted terminal quarantine marker over *exc*.
+ """Prefer the persisted terminal quarantine marker over *exc*; sentence-terminate either message.
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).
+ carries the message and code the user needs (#42177). ``format_auth_error`` appends the
+ remediation sentence with a space, so an unterminated message reads "Invalid refresh token Run …".
"""
from hermes_cli.auth import AuthError, get_provider_auth_state
from hermes_cli.auth_nous import _terminal_quarantine_marker
@@ -37,28 +38,57 @@ def _quarantined_nous_error(exc: BaseException) -> BaseException:
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"),
+ return AuthError(_sentence(marker["message"]), provider="nous", code=marker.get("code"),
relogin_required=True)
+ if isinstance(exc, AuthError):
+ return AuthError(_sentence(exc), provider=exc.provider, code=exc.code,
+ relogin_required=exc.relogin_required, retry_after=exc.retry_after,
+ retryable=exc.retryable)
return exc
+def _sentence(text: object) -> str:
+ return str(text).strip().rstrip(".") + "."
+
+
+def _nous_credential_present(exc: BaseException) -> bool:
+ """True when a Nous credential exists that failed — a coded error (``invalid_grant``, a quarantine
+ marker, ``refresh_failed``) or persisted Nous auth state. The uncoded "not logged into Nous Portal"
+ with no stored state is the normal condition for users who never chose Nous; the auto-route walk
+ hits it on every discovery pass and must not warn (the ladder already logs its own summary).
+ """
+ if getattr(exc, "code", None):
+ return True
+ from hermes_cli.auth import get_provider_auth_state
+
+ with contextlib.suppress(Exception):
+ return bool(get_provider_auth_state("nous"))
+ return False
+
+
def record_nous_credential_failure(exc: BaseException) -> str:
- """Remember *exc* as the latest Nous credential failure; WARN the first time each message is seen."""
+ """Remember *exc* as the latest Nous credential failure.
+
+ Logged once per distinct message: WARNING when a real credential failed, DEBUG when Hermes was
+ simply never logged into Nous.
+ """
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)
+ message = message.strip() or type(exc).__name__
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__}"
+ detail = f"Nous Portal runtime credentials unavailable: {message}"
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)
+ level = logging.WARNING if _nous_credential_present(exc) else logging.DEBUG
+ logger.log(level, "Auxiliary Nous client unavailable: %s", detail)
return detail
diff --git a/tests/agent/test_auxiliary_unavailable_nous_reason.py b/tests/agent/test_auxiliary_unavailable_nous_reason.py
index cd3042a1c99..e305441946e 100644
--- a/tests/agent/test_auxiliary_unavailable_nous_reason.py
+++ b/tests/agent/test_auxiliary_unavailable_nous_reason.py
@@ -42,9 +42,26 @@ def test_nous_credential_failure_is_remembered_and_warned_once(caplog, monkeypat
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 detail.startswith("Nous Portal runtime credentials unavailable: ")
+ assert "invalid_grant" in detail and "Run `hermes model` to re-authenticate." in detail
+ assert "Invalid refresh token. Run" in detail, detail # sentence-terminated before the remediation
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
+
+
+def test_never_logged_in_is_debug_but_a_dead_credential_warns(caplog, monkeypatch, tmp_path):
+ """The auto-route walk resolves Nous on every pass; users who never chose Nous must not be nagged."""
+ _reset(monkeypatch)
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ not_logged_in = AuthError("Hermes is not logged into Nous Portal.", provider="nous", relogin_required=True)
+ dead = AuthError("Invalid refresh token", provider="nous", code="invalid_grant", relogin_required=True)
+ with caplog.at_level(logging.DEBUG, logger="agent.auxiliary_unavailable"):
+ quiet = unavailable.record_nous_credential_failure(not_logged_in)
+ loud = unavailable.record_nous_credential_failure(dead)
+
+ levels = {rec.levelno for rec in caplog.records if quiet in rec.getMessage()}
+ assert levels == {logging.DEBUG}, caplog.records
+ assert {rec.levelno for rec in caplog.records if loud in rec.getMessage()} == {logging.WARNING}
+ assert "hermes model" in quiet # the goal judge still gets the remediation text