Skip to content

The agent that grows with you

fix(auth): avoid auto provider resolution recursion

KoNit-K7e06625687a2
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index ba712f0fabb..0becf6eb696 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -74,7 +74,11 @@ def _config_base_url_trustworthy_for_bare_custom(cfg_base_url: str, cfg_provider
"""
cfg_provider_norm = (cfg_provider or "").strip().lower()
bu = (cfg_base_url or "").strip()
- return bool(bu) and (cfg_provider_norm == "custom" or _resolves_to_custom(cfg_provider_norm)
+ # A bare or ``auto`` provider is the caller currently resolving auto. Asking
+ # ``resolve_provider`` whether it aliases custom re-enters that same path.
+ return bool(bu) and (cfg_provider_norm == "custom" or (
+ cfg_provider_norm not in {"", "auto"} and _resolves_to_custom(cfg_provider_norm)
+ )
or (not base_url_host_matches(bu, "openrouter.ai") and _loopback_hostname(base_url_hostname(bu))))
diff --git a/tests/hermes_cli/test_resolve_provider_custom_endpoint.py b/tests/hermes_cli/test_resolve_provider_custom_endpoint.py
index 1e6b2792e64..d986f4dc956 100644
--- a/tests/hermes_cli/test_resolve_provider_custom_endpoint.py
+++ b/tests/hermes_cli/test_resolve_provider_custom_endpoint.py
@@ -72,3 +72,20 @@ def test_stale_remote_base_url_without_a_custom_pin_is_not_a_provider(isolated_h
with pytest.raises(AuthError):
resolve_provider("auto")
assert run_bootstrap(announce=False).provider_configured is False
+
+
+def test_auto_provider_with_loopback_base_url_resolves_without_recursing(isolated_home, monkeypatch):
+ """A fresh setup keeps ``provider: auto`` until the picker stores its choice (#110926)."""
+ (isolated_home / "config.yaml").write_text(
+ "model:\n provider: auto\n base_url: http://127.0.0.1:8000/v1\n",
+ encoding="utf-8",
+ )
+ from hermes_cli import runtime_provider
+ from hermes_cli.auth import resolve_provider
+
+ def unexpected_provider_resolution(_name):
+ raise AssertionError("the bare custom trust check must not resolve model.provider=auto")
+
+ monkeypatch.setattr(runtime_provider, "_resolves_to_custom", unexpected_provider_resolution)
+
+ assert resolve_provider("auto") == "custom"