Repository navigation
fix(relay): forward bare-JSON stream frames without "data:" prefix - #6798
TuTouPower wants to merge 1 commit into
Conversation
Some upstreams (e.g. the Console Go gateway for certain models like
deepseek-v4-pro) emit Anthropic stream chunks as bare JSON lines
({"type":"content_block_delta",...}) instead of standard SSE with a
"data:" prefix. StreamScannerHandler dropped every non-"data:" line, so
clients received a 200 with an empty body while other models (which do
use SSE) worked.
Accept lines starting with '{' as data frames in addition to "data:" /
"[DONE]" prefixed ones, and only strip the "data:" prefix when present.
Empty-object "{}" heartbeat frames are still filtered by the existing
len<6 guard.
Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe stream scanner now accepts bare JSON lines alongside ChangesStream frame support
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
StreamScannerHandler(relay/helper/stream_scanner.go)此前只转发以data:或[DONE]开头的行,其余行一律丢弃。部分上游(如 Console Go 网关的deepseek-v4-pro)的 Anthropic stream 直接下发无data:前缀的裸 JSON 帧({"type":"content_block_delta",...},以及若干{}心跳帧),导致这些帧全部被丢弃,客户端收到 HTTP 200 + 空 body。对照deepseek-v4-flash(上游用标准data:SSE)则正常。改动:在原有过滤条件上,额外接受以
{开头的行作为数据帧;仅在存在data:前缀时剥离前缀。空对象{}心跳帧继续由既有len(data) < 6守卫过滤,无需特殊处理。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
event:行过滤,与本缺陷无前缀裸 JSON 行不同)。{开头裸 JSON 行,已由直连上游 vs 经 new-api 对比验证根因。stream_scanner.go及其测试,不含无关改动。go test ./relay/...全部通过(含新增TestStreamScannerHandler_BareJSONFrames、TestStreamScannerHandler_MixedSSEAndBareJSON)。📸 运行证明 / Proof of Work
Summary by CodeRabbit
Bug Fixes
data:prefix.{}heartbeat frames continue to be ignored.[DONE]marker.Tests