fix: add SSE heartbeats to prevent stream timeout on long tool calls
From the PR description
Summary
- Extract SSE setup into
backend/src/lib/sse.tswith 15-second keepalive heartbeats - Disable per-request inactivity timeouts (
req.setTimeout(0),res.setTimeout(0),socket.setTimeout(0)) and Nagle's algorithm (socket.setNoDelay(true)) for SSE connections - scoped to authenticated long-running assistant streams only - Apply to all SSE endpoints: chat, project chat, tabular chat, and tabular generate
Why
Long-running tool calls (e.g. external API searches, 30-60s) left the SSE connection
idle from the browser's perspective, causing "Error in input stream" when the connection
was killed. Periodic : keepalive comments keep the connection alive, and disabling
per-request inactivity timeouts prevents Node.js from reaping the socket during legitimate
long-running work.
Test
npm run build --prefix backend- Ran multiple long-running tool calls; streams completed without error
Our analysis
Keep SSE streams alive through long tool calls with heartbeats — read the full analysis →
Think the analysis missed something the PR description covers?
Capture this PR into my fork
Download a Markdown prompt that tells Claude how to port every
commit in this PR into your working tree. Run it via
claude -p < capture-pull-170.md from
inside the repo you want the changes in.