Skip to content

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

fix(lenses): a trace with no live events is not scanned, not clean

Claude7056a556d71d
diff --git a/cli/beacon/internal/endpoint/dashboard/lens_data.go b/cli/beacon/internal/endpoint/dashboard/lens_data.go
index 2096550e..a72a6bcd 100644
--- a/cli/beacon/internal/endpoint/dashboard/lens_data.go
+++ b/cli/beacon/internal/endpoint/dashboard/lens_data.go
@@ -2,6 +2,7 @@ package dashboard
import (
"encoding/json"
+ "errors"
"strings"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
@@ -90,6 +91,11 @@ func fitLensEvents(bundle *asymptoteobserve.TraceBundleV1, budget int) bool {
// lensFindings runs the active rules over the trace's events. Any error, including no active rules
// (*detect.NoRulesError), leaves the caller's Findings nil: "not scanned".
func lensFindings(raw []schema.Event, opts LensDataOptions) (*asymptoteobserve.LensFindingsV1, error) {
+ if len(raw) == 0 {
+ // The trace is known only to the history: its lines have rotated out of the live log.
+ // Scanning nothing would report a clean scan of a trace no rule ever saw.
+ return nil, errors.New("no live events to scan")
+ }
compiled, skipped, err := compileActiveRules(opts.UserMode, opts.RulesDir)
if err != nil {
return nil, err
diff --git a/cli/beacon/internal/endpoint/dashboard/lens_data_test.go b/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
index 83fcf70e..8d03a114 100644
--- a/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/lens_data_test.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
+ "os"
"strings"
"testing"
@@ -221,3 +222,36 @@ func TestLensDataEvidenceResolvesAgainstTheHistoryBundle(t *testing.T) {
}
}
}
+
+// A trace that only the history still holds -- its lines rotated out of the live log -- keeps its
+// bundle, but must not claim a clean scan or a coverage verdict it could not compute.
+func TestLensDataForARotatedTraceIsNotScanned(t *testing.T) {
+ path := lensFixture(t)
+ withHistory(t)
+ optIn(t, path)
+ // Rotate: the live log now holds only an unrelated session.
+ other := testSchemaEvent("2026-06-12T10:00:00Z", "cursor", "prompt.submitted", "prompt", "repo-b")
+ other.Event.ID = "evt-later"
+ other.Session = &schema.SessionInfo{ID: "later"}
+ if err := os.Rename(path, path+".1"); err != nil {
+ t.Fatal(err)
+ }
+ writeTestLog(t, path, marshalEvents(t, other)...)
+ if err := os.Remove(path + ".1"); err != nil {
+ t.Fatal(err)
+ }
+
+ data, ok, err := BuildLensData(path, "session:claude_code:s1", LensDataOptions{UserMode: true})
+ if err != nil || !ok {
+ t.Fatalf("BuildLensData = ok %v, err %v; the history should still serve the trace", ok, err)
+ }
+ if len(data.Trace.Events) != 2 {
+ t.Fatalf("bundle has %d events, want the 2 the history kept", len(data.Trace.Events))
+ }
+ if data.Findings != nil {
+ t.Fatalf("findings = %#v, want nil (not scanned) for a trace with no live events", data.Findings)
+ }
+ if data.TokenCoverage != nil {
+ t.Fatalf("token coverage = %#v, want nil", data.TokenCoverage)
+ }
+}