Skip to content

fix(relay): remove extra blank line from Claude SSE stream#5773

Draft
zhangzhichaolove wants to merge 1 commit into
QuantumNous:mainfrom
zhangzhichaolove:codex/fix-5402-claude-sse-extra-blank-line
Draft

fix(relay): remove extra blank line from Claude SSE stream#5773
zhangzhichaolove wants to merge 1 commit into
QuantumNous:mainfrom
zhangzhichaolove:codex/fix-5402-claude-sse-extra-blank-line

Conversation

@zhangzhichaolove

@zhangzhichaolove zhangzhichaolove commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

修复 Claude 原生 /v1/messages 流式转发时,SSE event 之间多输出一个空行的问题。

问题原因是 ClaudeChunkDatadata: 行尾主动追加了 \n,而 common.CustomEvent 在写出 data: 字段时还会自动补上标准 SSE event 终止符 \n\n,最终导致输出变成 data: ...\n\n\n。本次改动移除了 ClaudeChunkData 中的多余换行,让 Claude stream event 恢复为标准的单个空行分隔。

同时新增回归测试,连续写出两个 Claude SSE chunk,断言输出不包含三连换行,避免后续再次引入同类格式回归。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

go test ./relay/helper
go test ./relay/channel/claude
go test ./relay/...

Summary by CodeRabbit

  • Bug Fixes
    • Fixed streaming event formatting so SSE payloads no longer include an extra blank line.
    • Improved response formatting consistency for message streaming, preventing malformed line breaks in event output.
  • Tests
    • Added coverage to verify streamed events are formatted correctly and do not contain unintended extra newlines.

- stop appending a trailing newline to Claude stream data frames before CustomEvent writes the SSE terminator
- keep Claude native /v1/messages stream output at the standard single blank line between events
- add a regression test for consecutive Claude SSE chunks

Refs QuantumNous#5402
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Claude SSE chunk rendering now omits the trailing newline on the data: line, and a new unit test checks that two Claude events produce a single blank line between frames without triple-newline sequences.

Changes

Claude SSE blank-line fix

Layer / File(s) Summary
SSE chunk formatting
relay/helper/common.go
ClaudeChunkData formats the data: line without a trailing newline.
Output regression test
relay/helper/common_test.go
A new test renders two Claude events and asserts the SSE body matches the expected framing without \n\n\n.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hopped through streams with careful feet, 🐇
Fixed one blank line so things look neat.
No triple-newline puddles remain,
Just tidy chunks in SSE rain.
Hop hop — the relay sings again!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: removing an extra blank line from the Claude SSE stream.
Linked Issues check ✅ Passed The code removes the trailing newline in ClaudeChunkData and adds regression coverage, matching issue #5402's requirements.
Out of Scope Changes check ✅ Passed The PR stays focused on the SSE formatting fix and a targeted regression test with no unrelated changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Claude /v1/messages stream relay emits an extra blank line between SSE events

1 participant