From d1a13ae244dcb6db95b113fd4b85e4837b2c0c78 Mon Sep 17 00:00:00 2001 From: Keane Yan Date: Fri, 17 Apr 2026 08:12:37 +0800 Subject: [PATCH] fix(auxiliary): normalize model on auto cache miss --- agent/auxiliary_client.py | 2 +- .../test_auxiliary_named_custom_providers.py | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 18e5d123db..ee9c556046 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -5572,7 +5572,7 @@ def _get_cached_client( client, default_model, _ = _client_cache[cache_key] # Race loser was never exposed to a caller — safe to close now. _close_cached_client(built_client, close_async=async_mode) - return client, model or default_model + return client, _compat_model(client, model, default_model) # Aliases for direct REST APIs not modeled in PROVIDER_REGISTRY, so ``auxiliary..provider: diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py index 40336b720c..a2b68c476e 100644 --- a/tests/agent/test_auxiliary_named_custom_providers.py +++ b/tests/agent/test_auxiliary_named_custom_providers.py @@ -219,6 +219,43 @@ class TestResolveVisionProviderClientModelNormalization: assert model == "glm-5v-turbo" # zai has dedicated vision model in _PROVIDER_VISION_MODELS +class TestAutoClientCacheModelCompatibility: + """Auto client cache should not keep OpenRouter-format model overrides on non-OR clients.""" + + def test_first_auto_cache_miss_drops_openrouter_model_for_named_custom_runtime(self, tmp_path): + from agent import auxiliary_client as ac + + ac._client_cache.clear() + try: + fake_client = MagicMock() + fake_client.base_url = "https://aixj.vip/v1" + fake_client.api_key = "test-key" + + runtime = { + "provider": "custom:aixj.vip", + "model": "gpt-5.4", + "base_url": "https://aixj.vip/v1", + "api_key": "***", + "api_mode": "codex_responses", + } + + with patch( + "agent.auxiliary_client.resolve_provider_client", + return_value=(fake_client, "gpt-5.4"), + ) as mock_resolve: + client, model = ac._get_cached_client( + "auto", + "google/gemini-3-flash-preview", + main_runtime=runtime, + ) + + assert client is fake_client + assert model == "gpt-5.4" + mock_resolve.assert_called_once() + finally: + ac._client_cache.clear() + + class TestVisionPathApiMode: """Vision path should propagate api_mode to _get_cached_client."""