Skip to content

[plan] Add missing scanner.Buffer() calls in gateway_logs.go lines 336 and 777 #20028

@github-actions

Description

@github-actions

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 — add scanner.Buffer() at lines ~336 and ~777

Approach

  1. Locate the two scanner sites at approximately lines 336 and 777 in pkg/cli/gateway_logs.go.
  2. 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() {)
  3. Run make fmt and existing gateway log tests: go test -v -run "Test.*Gateway" ./pkg/cli/.
  4. Run make agent-finish for full validation.

Acceptance Criteria

  • Lines ~336 and ~777 in gateway_logs.go both have scanner.Buffer(buf, maxScannerBufferSize) immediately after bufio.NewScanner(file)
  • The buffer pattern matches the existing correct pattern at lines ~149 and ~615
  • All existing gateway log tests pass
  • make agent-finish passes with no errors

Generated by Plan Command for issue #discussion #19993 ·

  • expires on Mar 10, 2026, 5:59 AM UTC

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions