mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 12:16:54 +00:00
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.
This commit is contained in:
1 parent
a7dcefde95
commit
3dcbc72ddd
1 file changed
+1
-5
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user