Skip to content

The agent that grows with you

fix(providers): a broken missing_credentials_hint never replaces the AuthError

Tekniumee070ebd317a
diff --git a/hermes_cli/runtime_readiness.py b/hermes_cli/runtime_readiness.py
index 9be83f1308e..71ea8fdf29f 100644
--- a/hermes_cli/runtime_readiness.py
+++ b/hermes_cli/runtime_readiness.py
@@ -5,14 +5,32 @@ contract whichever backend it reached: ``ok``/``provider``/``model``/``source``,
failure (naming the configured pin, never the fallback chain's tail), ``free_tier_route`` on success.
"""
+import logging
+
+logger = logging.getLogger(__name__)
+
def missing_credentials_suffix(provider) -> str:
"""``" <hint>"`` from *provider*'s profile (``ProviderProfile.missing_credentials_hint``) for a
- "No usable credentials found" message, else ``""``."""
+ "No usable credentials found" message, else ``""``. Plugin boundary: a raising hook (or a plugin
+ host that is down) or a non-string answer yields ``""`` and is logged once per provider, so the
+ AuthError it decorates (and the fallback chain walking on it) is never replaced."""
from providers import get_provider_profile
- profile = get_provider_profile(str(provider or "").strip().lower()) if provider else None
- hint = profile.missing_credentials_hint() if profile is not None else None
- return f" {hint.strip()}" if hint and hint.strip() else ""
+ name = str(provider or "").strip().lower()
+ profile = get_provider_profile(name) if name else None
+ if profile is None:
+ return ""
+ try:
+ hint = profile.missing_credentials_hint()
+ except Exception: # health: allow BLE001 -- plugin hook boundary; logged with traceback once below
+ if name not in _HINT_FAILURES_LOGGED:
+ _HINT_FAILURES_LOGGED.add(name)
+ logger.warning("%s missing_credentials_hint failed; showing the error without it", name, exc_info=True)
+ return ""
+ return f" {hint.strip()}" if isinstance(hint, str) and hint.strip() else ""
+
+
+_HINT_FAILURES_LOGGED: set[str] = set()
def check_runtime_readiness(requested=None, *, strict_profile_scope=False, resolve=None):
diff --git a/tests/providers/test_missing_credentials_hints.py b/tests/providers/test_missing_credentials_hints.py
index 7103725dca1..724dfabaa0e 100644
--- a/tests/providers/test_missing_credentials_hints.py
+++ b/tests/providers/test_missing_credentials_hints.py
@@ -58,6 +58,36 @@ def test_readiness_check_appends_the_profile_hint(hinted_provider, profile_cls,
assert verdict["error"] == f"No usable credentials found for fake-hinted.{suffix}"
+class _RaisingHintProfile(ProviderProfile):
+ def missing_credentials_hint(self):
+ raise RuntimeError("plugin host is down")
+
+
+class _ListHintProfile(ProviderProfile):
+ def missing_credentials_hint(self):
+ return ["not", "a", "string"]
+
+
[email protected]("profile_cls", [_RaisingHintProfile, _ListHintProfile])
+def test_a_broken_hint_keeps_the_auth_error_and_the_fallback_chain(hinted_provider, monkeypatch, caplog, profile_cls):
+ hinted_provider(profile_cls)
+ monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-fake")
+ from hermes_cli import runtime_readiness
+ from hermes_cli.auth import AuthError
+ from hermes_cli.runtime_provider import resolve_runtime_provider, resolve_runtime_with_fallback
+
+ monkeypatch.setattr(runtime_readiness, "_HINT_FAILURES_LOGGED", set(), raising=False)
+ for _ in range(2):
+ with pytest.raises(AuthError) as excinfo:
+ resolve_runtime_provider(requested="fake-hinted")
+ assert str(excinfo.value) == "No usable credentials found for provider 'fake-hinted'. Set FAKE_HINTED_KEY."
+ runtime, entry = resolve_runtime_with_fallback(
+ {"fallback_providers": [{"provider": "openrouter", "model": "acme/model"}]}, requested="fake-hinted")
+ assert (runtime["provider"], entry["provider"]) == ("openrouter", "openrouter")
+ warned = [r for r in caplog.records if "missing_credentials_hint failed" in r.getMessage()]
+ assert len(warned) == (1 if profile_cls is _RaisingHintProfile else 0) # once per provider, not per call
+
+
_AUTH_REQUIRED_AGENT = """import json, sys
for line in sys.stdin:
request = json.loads(line)