-
Notifications
You must be signed in to change notification settings - Fork 295
Description
Objective
Add scanner.Buffer(buf, maxScannerBufferSize) calls to two bufio.NewScanner instances in gateway_logs.go that currently lack them, preventing silent truncation of large JSONL payloads.
Context
Reported in discussion #19993 (Sergo audit: scanner-buffer-revisit-plus-regexp-compilation-audit, 2026-03-07). This is a carry-over finding from Run 13 (2026-03-06).
gateway_logs.go has 4 bufio.NewScanner(file) instances. Lines ~149 and ~615 correctly call scanner.Buffer(buf, maxScannerBufferSize). Lines ~336 and ~777 do not. Both missing-buffer scanners read gateway.jsonl entries that include AI tool call payloads which can exceed the default 64 KB token limit. Without the Buffer call, the scanner silently stops at the first oversized line, causing silent partial processing of gateway metrics (the scanner.Err() check returns the error but callers in the metrics aggregation path ignore it).
The constant maxScannerBufferSize = 1_048_576 (1 MB) is already defined in the file.
File to Modify
pkg/cli/gateway_logs.go— addscanner.Buffer()at lines ~336 and ~777
Approach
- Locate the two scanner sites at approximately lines 336 and 777 in
pkg/cli/gateway_logs.go. - For each, add the buffer allocation immediately after
bufio.NewScanner(file), matching the pattern at lines ~149–152:// Before: scanner := bufio.NewScanner(file) lineNum := 0 // (or directly: for scanner.Scan() {) // After: scanner := bufio.NewScanner(file) buf := make([]byte, maxScannerBufferSize) scanner.Buffer(buf, maxScannerBufferSize) lineNum := 0 // (or directly: for scanner.Scan() {)
- Run
make fmtand existing gateway log tests:go test -v -run "Test.*Gateway" ./pkg/cli/. - Run
make agent-finishfor full validation.
Acceptance Criteria
- Lines ~336 and ~777 in
gateway_logs.goboth havescanner.Buffer(buf, maxScannerBufferSize)immediately afterbufio.NewScanner(file) - The buffer pattern matches the existing correct pattern at lines ~149 and ~615
- All existing gateway log tests pass
-
make agent-finishpasses with no errors
Generated by Plan Command for issue #discussion #19993 · ◷
- expires on Mar 10, 2026, 5:59 AM UTC