fix(agent): LLM traffic honours CIDR and wildcard NO_PROXY entries like the platform adapters do

Three answers to "is this host in NO_PROXY": process_bootstrap used the stdlib
proxy_bypass_environment (no CIDR, no `*.`), gateway/platforms/base.py had a
full matcher (should_bypass_proxy) and a second suffix-only one
(is_host_excluded_by_no_proxy, used by Slack). Live-verified: with
NO_PROXY=10.0.0.0/8 Telegram bypassed the proxy while the LLM call to a 10.x
endpoint went through it.

The full matcher moves to the leaf module agent/proxy_bypass.py (stdlib only,
importable at early boot); both base.py functions are one-line forwarders and
process_bootstrap._get_proxy_for_base_url uses it (passing host:port so
port-qualified entries match). The six-key proxy env scan is also shared.
This commit is contained in:
teknium1
2026-09-12 19:42:53 -07:00
committed by Teknium
parent 1512edfb85
commit 164c5ea142
4 changed files with 18 additions and 88 deletions
+8 -8
View File
@@ -15,10 +15,10 @@ import socket
import sys
import threading
import time
import urllib.request
from typing import Any, Optional
from utils import base_url_hostname, normalize_proxy_url
from agent.proxy_bypass import first_proxy_env_value, should_bypass_proxy
_OPENAI_CLS_CACHE = None
@@ -288,18 +288,18 @@ class _SafeWriter:
def _get_proxy_from_env() -> Optional[str]:
"""First configured proxy URL from HTTPS_PROXY / HTTP_PROXY / ALL_PROXY (any case), or None."""
keys = ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy")
return next((normalize_proxy_url(v) for k in keys if (v := os.environ.get(k, "").strip())), None)
value = first_proxy_env_value()
return normalize_proxy_url(value) if value else None
def _get_proxy_for_base_url(base_url: Optional[str]) -> Optional[str]:
"""Env-configured proxy unless NO_PROXY excludes this base URL."""
"""Env-configured proxy unless NO_PROXY excludes this base URL (same matcher as the
gateway adapters: CIDR, ``*.`` wildcards and host:port entries all count)."""
proxy = _get_proxy_from_env()
host = base_url_hostname(base_url) if proxy and base_url else ""
try:
return None if host and urllib.request.proxy_bypass_environment(host) else proxy
except Exception:
if not (proxy and base_url):
return proxy
raw = base_url.strip()
return None if should_bypass_proxy(raw if "://" in raw else f"//{raw}") else proxy
def _shared_transport_cls():