fix: 3-minute timeout on SSE LLM streams

🟢 open · #112 · willchen96/mike ← bmersereau/mike · opened 13d ago by bmersereau · +1,364-33 across 8 files · ↗ on GitHub

From the PR description

Summary

  • Wraps runLLMStream in both POST /chat and POST /projects/:projectId/chat with a Promise.race against a 180-second timeout
  • On timeout, writes { type: "error", message: "Request timed out" } SSE event followed by [DONE] and closes the connection
  • Prevents stalled upstream LLM API calls from holding SSE connections open indefinitely under load

Closes #100 Closes #114 Closes #117 Closes #119

Changes

  • backend/src/routes/chat.ts - STREAM_TIMEOUT_MS = 180_000, Promise.race wrapping runLLMStream, timeout-specific error message in catch
  • backend/src/routes/projectChat.ts - same pattern; STREAM_TIMEOUT_MS const placed after all imports
  • backend/src/lib/__tests__/sseTimeout.test.ts - static analysis tests verifying both routes use Promise.race and the timeout
  • backend/tsconfig.json - exclude __tests__ from tsc build
  • backend/vitest.config.ts - include filter scoping tests to src/ to exclude compiled dist/ artifacts
  • backend/package.json - "test": "vitest run" script added

Test plan

  • Unit tests added and passing (3/3)
  • Backend build passes

Our analysis

Cap SSE chat streams with a 180-second timeout — 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-112.md from inside the repo you want the changes in.

⬇ Download capture-pull-112.md