The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): name the phase and the setting in transport-timeout error summaries
Tekniuma8c7ec078d83
diff --git a/agent/api_error_summary.py b/agent/api_error_summary.pyindex d4eaa61712a..4b57d961cbc 100644--- a/agent/api_error_summary.py+++ b/agent/api_error_summary.py@@ -155,8 +155,8 @@ class ApiErrorSummaryMixin:def _summarize_api_error(error: Exception) -> str:"""Extract a human-readable one-liner from an API error.- Cloudflare HTML pages → ``<title>``; network/DNS failures (even SDK-wrapped) → offline hint; else- truncated str(error).+ Cloudflare HTML pages → ``<title>``; network/DNS failures (even SDK-wrapped) → offline hint;+ transport timeouts → connect/read phase plus the setting to raise; else truncated str(error)."""raw = str(error)@@ -171,6 +171,11 @@ class ApiErrorSummaryMixin:)current = current.__cause__ or current.__context__+ from agent.timeout_error_summary import summarize_timeout_error+ timeout_summary = summarize_timeout_error(error)+ if timeout_summary is not None:+ return timeout_summary+if is_provider_stream_parse_error(error):return f"Malformed provider streaming response: {raw[:300]}"diff --git a/agent/timeout_error_summary.py b/agent/timeout_error_summary.pynew file mode 100644index 00000000000..9b116cd7dc0--- /dev/null+++ b/agent/timeout_error_summary.py@@ -0,0 +1,55 @@+"""Phase-specific one-liners for transport-timeout API errors.++A timeout that survives the retry loop otherwise surfaces as the SDK's bare+text: ``Request timed out.`` (openai ``APITimeoutError``) or ``timed out`` (a+raw httpx ``ReadTimeout`` mid-stream). Neither says whether a connection was+ever made, nor which setting to raise. The openai SDK wraps EVERY httpx+timeout, connect included, in ``APITimeoutError``, so the phase is read from+the most specific exception in the ``__cause__``/``__context__`` chain.+"""++from __future__ import annotations++from typing import Optional++# No TCP/TLS connection was established: raising the read timeout will not help.+_CONNECT_TIMEOUT_TYPES = frozenset({"ConnectTimeout", "ConnectTimeoutError"})+# The request was sent (or a stream was open) but no bytes arrived in time.+# ``APITimeoutError`` without a transport cause also lands here.+_READ_TIMEOUT_TYPES = frozenset({+ "ReadTimeout", "WriteTimeout", "PoolTimeout", "TimeoutException", "ReadTimeoutError",+ "APITimeoutError",+})+++def _timeout_phase(error: BaseException) -> Optional[str]:+ """``"connect"``, ``"read"``, or ``None`` when no timeout is in the chain."""+ phase = None+ current: Optional[BaseException] = error+ seen: set[int] = set()+ while current is not None and id(current) not in seen:+ seen.add(id(current))+ name = type(current).__name__+ if name in _CONNECT_TIMEOUT_TYPES:+ return "connect"+ if name in _READ_TIMEOUT_TYPES:+ phase = "read"+ current = current.__cause__ or current.__context__+ return phase+++def summarize_timeout_error(error: BaseException) -> Optional[str]:+ """Timeout summary naming the phase and the setting to change, or ``None``+ for any other error (the caller's existing summary handling then applies).++ Both lines keep the "timed out" wording: cron failure notices and the error+ classifier re-read this summary as text and match on it.+ """+ phase = _timeout_phase(error)+ if phase == "connect":+ return ("Connection to the provider timed out before it was established "+ "(check the base_url and network path)")+ if phase == "read":+ return ("Request timed out waiting for the provider to respond (if the model needs "+ "longer, raise providers.<provider>.request_timeout_seconds in config.yaml)")+ return Nonediff --git a/tests/agent/test_timeout_error_summary.py b/tests/agent/test_timeout_error_summary.pynew file mode 100644index 00000000000..38f98a640ad--- /dev/null+++ b/tests/agent/test_timeout_error_summary.py@@ -0,0 +1,33 @@+"""Transport timeouts get a phase-specific summary instead of the SDK's bare+"Request timed out." / "timed out" text (agent/timeout_error_summary.py)."""++import httpx+import openai++from agent.api_error_summary import ApiErrorSummaryMixin++_REQ = httpx.Request("POST", "http://127.0.0.1:1/v1/chat/completions")+++def _sdk_timeout(cause: Exception) -> openai.APITimeoutError:+ # Same shape the openai SDK raises: ``raise APITimeoutError(request=...) from err``.+ try:+ raise openai.APITimeoutError(request=_REQ) from cause+ except openai.APITimeoutError as exc:+ return exc+++def test_sdk_wrapped_timeouts_name_the_phase():+ summarize = ApiErrorSummaryMixin._summarize_api_error+ connect = summarize(_sdk_timeout(httpx.ConnectTimeout("timed out", request=_REQ)))+ read = summarize(_sdk_timeout(httpx.ReadTimeout("timed out", request=_REQ)))+ midstream = summarize(httpx.ReadTimeout("timed out", request=_REQ))++ assert connect.startswith("Connection to the provider timed out before it was established")+ for text in (read, midstream):+ assert text.startswith("Request timed out waiting for the provider")+ assert "request_timeout_seconds" in text+++def test_non_timeout_errors_keep_their_summary():+ assert ApiErrorSummaryMixin._summarize_api_error(RuntimeError("upstream exploded")) == "upstream exploded"