From 6d7ced4d765c20ca1908c10a160a61eccf4ac41f Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 25 Feb 2026 15:16:30 +0800 Subject: [PATCH] fix(oplog): use json.Decoder to handle arbitrarily large JSONL lines Replace bufio.Scanner with json.NewDecoder which has no fixed line length limit. Fixes "token too long" crash when audit results produce JSONL entries exceeding the 64KB scanner default. --- internal/oplog/oplog.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/oplog/oplog.go b/internal/oplog/oplog.go index 4eedc5a90..c403f42ca 100644 --- a/internal/oplog/oplog.go +++ b/internal/oplog/oplog.go @@ -3,7 +3,6 @@ package oplog import ( - "bufio" "encoding/json" "os" "path/filepath" @@ -92,21 +91,18 @@ func Read(configPath, filename string, limit int) ([]Entry, error) { defer f.Close() var all []Entry - scanner := bufio.NewScanner(f) - for scanner.Scan() { - line := scanner.Bytes() - if len(line) == 0 { - continue - } + dec := json.NewDecoder(f) + for dec.More() { var e Entry - if err := json.Unmarshal(line, &e); err != nil { - continue // skip malformed lines + if err := dec.Decode(&e); err != nil { + // Skip malformed entries — advance past the bad line + if dec.More() { + continue + } + break } all = append(all, e) } - if err := scanner.Err(); err != nil { - return nil, err - } // Reverse to newest-first for i, j := 0, len(all)-1; i < j; i, j = i+1, j-1 {