From 3dcbc72ddd1935e988e92151221e28d4d373ed0d Mon Sep 17 00:00:00 2001 From: Viet Tran Date: Fri, 6 Mar 2026 22:39:21 +0700 Subject: [PATCH] fix(openai): increase SSE scanner buffer to 1MB and remove duplicate error check (#72) Default bufio.Scanner limit (64KB) can truncate large SSE lines from tool call arguments or thinking content, causing silent parse failures. Set buffer to 1MB to match the scale of extended thinking responses. Also remove a duplicate scanner.Err() check that was accidentally left in. --- internal/providers/openai.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/providers/openai.go b/internal/providers/openai.go index 97ac6fe2..ed51c8ff 100644 --- a/internal/providers/openai.go +++ b/internal/providers/openai.go @@ -103,6 +103,7 @@ func (p *OpenAIProvider) ChatStream(ctx context.Context, req ChatRequest, onChun accumulators := make(map[int]*toolCallAccumulator) scanner := bufio.NewScanner(respBody) + scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024) // 1MB max line for large tool call / thinking chunks for scanner.Scan() { line := scanner.Text() if !strings.HasPrefix(line, "data:") { @@ -185,11 +186,6 @@ func (p *OpenAIProvider) ChatStream(ctx context.Context, req ChatRequest, onChun return nil, fmt.Errorf("%s: stream read error: %w", p.name, err) } - // Check for scanner errors (timeout, connection reset, etc.) - if err := scanner.Err(); err != nil { - return nil, fmt.Errorf("%s: stream read error: %w", p.name, err) - } - // Parse accumulated tool call arguments for i := 0; i < len(accumulators); i++ { acc := accumulators[i]