fix(agent): prevent outer wall-clock timeout for streaming requests

This commit is contained in:
Xubin Ren
2026-05-16 10:12:57 +00:00
parent 06a1bef9fe
commit e87c07c368
2 changed files with 58 additions and 3 deletions
+14 -3
View File
@@ -669,14 +669,25 @@ class AgentRunner:
else:
coro = self.provider.chat_with_retry(**kwargs)
# Streaming requests already have provider-level idle timeouts
# (NANOBOT_STREAM_IDLE_TIMEOUT_S). Do not also apply the outer wall-clock
# LLM timeout here, or healthy long reasoning streams can be killed just
# because total elapsed time exceeded NANOBOT_LLM_TIMEOUT_S.
outer_timeout_s = None if (wants_streaming or wants_progress_streaming) else timeout_s
try:
response = (
await coro if timeout_s is None
else await asyncio.wait_for(coro, timeout=timeout_s)
await coro if outer_timeout_s is None
else await asyncio.wait_for(coro, timeout=outer_timeout_s)
)
except asyncio.TimeoutError:
if outer_timeout_s is None:
return LLMResponse(
content="Error calling LLM: stream stalled",
finish_reason="error",
error_kind="timeout",
)
return LLMResponse(
content=f"Error calling LLM: timed out after {timeout_s:g}s",
content=f"Error calling LLM: timed out after {outer_timeout_s:g}s",
finish_reason="error",
error_kind="timeout",
)