The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): stop probing hosted provider hosts for local server types (#61421)
liuhao10245d0a39a1333f
diff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex 52360ca0cec..7ed75a7bbab 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -730,6 +730,12 @@ def detect_local_server_type(base_url: str, api_key: str = "") -> Optional[str]:import httpx# IPv4-resolve BEFORE deriving server/LM Studio URLs and the cache lookup, so localhost and 127.0.0.1 share a cache entry.normalized = _localhost_to_ipv4(_normalize_base_url(base_url))+ # A hosted provider (api.openai.com, api.anthropic.com, ...) never runs Ollama/LM Studio/llama.cpp/vLLM:+ # skip the waterfall so egress logs do not fill with 404s for /api/tags, /v1/props, /version (#61421).+ # Local addresses are never in that table, and ollama.com is the one hosted host that does speak+ # Ollama's /api/tags, so it keeps the probe.+ if not is_local_endpoint(normalized) and _infer_provider_from_url(normalized) not in (None, "ollama-cloud"):+ return Noneserver_url = _server_root(normalized)lmstudio_url = _lmstudio_server_root(normalized)cached = _endpoint_probe_path_cache.get(server_url)diff --git a/tests/agent/test_model_metadata_local_ctx.py b/tests/agent/test_model_metadata_local_ctx.pyindex 1472efa55af..6ef9843096b 100644--- a/tests/agent/test_model_metadata_local_ctx.py+++ b/tests/agent/test_model_metadata_local_ctx.py@@ -1067,3 +1067,50 @@ class TestReconcileSelfHealsPoisonedCache:mock_save.assert_called_once_with("deepseek-v4-flash", "http://127.0.0.1:8080/v1", 1048576)+++class TestDetectLocalServerTypeSkipsHostedProviders:+ """Hosted provider hosts must never receive the Ollama/LM Studio/llama.cpp/vLLM discovery waterfall+ (#61421: /api/tags, /v1/props, /version 404s on api.openai.com polluted egress logs)."""++ @pytest.mark.parametrize(+ "base_url, expect_requests",+ [+ ("https://api.openai.com/v1", 0),+ ("https://api.openai.com./v1", 0), # trailing-dot FQDN must not bypass the guard+ ("https://api.anthropic.com", 0),+ ("http://127.0.0.1:11434/v1", 5), # control: local endpoints still get the full waterfall+ ("http://my-box:8080/v1", 5), # unqualified LAN hostname is local by definition+ ],+ )+ def test_public_hosts_get_no_probe_local_hosts_do(self, base_url, expect_requests):+ import agent.model_metadata as mm++ calls = []++ class _Resp:+ status_code = 404+ text = ""++ def json(self):+ return {}++ class _Client:+ def __init__(self, *a, **k):+ pass++ def __enter__(self):+ return self++ def __exit__(self, *a):+ return False++ def get(self, url):+ calls.append(url)+ return _Resp()++ mm._endpoint_probe_path_cache.clear()+ with patch("httpx.Client", _Client), patch.object(mm, "_endpoint_blackholed", return_value=False), \+ patch.object(mm, "_local_probe_disk_get", return_value=None), patch.object(mm, "_local_probe_disk_put"):+ assert mm.detect_local_server_type(base_url) is None+ assert len(calls) == expect_requests