fix: add SSE heartbeats to prevent stream timeout on long tool calls

🟢 open · #170 · Open-Legal-Products/mike ← trustfoundry-ai/mike · opened 1mo ago by iamgroot2285 · +71-48 across 4 files · ↗ on GitHub

From the PR description

Summary

  • Extract SSE setup into backend/src/lib/sse.ts with 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.

⬇ Download capture-pull-170.md