From 8658d15957d9c6aefda807c88f8efdbb9d4c1789 Mon Sep 17 00:00:00 2001 From: fangliquan Date: Sat, 19 Sep 2026 18:35:03 +0800 Subject: [PATCH] fix(provider): honor explicit local provider names --- agent/auxiliary_client.py | 3 ++- tests/agent/test_auxiliary_named_custom_providers.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index c86c5717aa..505f822cf9 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -5374,10 +5374,11 @@ def resolve_provider_client( explicit_base_url, explicit_api_key, api_mode, main_runtime, is_vision, task, ) branch = _EXPLICIT_PROVIDER_BRANCHES.get(provider) + alias_identity = original_provider.removeprefix("custom:") # A configured provider whose name collides with a local-server alias is still a named # provider. Resolve it before the alias's generic ``custom`` branch, which otherwise loses # the configured base_url and can fall through to an unrelated credentialed provider. - if branch is None or original_provider in _LOCAL_SERVER_ALIASES: + if branch is None or alias_identity in _LOCAL_SERVER_ALIASES: try: result = _resolve_named_custom_branch(req) except ImportError: diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py index 5f1098398d..dbff6b0826 100644 --- a/tests/agent/test_auxiliary_named_custom_providers.py +++ b/tests/agent/test_auxiliary_named_custom_providers.py @@ -394,7 +394,8 @@ class TestCustomProviderAliasCollision: # Built-in kimi-coding points at api.moonshot.ai assert "moonshot" in base_url or "kimi" in base_url, f"unexpected base_url {base_url!r}" - def test_named_llamacpp_wins_over_local_server_alias(self, tmp_path): + @pytest.mark.parametrize("provider", ["llamacpp", "custom:llamacpp"]) + def test_named_llamacpp_wins_over_local_server_alias(self, tmp_path, provider): _write_config(tmp_path, { "model": {"provider": "openrouter", "default": "anthropic/claude-sonnet-4.6"}, "providers": { @@ -407,7 +408,7 @@ class TestCustomProviderAliasCollision: from agent.auxiliary_client import resolve_provider_client from openai import OpenAI - client, model = resolve_provider_client("llamacpp", model="local-model", raw_codex=True) + client, model = resolve_provider_client(provider, model="local-model", raw_codex=True) assert isinstance(client, OpenAI) assert str(client.base_url).rstrip("/") == "http://127.0.0.1:8081/v1"