fix agent idle stream heartbeat visibility

This commit is contained in:
Hamza Ayed
2026-10-04 16:37:45 +03:00
parent cfd15e9928
commit 23f9ccc99d
4 changed files with 50 additions and 3 deletions
+3 -3
View File
@@ -2385,9 +2385,9 @@ async def run_agent_stream(
message = await asyncio.wait_for(queue.get(), timeout=0.25)
except TimeoutError:
if perf_counter() - last_output_at >= AGENT_STREAM_HEARTBEAT_SECONDS:
# Keep otherwise-idle SSE connections alive while the model
# or a local tool is taking several minutes to finish.
yield ": keep-alive\n\n"
# Send a visible SSE event (not only a comment) so clients
# can reset idle timers and tell the user the agent is alive.
yield "event: heartbeat\ndata: {}\n\n"
last_output_at = perf_counter()
continue
yield f"event: progress\ndata: {json.dumps({'message': message}, ensure_ascii=False)}\n\n"