Skip to content

The agent that grows with you

fix: /model no longer calls one configured provider ambiguous when its compat view is also passed

teknium1a02ca4a1534d
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py
index 0bcb1b5e40c..fa1f31d78c1 100644
--- a/hermes_cli/model_switch.py
+++ b/hermes_cli/model_switch.py
@@ -857,8 +857,14 @@ def _configured_provider_matches(
if isinstance(user_providers, dict):
candidates += [(slug, cfg) for slug, cfg in user_providers.items()
if isinstance(slug, str) and isinstance(cfg, dict)]
+ # get_compatible_custom_providers() re-lists every ``providers.<slug>`` row as a ``custom:<name>``
+ # entry stamped with ``provider_key: <slug>``; callers (gateway, TUI, CLI) pass both views, so
+ # that projection is the same endpoint as the row above, not a second declaration (#112788).
+ # Hand-written ``custom_providers:`` rows carry no provider_key and stay separate candidates.
+ projected = {slug for slug, _ in candidates}
candidates += [(f"custom:{e['name']}", e) for e in _custom_entries(custom_providers)
- if isinstance(e.get("name"), str) and e["name"].strip()]
+ if isinstance(e.get("name"), str) and e["name"].strip()
+ and str(e.get("provider_key") or "").strip() not in projected]
matches: dict[str, str] = {}
for slug, cfg in candidates:
diff --git a/tests/hermes_cli/test_model_switch_configured_provider_routing.py b/tests/hermes_cli/test_model_switch_configured_provider_routing.py
index 47e482f2cc1..323dc7c85ee 100644
--- a/tests/hermes_cli/test_model_switch_configured_provider_routing.py
+++ b/tests/hermes_cli/test_model_switch_configured_provider_routing.py
@@ -122,3 +122,37 @@ def test_xai_oauth_soft_accept_preserved_when_no_match():
)
assert result.success is True, result.error_message
assert result.target_provider == "xai-oauth"
+
+
+
+def test_compat_projection_of_same_provider_is_not_ambiguous():
+ """The gateway/TUI/CLI pass ``providers:`` AND ``get_compatible_custom_providers()``, which re-lists
+ each ``providers.<slug>`` row as ``custom:<name>``. One configured endpoint must route, not be
+ rejected as 'declared by multiple configured providers' (#112788)."""
+ from hermes_cli.config import get_compatible_custom_providers
+
+ user_providers = {"relay": {"name": "relay", "api": "https://relay.example/v1",
+ "key_env": "RELAY_KEY", "default_model": "claude-opus-4-7"}}
+ result = _run_switch(
+ raw_input="claude-opus-4-7", current_provider="openrouter", user_providers=user_providers,
+ custom_providers=get_compatible_custom_providers({"providers": user_providers}))
+ assert result.success is True, result.error_message
+ assert result.target_provider == "relay"
+
+
+def test_distinct_legacy_endpoint_with_same_model_stays_ambiguous():
+ """Control for #112788: a hand-written ``custom_providers:`` row (no provider_key) that declares
+ the same model on a different endpoint is still a genuinely separate candidate."""
+ from hermes_cli.config import get_compatible_custom_providers
+
+ user_providers = {"relay": {"name": "relay", "api": "https://relay.example/v1",
+ "key_env": "RELAY_KEY", "default_model": "claude-opus-4-7"}}
+ cfg = {"providers": user_providers, "custom_providers": [
+ {"name": "backup-relay", "base_url": "https://backup.example/v1", "key_env": "BACKUP_KEY",
+ "model": "claude-opus-4-7"}]}
+ result = _run_switch(
+ raw_input="claude-opus-4-7", current_provider="openrouter", user_providers=user_providers,
+ custom_providers=get_compatible_custom_providers(cfg))
+ assert result.success is False
+ assert "multiple configured providers" in (result.error_message or "")
+ assert "custom:backup-relay" in result.error_message and "relay" in result.error_message