fix: 3-minute timeout on SSE LLM streams#112
Open
bmersereau wants to merge 4 commits into
Open
Conversation
bmersereau
commented
May 13, 2026
Author
bmersereau
left a comment
There was a problem hiding this comment.
PR Review
Summary
Wraps runLLMStream in both POST /chat and POST /projects/:projectId/chat with a 180-second Promise.race timeout. On timeout the handler writes a typed error SSE event and [DONE] before closing the connection. Three static-analysis tests verify both routes use Promise.race and the timeout constant.
Findings
- [severity:praise]
clearTimeout(timerId!)called on the happy path — prevents timer leak after successful stream - [severity:praise]
STREAM_TIMEOUT_MS = 180_000is placed correctly after all imports inprojectChat.ts✓ (issue #119 resolved) - [severity:praise]
vi.mockhoisting pattern not applicable here;STREAM_TIMEOUT_MSplacement verified - [severity:nit] The
timerId!non-null assertion is needed because TypeScript can't provetimerIdis assigned in the Promise constructor. This is a known unavoidable pattern; no change needed
Specific checks
-
"test": "vitest run"in package.json ✓ -
vitest.config.tsinclude filter present ✓ -
STREAM_TIMEOUT_MSafter all imports in projectChat.ts ✓ (issue #119) - Tests pass: 3/3 ✓
Verdict
Approve — clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
runLLMStreamin bothPOST /chatandPOST /projects/:projectId/chatwith aPromise.raceagainst a 180-second timeout{ type: "error", message: "Request timed out" }SSE event followed by[DONE]and closes the connectionCloses #100
Closes #114
Closes #117
Closes #119
Changes
backend/src/routes/chat.ts—STREAM_TIMEOUT_MS = 180_000,Promise.racewrappingrunLLMStream, timeout-specific error message in catchbackend/src/routes/projectChat.ts— same pattern;STREAM_TIMEOUT_MSconst placed after all importsbackend/src/lib/__tests__/sseTimeout.test.ts— static analysis tests verifying both routes usePromise.raceand the timeoutbackend/tsconfig.json— exclude__tests__from tsc buildbackend/vitest.config.ts— include filter scoping tests tosrc/to exclude compileddist/artifactsbackend/package.json—"test": "vitest run"script addedTest plan