Skip to content

Commit 75d7286

Browse files
committed
fix: avoid firewall blocked false positives (#1223)
1 parent bb7cb6a commit 75d7286

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/services/system_config_service.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,13 @@ def _classify_llm_http_error(status_code: int, error_text: str) -> _LLMDiagnosti
25932593
"LLM request was rejected by quota or rate limiting",
25942594
"rate_limit",
25952595
)
2596+
if SystemConfigService._has_transport_blocked_signal(error_text or ""):
2597+
return _LLMDiagnostic(
2598+
"network_error",
2599+
True,
2600+
"LLM request failed before a valid response was returned",
2601+
"network_error",
2602+
)
25962603
if SystemConfigService._has_request_blocked_signal(error_text or ""):
25972604
return _LLMDiagnostic(
25982605
"request_blocked",
@@ -2666,6 +2673,8 @@ def _has_model_access_denied_signal(text: str) -> bool:
26662673
@staticmethod
26672674
def _has_request_blocked_signal(text: str) -> bool:
26682675
lowered = text.lower()
2676+
if SystemConfigService._has_transport_blocked_signal(lowered):
2677+
return False
26692678
blocked_tokens = (
26702679
"your request was blocked",
26712680
"the request was blocked",
@@ -2678,6 +2687,19 @@ def _has_request_blocked_signal(text: str) -> bool:
26782687
)
26792688
return any(token in lowered for token in blocked_tokens)
26802689

2690+
@staticmethod
2691+
def _has_transport_blocked_signal(text: str) -> bool:
2692+
lowered = text.lower()
2693+
transport_tokens = (
2694+
"connection blocked",
2695+
"connection request was blocked",
2696+
"network blocked",
2697+
"blocked by network policy",
2698+
"blocked by firewall",
2699+
"firewall blocked",
2700+
)
2701+
return any(token in lowered for token in transport_tokens)
2702+
26812703
@staticmethod
26822704
def _has_provider_prefix_mismatch_signal(text: str) -> bool:
26832705
lowered = text.lower()
@@ -2756,7 +2778,9 @@ def _classify_llm_exception(exc: Exception) -> _LLMDiagnostic:
27562778
return _LLMDiagnostic("network_error", True, "LLM request failed before a valid response was returned", "connection_refused")
27572779
if "ssl" in text or "tls" in text or "certificate" in text:
27582780
return _LLMDiagnostic("network_error", True, "LLM request failed before a valid response was returned", "tls_error")
2759-
if any(token in exc_name for token in ("connection", "network")) or any(token in text for token in ("connection", "network")):
2781+
if any(token in exc_name for token in ("connection", "network")) or any(
2782+
token in text for token in ("connection", "network", "firewall")
2783+
):
27602784
return _LLMDiagnostic("network_error", True, "LLM request failed before a valid response was returned", "network_error")
27612785
return _LLMDiagnostic("network_error", False, "LLM channel test failed", "unknown_error")
27622786

tests/test_system_config_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,8 @@ class RateLimitError(Exception):
14111411
(Exception("TLS certificate verify failed"), "network_error", "tls_error"),
14121412
(Exception("Connection refused"), "network_error", "connection_refused"),
14131413
(Exception("connection request was blocked by firewall"), "network_error", "network_error"),
1414+
(Exception("connection blocked by policy"), "network_error", "network_error"),
1415+
(Exception("request blocked by firewall"), "network_error", "network_error"),
14141416
(Exception("blocked"), "network_error", "unknown_error"),
14151417
(Exception("model gpt-4o is not authorized for this account"), "model_not_found", "model_access_denied"),
14161418
(Exception("litellm.APIError: APIError: OpenAIException - Model disabled."), "model_not_found", "model_access_denied"),
@@ -1512,6 +1514,8 @@ def test_discover_llm_channel_models_classifies_error_scenarios(self, mock_get)
15121514
rate_limit_response.json.return_value = {"error": {"message": "too many requests"}}
15131515
blocked_response = Mock(ok=False, status_code=403, text="Forbidden: your request was blocked by content policy")
15141516
blocked_response.json.return_value = {"error": {"message": "Forbidden: your request was blocked by content policy"}}
1517+
connection_blocked_response = Mock(ok=False, status_code=403, text="connection blocked by policy")
1518+
connection_blocked_response.json.return_value = {"error": {"message": "connection blocked by policy"}}
15151519
invalid_json_response = Mock(ok=True, status_code=200, text="<html>bad gateway</html>")
15161520
invalid_json_response.json.side_effect = ValueError("invalid json")
15171521

@@ -1524,6 +1528,7 @@ def test_discover_llm_channel_models_classifies_error_scenarios(self, mock_get)
15241528
(quota_blocked_response, "quota", "model_discovery", True, "insufficient_balance"),
15251529
(rate_limit_response, "quota", "model_discovery", True, "rate_limit"),
15261530
(blocked_response, "request_blocked", "model_discovery", False, "provider_blocked"),
1531+
(connection_blocked_response, "network_error", "model_discovery", True, "network_error"),
15271532
(invalid_json_response, "format_error", "response_parse", False, "non_json"),
15281533
]:
15291534
with self.subTest(error_code=error_code):

0 commit comments

Comments
 (0)