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 <noreply@anthropic.com>
This commit is contained in:
parent
1ded94388e
commit
777226722a
6
app.py
6
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)}
|
||||
|
|
|
|||
Loading…
Reference in New Issue