The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: key the ACP named-provider swap on is_user_defined, not slug-name collision
teknium121d28dfe000a
diff --git a/acp_adapter/model_catalog.py b/acp_adapter/model_catalog.pyindex 87bce5b059d..b2b036f51f4 100644--- a/acp_adapter/model_catalog.py+++ b/acp_adapter/model_catalog.py@@ -254,20 +254,32 @@ def build_model_state(model: str, provider: str, base_url: str) -> SessionModelSnamed_catalogs = _named_custom_provider_catalogs()named_slugs = {str(slug).strip().lower() for slug, _label, _models in named_catalogs}current_choice_provider = str(provider or "").strip().lower()+ current_base = base_url.strip().rstrip("/").lower()# ``build_models_payload`` represents configured ``providers:`` entries by their raw# config key. ACP ids must instead use the durable ``custom:<key>`` identity so the- # picker value round-trips through ``parse_model_input``.- if f"custom:{current_choice_provider}" in named_slugs:- current_choice_provider = f"custom:{current_choice_provider}"- inventory_rows = [- row for row in (payload.get("providers") or [])- if f"custom:{str(row.get('slug') or '').strip().lower()}" not in named_slugs- ]+ # picker value round-trips through ``parse_model_input``. Only user-defined rows are+ # replaced by the named catalogs: a ``providers:`` key that shadows a canonical name+ # (``providers.openrouter:`` → proxy) must leave the canonical row — and a session that+ # runs on the canonical endpoint — alone, or picking "current" re-routes to the proxy.+ all_rows = payload.get("providers") or []+ canonical_current = any(+ str(r.get("slug") or "").strip().lower() == current_choice_provider and not r.get("is_user_defined")+ for r in all_rows+ )+ inventory_rows: list = []+ for row in all_rows:+ slug = str(row.get("slug") or "").strip().lower()+ if not row.get("is_user_defined") or not {slug, f"custom:{slug}"} & named_slugs:+ inventory_rows.append(row)+ continue+ row_base = str(row.get("api_url") or "").strip().rstrip("/").lower()+ if slug.removeprefix("custom:") == current_choice_provider and (current_base == row_base or not canonical_current):+ current_choice_provider = f"custom:{current_choice_provider}"cat = _ModelCatalog(normalize_provider=normalize_provider, current_model=model,current_choice_provider=current_choice_provider,- current_base_url=base_url.strip().rstrip("/").lower(),+ current_base_url=current_base,)cat.add_inventory_rows(inventory_rows, provider_label)cat.add_named_catalogs(named_catalogs, current_choice_provider)diff --git a/tests/acp_adapter/test_named_provider_catalogs.py b/tests/acp_adapter/test_named_provider_catalogs.pyindex 2feb2e0f7a3..0161e444cf5 100644--- a/tests/acp_adapter/test_named_provider_catalogs.py+++ b/tests/acp_adapter/test_named_provider_catalogs.py@@ -257,7 +257,7 @@ class TestModelStateIncludesNamedProviders:}}inventory = {- "providers": [{"slug": "relay", "name": "Relay", "models": ["model-a"]}]+ "providers": [{"slug": "relay", "name": "Relay", "is_user_defined": True, "models": ["model-a"]}]}with patch("hermes_cli.config.load_config", return_value=cfg), patch(@@ -310,3 +310,28 @@ class TestModelStateIncludesNamedProviders:)assert provider == "custom:local-127.0.0.1:11434"assert model == "qwen3:1.7b"++ @pytest.mark.asyncio+ async def test_named_entry_shadowing_a_canonical_provider_keeps_the_canonical_session(self):+ """``providers.openrouter:`` (a proxy) must not swallow the canonical OpenRouter rows nor+ relabel a session running on openrouter.ai as ``custom:openrouter`` (that id resolves to+ the proxy base_url)."""+ manager = SessionManager(+ agent_factory=lambda: SimpleNamespace(+ model="model-c", provider="openrouter", base_url="https://openrouter.ai/api/v1")+ )+ acp_agent = HermesACPAgent(session_manager=manager)+ inventory = {"providers": [+ {"slug": "openrouter", "name": "OpenRouter", "is_user_defined": False, "models": ["model-c"]},+ {"slug": "custom:openrouter", "name": "openrouter", "is_user_defined": True,+ "api_url": "https://or.example/api/v1", "models": ["model-a"]},+ ]}++ with patch("hermes_cli.inventory.build_models_payload", return_value=inventory), patch(+ "acp_adapter.model_catalog._named_custom_provider_catalogs",+ return_value=[("custom:openrouter", "openrouter", [("model-a", "")])],+ ):+ resp = await acp_agent.new_session(cwd="/tmp")++ assert resp.models.current_model_id == "openrouter:model-c"+ assert [m.model_id for m in resp.models.available_models] == ["openrouter:model-c", "custom:openrouter:model-a"]