fix: increase SSE scanner max line size from 40MB to 500MB#874
Merged
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom Mar 9, 2026
Merged
fix: increase SSE scanner max line size from 40MB to 500MB#874Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
Wei-Shaw merged 2 commits intoWei-Shaw:mainfrom
Conversation
4K image base64 data can exceed 40MB limit, causing "bufio.Scanner: token too long" errors. Scanner is adaptive (starts at 64KB, grows as needed), so increasing the cap has no impact on normal responses.
The viper config default (config.go) was overriding the constant in gateway_service.go. Both must be updated to take effect.
c794f7f to
4ce986d
Compare
|
gemini渠道已成功出图4K,但是反重力渠道仍然无法正常出图4K。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景 / Background
通过 Gemini 生成 4K 分辨率图片时,上游响应中的 base64 数据行可能超过 40MB,导致
bufio.Scanner报token too long错误,客户端收到空的 candidates。When generating 4K resolution images via Gemini, the base64 data line in upstream SSE responses can exceed 40MB, causing
bufio.Scannerto fail withtoken too longerror. The client receives empty candidates as a result.目的 / Purpose
将 SSE scanner 的最大行大小从 40MB 提升到 500MB,支持 4K 甚至 8K 图片的 base64 传输。
bufio.Scanner本身是自适应的(初始 64KB,按需增长),增大上限不会影响正常文本响应的内存使用。Increase the SSE scanner max line size from 40MB to 500MB to support 4K and even 8K image base64 transfer.
bufio.Scanneris adaptive (starts at 64KB, grows as needed), so increasing the cap has zero impact on memory usage for normal text responses.改动内容 / Changes
后端 / Backend
gateway_service.go:defaultMaxLineSize常量从40 * 1024 * 1024改为500 * 1024 * 1024config.go:viper.SetDefault("gateway.max_line_size", ...)同步从 40MB 改为 500MB(viper 配置默认值会覆盖代码常量,两处必须同步修改)gateway_service.go: UpdatedefaultMaxLineSizeconstant from40 * 1024 * 1024to500 * 1024 * 1024config.go: Updateviper.SetDefault("gateway.max_line_size", ...)from 40MB to 500MB (viper config default overrides the code constant, both must be updated in sync)