Skip to content

Chatbot frontend became unresponsive after receiving a complete LLM response #23

@siddhantgithub

Description

@siddhantgithub

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions