Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: scope malformed-line checks to session window in readStructuredEvents

Cursor Agent57a57278883e
diff --git a/cli/beacon/internal/ci/validate.go b/cli/beacon/internal/ci/validate.go
index 95daf747..9c92d34a 100644
--- a/cli/beacon/internal/ci/validate.go
+++ b/cli/beacon/internal/ci/validate.go
@@ -95,6 +95,7 @@ func readStructuredEvents(path string, since time.Time) ([]schema.Event, []strin
scanner := bufio.NewScanner(file)
scanner.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)
lineNo := 0
+ filtering := !since.IsZero()
for scanner.Scan() {
lineNo++
line := bytes.TrimSpace(scanner.Bytes())
@@ -103,23 +104,22 @@ func readStructuredEvents(path string, since time.Time) ([]schema.Event, []strin
}
var event schema.Event
if err := json.Unmarshal(line, &event); err != nil {
+ if filtering {
+ continue
+ }
malformed = append(malformed, fmt.Sprintf("line %d: %v", lineNo, err))
continue
}
- if err := event.Validate(); err != nil {
- malformed = append(malformed, fmt.Sprintf("line %d: %v", lineNo, err))
- continue
- }
- if !since.IsZero() {
+ if filtering {
ts, err := time.Parse(time.RFC3339, event.Timestamp)
- if err != nil {
- malformed = append(malformed, fmt.Sprintf("line %d: timestamp is not RFC3339", lineNo))
- continue
- }
- if ts.Before(since) {
+ if err != nil || ts.Before(since) {
continue
}
}
+ if err := event.Validate(); err != nil {
+ malformed = append(malformed, fmt.Sprintf("line %d: %v", lineNo, err))
+ continue
+ }
events = append(events, event)
}
if err := scanner.Err(); err != nil {
diff --git a/cli/beacon/internal/ci/validate_test.go b/cli/beacon/internal/ci/validate_test.go
index adf618d6..8d4299b5 100644
--- a/cli/beacon/internal/ci/validate_test.go
+++ b/cli/beacon/internal/ci/validate_test.go
@@ -75,6 +75,41 @@ func TestValidateFiltersEventsBeforeSince(t *testing.T) {
}
}
+func TestValidateSinceIgnoresOldMalformedLines(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ // Write an old malformed line followed by a valid new event.
+ f, err := os.Create(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := f.WriteString("{not-json}\n"); err != nil {
+ t.Fatal(err)
+ }
+ event := NewSessionEvent("ci.test", "test event", nil)
+ event.Harness.Name = "claude_code"
+ data, err := json.Marshal(event)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := f.Write(append(data, '\n')); err != nil {
+ t.Fatal(err)
+ }
+ f.Close()
+
+ result := Validate(ValidationOptions{
+ LogPath: path,
+ MinEvents: 1,
+ RequireHarness: "claude",
+ Since: time.Now().Add(-1 * time.Minute),
+ })
+ if result.Status != "ok" {
+ t.Fatalf("Validate status = %q, want ok; old malformed line should be ignored with Since filter; stages=%#v", result.Status, result.Stages)
+ }
+ if result.EventCount != 1 {
+ t.Fatalf("EventCount = %d, want 1", result.EventCount)
+ }
+}
+
func writeEventLine(t *testing.T, path string, event schema.Event) {
t.Helper()
data, err := json.Marshal(event)