From 91ef085d7dd5507a27b32f89344a1e2a2071a8ec Mon Sep 17 00:00:00 2001 From: erio Date: Mon, 9 Mar 2026 07:52:32 +0800 Subject: [PATCH 1/2] fix: increase SSE scanner max line size from 40MB to 500MB 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. --- backend/internal/service/gateway_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index c6bec806..9b3c8bc0 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -41,7 +41,7 @@ const ( claudeAPIURL = "https://api.anthropic.com/v1/messages?beta=true" claudeAPICountTokensURL = "https://api.anthropic.com/v1/messages/count_tokens?beta=true" stickySessionTTL = time.Hour // 粘性会话TTL - defaultMaxLineSize = 40 * 1024 * 1024 + defaultMaxLineSize = 500 * 1024 * 1024 // Canonical Claude Code banner. Keep it EXACT (no trailing whitespace/newlines) // to match real Claude CLI traffic as closely as possible. When we need a visual // separator between system blocks, we add "\n\n" at concatenation time. From 4ce986d47d1fe274a9aafd17348f24361afcfd96 Mon Sep 17 00:00:00 2001 From: erio Date: Mon, 9 Mar 2026 08:05:02 +0800 Subject: [PATCH 2/2] fix: also update viper default max_line_size from 40MB to 500MB The viper config default (config.go) was overriding the constant in gateway_service.go. Both must be updated to take effect. --- backend/internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go index 42f1e629..de876098 100644 --- a/backend/internal/config/config.go +++ b/backend/internal/config/config.go @@ -1402,7 +1402,7 @@ func setDefaults() { viper.SetDefault("gateway.concurrency_slot_ttl_minutes", 30) // 并发槽位过期时间(支持超长请求) viper.SetDefault("gateway.stream_data_interval_timeout", 180) viper.SetDefault("gateway.stream_keepalive_interval", 10) - viper.SetDefault("gateway.max_line_size", 40*1024*1024) + viper.SetDefault("gateway.max_line_size", 500*1024*1024) viper.SetDefault("gateway.scheduling.sticky_session_max_waiting", 3) viper.SetDefault("gateway.scheduling.sticky_session_wait_timeout", 120*time.Second) viper.SetDefault("gateway.scheduling.fallback_wait_timeout", 30*time.Second)