History

fix(executor): increase buffer size for stream scanners to 50MB across multiple executors

sususu committed 11 months ago

Commit 76c563d1 parent 94d61c711 files · +15 −15Browse files

Unified · Split

11 files
  1. internal/runtime/executor/antigravity_executor.go +1 −1
  2. internal/runtime/executor/claude_executor.go +2 −2
  3. internal/runtime/executor/codex_executor.go +1 −1
  4. internal/runtime/executor/gemini_cli_executor.go +1 −1
  5. internal/runtime/executor/gemini_executor.go +1 −1
  6. internal/runtime/executor/gemini_vertex_executor.go +2 −2
  7. internal/runtime/executor/iflow_executor.go +1 −1
  8. internal/runtime/executor/openai_compat_executor.go +1 −1
  9. internal/runtime/executor/qwen_executor.go +1 −1
  10. internal/translator/claude/gemini/claude_gemini_response.go +2 −2
  11. internal/translator/claude/openai/responses/claude_openai-responses_response.go +2 −2
internal/runtime/executor/antigravity_executor.go+1−1
@@ -38,7 +38,7 @@ const ( · 37 unmodified lines
3838 defaultAntigravityAgent = "antigravity/1.11.5 windows/amd64"
3939 antigravityAuthType = "antigravity"
4040 refreshSkew = 3000 * time.Second
41− streamScannerBuffer int = 20_971_520
41+ streamScannerBuffer int = 52_428_800 // 50MB
4242 )
4343
4444 var randSource = rand.New(rand.NewSource(time.Now().UnixNano()))
internal/runtime/executor/claude_executor.go+2−2
@@ -238,7 +238,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A · 237 unmodified lines
238238 // If from == to (Claude → Claude), directly forward the SSE stream without translation
239239 if from == to {
240240 scanner := bufio.NewScanner(decodedBody)
241− scanner.Buffer(nil, 20_971_520)
241+ scanner.Buffer(nil, 52_428_800) // 50MB
242242 for scanner.Scan() {
243243 line := scanner.Bytes()
244244 appendAPIResponseChunk(ctx, e.cfg, line)
@@ -261,7 +261,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A · 16 unmodified lines
261261
262262 // For other formats, use translation
263263 scanner := bufio.NewScanner(decodedBody)
264− scanner.Buffer(nil, 20_971_520)
264+ scanner.Buffer(nil, 52_428_800) // 50MB
265265 var param any
266266 for scanner.Scan() {
267267 line := scanner.Bytes()
internal/runtime/executor/codex_executor.go+1−1
@@ -205,7 +205,7 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au · 204 unmodified lines
205205 }
206206 }()
207207 scanner := bufio.NewScanner(httpResp.Body)
208− scanner.Buffer(nil, 20_971_520)
208+ scanner.Buffer(nil, 52_428_800) // 50MB
209209 var param any
210210 for scanner.Scan() {
211211 line := scanner.Bytes()
internal/runtime/executor/gemini_cli_executor.go+1−1
@@ -309,7 +309,7 @@ func (e *GeminiCLIExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut · 308 unmodified lines
309309 }()
310310 if opts.Alt == "" {
311311 scanner := bufio.NewScanner(resp.Body)
312− scanner.Buffer(nil, 20_971_520)
312+ scanner.Buffer(nil, 52_428_800) // 50MB
313313 var param any
314314 for scanner.Scan() {
315315 line := scanner.Bytes()
internal/runtime/executor/gemini_executor.go+1−1
@@ -243,7 +243,7 @@ func (e *GeminiExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A · 242 unmodified lines
243243 }
244244 }()
245245 scanner := bufio.NewScanner(httpResp.Body)
246− scanner.Buffer(nil, 20_971_520)
246+ scanner.Buffer(nil, 52_428_800) // 50MB
247247 var param any
248248 for scanner.Scan() {
249249 line := scanner.Bytes()
internal/runtime/executor/gemini_vertex_executor.go+2−2
@@ -564,7 +564,7 @@ func (e *GeminiVertexExecutor) executeStreamWithServiceAccount(ctx context.Conte · 563 unmodified lines
564564 }
565565 }()
566566 scanner := bufio.NewScanner(httpResp.Body)
567− scanner.Buffer(nil, 20_971_520)
567+ scanner.Buffer(nil, 52_428_800) // 50MB
568568 var param any
569569 for scanner.Scan() {
570570 line := scanner.Bytes()
@@ -678,7 +678,7 @@ func (e *GeminiVertexExecutor) executeStreamWithAPIKey(ctx context.Context, auth · 107 unmodified lines
678678 }
679679 }()
680680 scanner := bufio.NewScanner(httpResp.Body)
681− scanner.Buffer(nil, 20_971_520)
681+ scanner.Buffer(nil, 52_428_800) // 50MB
682682 var param any
683683 for scanner.Scan() {
684684 line := scanner.Bytes()
internal/runtime/executor/iflow_executor.go+1−1
@@ -201,7 +201,7 @@ func (e *IFlowExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au · 200 unmodified lines
201201 }()
202202
203203 scanner := bufio.NewScanner(httpResp.Body)
204− scanner.Buffer(nil, 20_971_520)
204+ scanner.Buffer(nil, 52_428_800) // 50MB
205205 var param any
206206 for scanner.Scan() {
207207 line := scanner.Bytes()
internal/runtime/executor/openai_compat_executor.go+1−1
@@ -206,7 +206,7 @@ func (e *OpenAICompatExecutor) ExecuteStream(ctx context.Context, auth *cliproxy · 205 unmodified lines
206206 }
207207 }()
208208 scanner := bufio.NewScanner(httpResp.Body)
209− scanner.Buffer(nil, 20_971_520)
209+ scanner.Buffer(nil, 52_428_800) // 50MB
210210 var param any
211211 for scanner.Scan() {
212212 line := scanner.Bytes()
internal/runtime/executor/qwen_executor.go+1−1
@@ -181,7 +181,7 @@ func (e *QwenExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Aut · 180 unmodified lines
181181 }
182182 }()
183183 scanner := bufio.NewScanner(httpResp.Body)
184− scanner.Buffer(nil, 20_971_520)
184+ scanner.Buffer(nil, 52_428_800) // 50MB
185185 var param any
186186 for scanner.Scan() {
187187 line := scanner.Bytes()
internal/translator/claude/gemini/claude_gemini_response.go+2−2
@@ -331,8 +331,8 @@ func ConvertClaudeResponseToGeminiNonStream(_ context.Context, modelName string, · 330 unmodified lines
331331 streamingEvents := make([][]byte, 0)
332332
333333 scanner := bufio.NewScanner(bytes.NewReader(rawJSON))
334− buffer := make([]byte, 20_971_520)
335− scanner.Buffer(buffer, 20_971_520)
334+ buffer := make([]byte, 52_428_800) // 50MB
335+ scanner.Buffer(buffer, 52_428_800)
336336 for scanner.Scan() {
337337 line := scanner.Bytes()
338338 // log.Debug(string(line))
internal/translator/claude/openai/responses/claude_openai-responses_response.go+2−2
@@ -445,8 +445,8 @@ func ConvertClaudeResponseToOpenAIResponsesNonStream(_ context.Context, _ string · 444 unmodified lines
445445 // Use a simple scanner to iterate through raw bytes
446446 // Note: extremely large responses may require increasing the buffer
447447 scanner := bufio.NewScanner(bytes.NewReader(rawJSON))
448− buf := make([]byte, 20_971_520)
449− scanner.Buffer(buf, 20_971_520)
448+ buf := make([]byte, 52_428_800) // 50MB
449+ scanner.Buffer(buf, 52_428_800)
450450 for scanner.Scan() {
451451 line := scanner.Bytes()
452452 if !bytes.HasPrefix(line, dataTag) {