From 08d080e33378bbc768e1e80fe2e33879354f3cbf Mon Sep 17 00:00:00 2001 From: Maciej Lisiewski Date: Fri, 13 Nov 2026 20:34:58 +0100 Subject: [PATCH] fix(agent): titling reads the owning entry by its providers: key fast_catalog_provider returned the requested spelling, so a providers: entry named like a built-in (deepseek) read the built-in's catalog and sent its fast model to the entry's URL, and custom: never matched the entry. Return the entry's provider_key, only when it is not a registry provider; pin the URL-ownership check with a runtime on a URL the entry does not own. Refs #145452 Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com> --- agent/auxiliary_custom_credentials.py | 6 ++- ..._custom_keyed_catalog_probe_credentials.py | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/agent/auxiliary_custom_credentials.py b/agent/auxiliary_custom_credentials.py index 5c2360457f..b959158ca4 100644 --- a/agent/auxiliary_custom_credentials.py +++ b/agent/auxiliary_custom_credentials.py @@ -74,6 +74,10 @@ def fast_catalog_provider(runtime: dict[str, Any], main_provider: str) -> str: if main_provider != "custom" or not requested or requested == "custom": return main_provider from agent.custom_entry_pool import custom_entry_for_endpoint, named_custom_entry + from hermes_cli.auth import is_known_auth_provider found = named_custom_entry(requested) owns = found is not None and custom_entry_for_endpoint(str(runtime.get("base_url") or ""), requested) == found - return requested if owns else main_provider + # The entry's ``providers:`` key (``custom:`` spellings included), never a built-in's: a + # registry name would read that provider's catalog and send its fast model to this entry's URL. + key = str(found[1].get("provider_key") or "") if owns else "" + return key if key and not is_known_auth_provider(key) else main_provider diff --git a/tests/hermes_cli/test_custom_keyed_catalog_probe_credentials.py b/tests/hermes_cli/test_custom_keyed_catalog_probe_credentials.py index 1122867f35..7443e39739 100644 --- a/tests/hermes_cli/test_custom_keyed_catalog_probe_credentials.py +++ b/tests/hermes_cli/test_custom_keyed_catalog_probe_credentials.py @@ -88,6 +88,51 @@ def test_titling_fast_model_reads_the_declared_entrys_catalog(issue_config): assert seen == [f"Bearer {ROUTE_KEY}"] +@pytest.mark.parametrize(("name", "provider", "expected", "probes"), [ + ("litellm", "custom:litellm", "proxy-small-mini", [f"Bearer {ROUTE_KEY}"]), # prefixed spelling of the entry + ("deepseek", "deepseek", "my-combo", []), # entry named like a built-in: never the built-in's catalog +]) +def test_titling_reads_the_owning_entry_by_its_own_name( + tmp_path, monkeypatch, catalog_server, name, provider, expected, probes): + from agent.auxiliary_client import _main_route_target + from hermes_cli.runtime_provider import resolve_runtime_provider + + url, seen = catalog_server + home = tmp_path / ".hermes" + home.mkdir() + (home / "config.yaml").write_text(yaml.safe_dump({ + "model": {"default": "my-combo", "provider": provider, "base_url": url}, + "providers": {name: {"name": f"my {name}", "base_url": url, "key_env": "HERMES_ROUTE_KEY"}}, + "auxiliary": {"title_generation": {"prefer_fast_model": True}}, + }), encoding="utf-8") + monkeypatch.setenv("HERMES_HOME", str(home)) + monkeypatch.setenv("HERMES_ROUTE_KEY", ROUTE_KEY) + monkeypatch.setenv("DEEPSEEK_API_KEY", "deepseek-registry-key") + runtime = resolve_runtime_provider() + assert runtime["provider"] == "custom" + + _provider, model, *_ = _main_route_target(runtime, "title_generation") + + assert model == expected + assert seen == probes + + +def test_titling_skips_the_named_entry_when_the_runtime_runs_on_another_url(issue_config): + """A ``--base-url`` override keeps ``requested_provider: litellm`` on a URL the entry does not + own; the entry's fast model would be sent to that URL, so titling stays on the main model.""" + from agent.auxiliary_client import _main_route_target + from hermes_cli.runtime_provider import resolve_runtime_provider + + _url, seen = issue_config + runtime = resolve_runtime_provider(requested="litellm", explicit_base_url="http://127.0.0.1:9/v1") + assert (runtime["provider"], runtime.get("requested_provider")) == ("custom", "litellm") + + _provider, model, *_ = _main_route_target(runtime, "title_generation") + + assert model == "my-combo" + assert seen == [] + + def test_custom_catalog_probe_never_sends_the_ambient_openai_key(issue_config): """``provider_model_ids("custom")`` probes ``model.base_url``; the entry owning it supplies the key, and an OpenAI key is never a fallback for a third-party host (#91308)."""