Skip to content

The agent that grows with you

fix(runtime): exempt loopback custom-provider pool credentials from the usable-secret floor

ygd5808baf96537a9
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index a7da0ae7f1c..888175a701e 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -646,6 +646,18 @@ def _try_resolve_from_custom_pool(
pool_api_key = getattr(entry, "runtime_api_key", None) or getattr(entry, "access_token", "")
if not pool_api_key:
return None
+ if not has_usable_secret(pool_api_key) and _loopback_hostname(base_url_hostname(base_url)):
+ # Legacy configs commonly used short/placeholder keys ('123',
+ # 'm', ...) for local no-auth services like Ollama -- fine for
+ # the endpoint itself, but has_usable_secret's 4-char floor
+ # (added after these configs were written) now rejects them
+ # here with no migration path. Every OTHER resolution path in
+ # this file already substitutes "no-key-required" for a
+ # loopback endpoint with no usable secret (the config-based
+ # custom_providers fallback a few hundred lines below, and the
+ # "actual" provider's local-offline exemption further down) --
+ # this pool path was the one gap (issue #86864).
+ pool_api_key = "no-key-required"
return {
"provider": provider_label,
"api_mode": api_mode_override or _detect_api_mode_for_url(base_url) or "chat_completions",
diff --git a/tests/hermes_cli/test_runtime_provider_resolution.py b/tests/hermes_cli/test_runtime_provider_resolution.py
index 1f90e3edb9c..33a54948ef8 100644
--- a/tests/hermes_cli/test_runtime_provider_resolution.py
+++ b/tests/hermes_cli/test_runtime_provider_resolution.py
@@ -86,6 +86,75 @@ def test_resolve_runtime_provider_uses_credential_pool(monkeypatch):
assert resolved["source"] == "manual"
+class TestCustomProviderPoolLoopbackNoKeyExemption:
+ """Regression for issue #86864: legacy custom_providers configs often
+ used short/placeholder api_keys ('123', 'm') for local no-auth
+ services like Ollama -- fine for the endpoint itself, but
+ has_usable_secret's 4-char floor now rejects them with a misleading
+ "No usable credentials found" error and no migration path. Every
+ OTHER resolution path in this file already substitutes
+ "no-key-required" for a loopback endpoint with no usable secret; the
+ credential-pool path was the one gap.
+ """
+
+ @staticmethod
+ def _pool_with(api_key: str):
+ entry = SimpleNamespace(runtime_api_key=api_key, access_token="")
+
+ class _Pool:
+ def has_credentials(self):
+ return True
+
+ def select(self):
+ return entry
+
+ return _Pool()
+
+ def test_short_placeholder_key_exempted_for_loopback_endpoint(self, monkeypatch):
+ """The exact reported repro: a 3-char legacy placeholder key
+ ('123') for a local Ollama endpoint must resolve to the same
+ "no-key-required" placeholder every other local no-auth path uses,
+ not the raw unusable value."""
+ monkeypatch.setattr(rp, "get_custom_provider_pool_key", lambda base_url, provider_name=None: "custom:local-ollama")
+ monkeypatch.setattr(rp, "load_pool", lambda pool_key: self._pool_with("123"))
+
+ result = rp._try_resolve_from_custom_pool("http://localhost:11434/v1", "custom", None)
+
+ assert result is not None
+ assert result["api_key"] == "no-key-required"
+
+ def test_single_char_placeholder_key_also_exempted(self, monkeypatch):
+ monkeypatch.setattr(rp, "get_custom_provider_pool_key", lambda base_url, provider_name=None: "custom:local")
+ monkeypatch.setattr(rp, "load_pool", lambda pool_key: self._pool_with("m"))
+
+ result = rp._try_resolve_from_custom_pool("http://127.0.0.1:11434/v1", "custom", None)
+
+ assert result["api_key"] == "no-key-required"
+
+ def test_short_key_not_exempted_for_non_loopback_endpoint(self, monkeypatch):
+ """Sanity: the exemption is scoped to loopback hosts only -- a
+ remote endpoint with a genuinely-too-short key must NOT get a
+ free pass. The short value passes through unchanged, so the
+ downstream has_usable_secret() gate still catches it."""
+ monkeypatch.setattr(rp, "get_custom_provider_pool_key", lambda base_url, provider_name=None: "custom:remote")
+ monkeypatch.setattr(rp, "load_pool", lambda pool_key: self._pool_with("xy"))
+
+ result = rp._try_resolve_from_custom_pool("https://api.remote-vendor.example/v1", "custom", None)
+
+ assert result["api_key"] == "xy"
+
+ def test_usable_loopback_key_passes_through_unchanged(self, monkeypatch):
+ """Sanity: a genuinely usable key for a loopback endpoint (a real
+ API key happens to be configured for a local proxy, say) must not
+ be silently overwritten."""
+ monkeypatch.setattr(rp, "get_custom_provider_pool_key", lambda base_url, provider_name=None: "custom:local")
+ monkeypatch.setattr(rp, "load_pool", lambda pool_key: self._pool_with("sk-genuinely-long-real-key-12345"))
+
+ result = rp._try_resolve_from_custom_pool("http://localhost:11434/v1", "custom", None)
+
+ assert result["api_key"] == "sk-genuinely-long-real-key-12345"
+
+
def test_qwen_oauth_auto_fallthrough_on_auth_failure(monkeypatch):
"""When requested_provider is 'auto' and Qwen creds fail, fall through."""
from hermes_cli.auth import AuthError