Skip to content

The agent that grows with you

fix(auxiliary): normalize model on auto cache miss

Keane Yand1a13ae244dc
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 18e5d123db5..ee9c556046e 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.<task>.provider:
diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py
index 40336b720c4..a2b68c476e1 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."""