Skip to content

fix(responses): parse standard SSE framing - #2464

Open
0YHR0 wants to merge 2 commits into
envoyproxy:mainfrom
0YHR0:agent/fix-responses-sse-line-endings
Open

fix(responses): parse standard SSE framing#2464
0YHR0 wants to merge 2 commits into
envoyproxy:mainfrom
0YHR0:agent/fix-responses-sse-line-endings

Conversation

@0YHR0

@0YHR0 0YHR0 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Make all existing translator SSE parsers accept standard event framing while they inspect streamed events for Gateway observability and protocol translation.

Root Cause

Several parsers required a space in data: lines, although SSE permits data: without that optional space. The Responses and Speech parsers also recognized only LF event boundaries, although SSE permits CRLF boundaries.

Impact

Client response bytes remain unchanged for passthrough translators. The missing parsing affects Gateway's extracted token usage, resolved response model, tracing chunks, and translated streams.

Fix

Use shared helpers to parse data: fields and LF or CRLF event boundaries across the affected stream parsers.

Related Issue

Fixes #2463

Testing

  • go test ./internal/translator -count=1

Signed-off-by: 0YHR0 <97868579@qq.com>
@0YHR0
0YHR0 requested a review from a team as a code owner July 31, 2026 13:03
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 31, 2026
@dosubot

dosubot Bot commented Jul 31, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-08-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about ai-gateway Add Dosu to your team

@0YHR0 0YHR0 changed the title fix(responses): accept standard SSE line endings fix(responses): parse standard SSE framing Jul 31, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.94%. Comparing base (e989693) to head (0ebee32).

Files with missing lines Patch % Lines
internal/translator/openai_responses.go 93.75% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2464   +/-   ##
=======================================
  Coverage   84.93%   84.94%           
=======================================
  Files         154      154           
  Lines       22423    22433   +10     
=======================================
+ Hits        19046    19056   +10     
  Misses       2222     2222           
  Partials     1155     1155           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kanurag94 kanurag94 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
One thing I noticed is that this bug exists in other translators too.

- openai_completions.go:157
- openai_openai.go:195
- openai_speech.go:154
- openai_transcription.go:137
- anthropic_anthropic.go:146
- openai_gcpvertexai.go:318

They split on a single \n and not \n\n. A backend sending data:{} will break them the same way.
Is it possible to create a followup/ or fix them here (create a shared helper).

Signed-off-by: 0YHR0 <97868579@qq.com>
@0YHR0

0YHR0 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@kanurag94 Thanks, I took the shared-helper approach in 4c81fc2. It now accepts both data field forms across the existing stream parsers, and shares LF/CRLF event-boundary handling for the parsers that buffer full events. I also added helper coverage and ran go test ./internal/translator -count=1. Could you please take another look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses API streaming parser ignores standard SSE framing

3 participants