This commit is contained in:
Mikan
2026-06-19 17:10:17 +03:00
parent 5202b30e0a
commit 81bbf8aa69
4 changed files with 171 additions and 59 deletions

View File

@@ -79,7 +79,15 @@ class LlmClient:
tool_calls: List[Dict[str, Any]] = []
usage: Dict[str, int] = {}
try:
async with httpx.AsyncClient(timeout=self.timeout) as client:
# Use explicit timeout config so connect/read/write/pool timeouts
# are all visible — a bare `timeout=N` hides WHICH stage failed.
timeout = httpx.Timeout(
connect=10.0, # 10s to establish TCP connection
read=float(self.timeout), # full request timeout
write=10.0,
pool=5.0,
)
async with httpx.AsyncClient(timeout=timeout) as client:
resp = await client.post(url, json=payload, headers=self._headers())
resp.raise_for_status()
data = resp.json()
@@ -88,9 +96,30 @@ class LlmClient:
text = msg.get("content") or ""
tool_calls = msg.get("tool_calls") or []
usage = data.get("usage") or {}
except httpx.ConnectError as e:
err = f"ConnectError: {e}"
# Surface the URL + cause so the operator can see WHY (DNS, refused, etc.)
cause = getattr(e, "__cause__", None) or getattr(e, "__context__", None)
log.error(
"llm_connect_failed",
purpose=purpose,
url=url,
base_url=self.base_url,
model=self.model,
error=err,
cause=str(cause) if cause else None,
)
raise
except Exception as e:
err = f"{type(e).__name__}: {e}"
log.error("llm_call_failed", purpose=purpose, error=err)
log.error(
"llm_call_failed",
purpose=purpose,
url=url,
base_url=self.base_url,
model=self.model,
error=err,
)
raise
finally:
latency_ms = int((time.monotonic() - started) * 1000)