The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: fold a duplicate custom_providers row at the match level so its own models still route
teknium1f7631c0ee72b
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.pyindex 5bf0e9eb8ed..637ccbae9a1 100644--- a/hermes_cli/model_switch.py+++ b/hermes_cli/model_switch.py@@ -859,18 +859,21 @@ def _configured_provider_matches(if isinstance(slug, str) and isinstance(cfg, dict)]# Callers (gateway, TUI, CLI) pass both ``providers:`` and the compat ``custom_providers`` view,# which re-lists every ``providers.<slug>`` row as ``custom:<name>``; a hand-migrated config may- # also keep the same endpoint in both sections. Either is one provider, not two (#112788).+ # also keep the same endpoint in both sections. Either is one provider, not two (#112788) — but+ # the duplicate is folded at the MATCH level, not dropped as a candidate: a model only the legacy+ # row declares still routes to the shared endpoint instead of falling through to the current+ # provider.rows = {slug: _configured_provider_identity(slug, cfg) for slug, cfg 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()- and not _duplicates_configured_row(f"custom:{e['name']}", e, rows)]+ entries = [(f"custom:{e['name']}", e) for e in _custom_entries(custom_providers)+ if isinstance(e.get("name"), str) and e["name"].strip()]matches: dict[str, str] = {}- for slug, cfg in candidates:+ for slug, cfg in candidates + entries:hit = next((mid for key in ("models", "model", "default_model")for mid in _declared_model_ids(cfg.get(key)) if mid.lower() == target), None)if hit:- matches.setdefault(slug, hit) # first declaration wins+ owner = _duplicates_configured_row(slug, cfg, rows) if slug not in rows else None+ matches.setdefault(owner or slug, hit) # first declaration winsreturn matches@@ -895,15 +898,17 @@ def _configured_provider_identity(slug: str, cfg: dict) -> tuple[str, str, str,return name, base_url, credential, _canonical_api_mode(api_mode).lower() if api_mode else ""-def _duplicates_configured_row(slug: str, entry: dict, rows: dict[str, tuple[str, str, str, str]]) -> bool:- """A ``custom_providers`` entry is a second view of a ``providers.<slug>`` row when it is that- row's compat projection (``provider_key`` names the slug AND it points at the same endpoint —- on the raw-list fallback a hand-written provider_key aimed elsewhere stays a candidate) or a- legacy duplicate with the same provider identity."""+def _duplicates_configured_row(+ slug: str, entry: dict, rows: dict[str, tuple[str, str, str, str]]) -> Optional[str]:+ """Slug of the ``providers.<slug>`` row a ``custom_providers`` entry is a second view of, else+ None: the row's compat projection (``provider_key`` names the slug AND it points at the same+ endpoint with the same credential — on the raw-list fallback a hand-written provider_key aimed+ at another endpoint or another key stays a candidate) or a legacy duplicate with the same+ provider identity."""identity = _configured_provider_identity(slug, entry)provider_key = _clean(entry.get("provider_key")).lower()- return any(identity == row or (provider_key == row_slug.lower() and identity[1] == row[1])- for row_slug, row in rows.items())+ return next((row_slug for row_slug, row in rows.items()+ if identity == row or (provider_key == row_slug.lower() and identity[1:3] == row[1:3])), None)def _current_provider_match(st: "_Switch", cfg_matches: dict[str, str]) -> Optional[str]:diff --git a/tests/hermes_cli/test_model_switch_configured_provider_routing.py b/tests/hermes_cli/test_model_switch_configured_provider_routing.pyindex 0c8657f7901..98e996ce6bc 100644--- a/tests/hermes_cli/test_model_switch_configured_provider_routing.py+++ b/tests/hermes_cli/test_model_switch_configured_provider_routing.py@@ -223,3 +223,33 @@ def test_raw_list_provider_key_pointing_elsewhere_stays_ambiguous():custom_providers=raw)assert result.success is Falseassert "multiple configured providers" in (result.error_message or "")+++def test_legacy_duplicate_keeps_its_own_declared_models():+ """Folding an identity-equal legacy row into ``providers.relay`` must not drop the models only+ that row declares: ``/model gpt-5.4-mini`` still routes to the shared endpoint instead of+ falling through to the current provider (#112788 review follow-up)."""+ from hermes_cli.config import get_compatible_custom_providers++ user_providers = {"relay": _RELAY}+ cfg = {"providers": user_providers,+ "custom_providers": [{**_LEGACY_RELAY, "models": ["gpt-5.4", "gpt-5.4-mini"]}]}+ result = _run_switch(+ raw_input="gpt-5.4-mini", current_provider="openrouter", user_providers=user_providers,+ custom_providers=get_compatible_custom_providers(cfg))+ assert result.success is True, result.error_message+ assert result.target_provider == "relay"+ assert result.new_model == "gpt-5.4-mini"+++def test_raw_list_provider_key_with_different_credential_stays_ambiguous():+ """Raw-list fallback: a ``provider_key: relay`` stamp on the same endpoint but a DIFFERENT+ credential is not the row's projection — credential identity differs, ambiguity is preserved."""+ user_providers = {"relay": _RELAY}+ raw = [{"name": "relay", "provider_key": "relay", "base_url": "https://relay.example/v1",+ "key_env": "OTHER_KEY", "model": "claude-opus-4-7"}]+ result = _run_switch(+ raw_input="claude-opus-4-7", current_provider="openrouter", user_providers=user_providers,+ custom_providers=raw)+ assert result.success is False+ assert "multiple configured providers" in (result.error_message or "")