fix(frontend): parse Server-Sent Events (SSE) protocol stream correctly in askQuestionStreamApi#572
Conversation
…ly in askQuestionStreamApi
|
@Sandeep6135 is attempting to deploy a commit to the firefistisdead's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 44 minutes and 2 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes the frontend streaming chat rendering by parsing Server-Sent Events (SSE) frames in askQuestionStreamApi so SSE protocol envelopes (e.g., data: ..., [DONE]) don’t leak into the UI.
Changes:
- Introduces a stream buffer to handle partial chunks and parse incoming text by newline delimiters.
- Filters SSE
data:lines and ignores the[DONE]marker when building the displayed answer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (line.startsWith("data: ")) { | ||
| const dataVal = line.slice(6); | ||
| if (dataVal === "[DONE]") { | ||
| break; | ||
| } |
Pull Request: Resolve SSE Protocol Leak in Chat Interface (Broken Stream Rendering)
Closes #565
📌 Classification & Priority
bug-fixmedium/criticalfrontend-appexceptional-ui-rendering📖 Summary
Important
This PR fixes an SSE (Server-Sent Events) protocol leak where raw control envelopes (
data: ...,event: ..., and[DONE]) generated by the backend AI services were leaking into the chat interface UI instead of rendering clean, human-readable answers.🔴 Problem
The frontend stream helper
askQuestionStreamApiconsumed the raw response stream by reading and decoding binary chunks. However, it lacked a protocol parser to filter SSE lines, appending the raw chunk string (includingdata:,event:, anddata: [DONE]metadata boundaries) directly to the UI rendering state. As a result, users were shown raw SSE protocol markup instead of clean generated sentences.🟢 Solution
Implemented a client-side stream parser inside
askQuestionStreamApi:bufferto handle partial chunk splits across network bounds.\n) and buffered trailing/incomplete lines to preserve character sequences.\r) to support multi-platform protocol alignment.data:prefix, while ignoring control events such as[DONE].🧪 Steps to Reproduce
data:or[DONE]protocol syntax leaks into the interface.🔍 Expected Behaviour
The user sees only the clean, conversational sentence output inside the chat interface bubbles.
❌ Actual Behaviour (Before Fix)
The chat bubble leaked raw SSE envelopes such as
data: Hello\n\ndata: World\n\ndata: [DONE]directly into the viewport.🛠️ Code Diff Walkthrough
frontend/src/services/api.js