Skip to content

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

fix: apply list results even when in detail mode and block enter while loading

Cursor Agent724b9af02c6e
diff --git a/cli/beacon/internal/endpoint/traceview/traceview.go b/cli/beacon/internal/endpoint/traceview/traceview.go
index 2c976aa6..6e950e8e 100644
--- a/cli/beacon/internal/endpoint/traceview/traceview.go
+++ b/cli/beacon/internal/endpoint/traceview/traceview.go
@@ -187,11 +187,13 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
m.ensureVisible()
return m, nil
case listLoaded:
- if m.mode != listMode || msg.request != m.listRequest {
+ if msg.request != m.listRequest {
return m, nil
}
- m.loading = false
- m.err = msg.err
+ if m.mode == listMode {
+ m.loading = false
+ m.err = msg.err
+ }
if msg.err == nil {
m.traces = msg.result.Traces
m.totalMatched = msg.result.TotalMatched
@@ -287,7 +289,7 @@ func (m Model) updateList(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
m.ensureVisible()
case "enter":
- if len(m.traces) > 0 {
+ if len(m.traces) > 0 && !m.loading {
m.mode = detailMode
m.loading = true
m.err = nil
diff --git a/cli/beacon/internal/endpoint/traceview/traceview_test.go b/cli/beacon/internal/endpoint/traceview/traceview_test.go
index 49837fe3..a56209d3 100644
--- a/cli/beacon/internal/endpoint/traceview/traceview_test.go
+++ b/cli/beacon/internal/endpoint/traceview/traceview_test.go
@@ -263,6 +263,58 @@ func TestLocalStorePagesThroughAllTracesAndEvents(t *testing.T) {
}
}
+func TestListResultAppliedWhileInDetailMode(t *testing.T) {
+ store := fixtureStore()
+ model := NewModel(store)
+ model.width, model.height = 100, 30
+ model = runCmd(t, model, model.Init())
+
+ next, _ := model.Update(key("/"))
+ model = next.(Model)
+ for _, r := range "test" {
+ next, _ = model.Update(key(string(r)))
+ model = next.(Model)
+ }
+ next, pendingList := model.Update(key("enter"))
+ model = next.(Model)
+ if !model.loading || model.query != "test" {
+ t.Fatalf("expected loading search, got loading=%t query=%q", model.loading, model.query)
+ }
+
+ // enter should be blocked while the list is loading.
+ next, cmd := model.Update(key("enter"))
+ model = next.(Model)
+ if model.mode != listMode || cmd != nil {
+ t.Fatalf("enter while loading should be a no-op, got mode=%v cmd=%v", model.mode, cmd)
+ }
+
+ // Simulate the list load completing after the user opened a trace through
+ // some other path (e.g. the load finishes, user quickly opens a trace,
+ // then a second search fires). The important invariant is that a list
+ // result delivered in detail mode is still applied.
+ model.mode = detailMode
+ model.loading = true
+ pendingMsg := pendingList()
+ next, _ = model.Update(pendingMsg)
+ model = next.(Model)
+
+ // The traces should be updated even though we were in detail mode.
+ if len(model.traces) != len(store.traces) {
+ t.Fatalf("expected traces to be updated, got %d", len(model.traces))
+ }
+ // loading should remain true because the detail load is still in progress.
+ if !model.loading {
+ t.Fatalf("expected loading to remain true in detail mode")
+ }
+
+ // Returning to list mode should show the search results, not stale data.
+ model.mode = listMode
+ model.loading = false
+ if model.query != "test" || model.totalMatched != len(store.traces) {
+ t.Fatalf("list state inconsistent: query=%q totalMatched=%d", model.query, model.totalMatched)
+ }
+}
+
func TestEventDetailsIncludesStructuredData(t *testing.T) {
event := dashboard.TraceEventV1{
Number: 7,