-
Notifications
You must be signed in to change notification settings - Fork 100
Chatbot frontend became unresponsive after receiving a complete LLM response #23
Copy link
Copy link
Open
Description
PROBLEM (Production Only)
The chatbot frontend became unresponsive after receiving a complete LLM response in production only. Local development worked perfectly.
Symptoms:
- After streaming completed, the app remained stuck in "streaming" state
- The useChat hook's onFinish callback was never triggered
- UI remained in loading state (isLoading: true) indefinitely
- Users could not send subsequent messages
- Input field remained disabled
ROOT CAUSE
The Connection: keep-alive HTTP header in the SSE streaming response prevented proper stream completion in production.
Why it failed in production:
- Vercel's Edge Network (HTTP/2) strictly honors Connection: keep-alive
- The connection remained open indefinitely even after sending [DONE]
- The useChat hook waits for connection close to trigger onFinish
- Without connection close, the stream never completed
Why it worked locally:
- Local development server (uvicorn) closes connections immediately after the generator completes
- Ignores or overrides the Connection: keep-alive directive
- No edge network buffering or HTTP/2 connection pooling
PROPOSED SOLUTION
Remove the Connection: keep-alive header to allow natural connection closure.
Code Change:
File: api/utils/stream.py (Line 252)
Before:
response.headers["Connection"] = "keep-alive"
After:
(Remove this line entirely)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels