Repository navigation
fix(go-models): raise SSE scanner buffer so large stream chunks are not dropped - #15382
Conversation
📝 WalkthroughWalkthroughAdds explicit ChangesSSE Buffer Size and Test Consolidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
f05dc73 to
846fa5a
Compare
|
Hi, @JinHai-CN @Haruko386 |
Haruko386
left a comment
There was a problem hiding this comment.
@Dexterity104 LGTM
Thank you for your contribution
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15382 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Closes #15381
Every provider in
internal/entity/models/reads its streaming response withbufio.NewScanner(resp.Body)and iterates overscanner.Scan(). The defaultbufio.Scannermaximum token size is 64KB, so when an upstream sends a single SSEdata:line larger than 64KB (long content deltas, large tool or function call argument blobs, bundledreasoning_content, or providers that emit a whole message in one event)scanner.Scan()returnsfalseandscanner.Err()returnsbufio.ErrTooLong. Streaming chat then ends with an error partway through the response.This change adds
scanner.Buffer(make([]byte, 64*1024), 1024*1024)immediately after every SSE scanner that was still bare, raising the cap to 1MB. 1MB is the value already used for streaming chat inopenai.go,modelscope.go,groq.go,mistral.go,xai.goand the other already patched providers (the 8MB cap in the repo is reserved for TTS and embedding paths), so this simply converges the remaining providers onto the established pattern. Nothing else changes: line parsing,data:prefix handling,[DONE]detection, JSON unmarshalling, error handling, and the existingscanner.Err()checks all stay the same.Providers covered (23 scanners across 22 files): 302ai, aliyun, baichuan, baidu, cohere, deepinfra, deepseek, gitee, huggingface, lmstudio, minimax (the chat scanner, whose TTS scanner was already bumped), moonshot, nvidia, ollama, openrouter, orcarouter, paddleocr, siliconflow, tokenhub, vllm, volcengine, xunfei, zhipu-ai.
jiekouai.gois excluded because it is covered by the in flight #15337.A table driven regression test (
sse_scanner_buffer_test.go) streams a single 128KBdata:content delta followed bydata: [DONE]through anhttptestserver and asserts thatChatStreamlyWithSenderdelivers the full content with no error across a representative subset of providers. Without the buffer fix the test fails withbufio.Scanner: token too long.This PR also removes three duplicate declarations of the package level
roundTripperFunctest helper that several recently merged provider PRs each added independently, which had left theinternal/entity/modelstest package unable to compile. The helper now lives in a single place and is shared.Type of change