From 777226722a77c53a56538067cd3fe9e81f2a1998 Mon Sep 17 00:00:00 2001 From: dtarkent2-sys Date: Fri, 20 Feb 2026 03:25:53 +0000 Subject: [PATCH] fix: add SSE heartbeat to prevent Railway proxy timeout Railway kills idle connections after ~30s. During long LLM calls between agent stages, the SSE stream goes silent and gets dropped. Now sends heartbeat events every 15s to keep the connection alive. Co-Authored-By: Claude Opus 4.6 --- app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index ed0111f7..981849b9 100644 --- a/app.py +++ b/app.py @@ -285,7 +285,11 @@ async def stream_analysis(analysis_id: str): async def event_generator(): while True: - event = await q.get() + try: + event = await asyncio.wait_for(q.get(), timeout=15) + except asyncio.TimeoutError: + yield {"event": "heartbeat", "data": ""} + continue if event is None: break yield {"data": json.dumps(event)}