High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: dashboard identifies activity events by request id, dropping and duplicating rows
Luigi Agostib82f4cf2069e
diff --git a/internal/activity/activity.go b/internal/activity/activity.goindex 32de95d3..83f4e0d0 100644--- a/internal/activity/activity.go+++ b/internal/activity/activity.go@@ -703,6 +703,14 @@ func activityLogDay(name string) (string, bool) {return day, true}+// EventIdentity exposes the composite identity for consumers that need to+// recognise the same event across ingests. Callers must not key on RequestID+// alone: it is absent unless the client sent X-Request-Id, and a single request+// can emit more than one event.+func EventIdentity(evt Event) string {+ return eventDedupKey(evt)+}+// eventDedupKey builds a cheap composite key that collapses the byte-identical// primary + per-source dual-write copies of an event, without json.Marshal-ing the// whole struct. A false collision would require two genuinely-distinct eventsdiff --git a/internal/dashboard/activity_identity_test.go b/internal/dashboard/activity_identity_test.gonew file mode 100644index 00000000..09132e6a--- /dev/null+++ b/internal/dashboard/activity_identity_test.go@@ -0,0 +1,77 @@+package dashboard++import (+ "testing"+ "time"++ "github.com/pinchtab/pinchtab/internal/activity"+)++// The dashboard identifies an activity event by its request id alone, but the+// activity store keys events on a composite of timestamp, source, request id,+// method, path, status and tab — because one request can emit several events.+// Where those two notions of identity disagree, the dashboard silently drops+// rows as duplicates.+func TestRecordActivityEventKeepsDistinctEventsSharingARequestID(t *testing.T) {+ d := NewDashboard(nil)++ base := time.Date(2026, 7, 29, 12, 0, 0, 0, time.UTC)+ events := []activity.Event{+ {RequestID: "req-1", Source: "client", Method: "POST", Path: "/action", TabID: "tab-a", Status: 200, Timestamp: base},+ {RequestID: "req-1", Source: "client", Method: "POST", Path: "/action", TabID: "tab-b", Status: 200, Timestamp: base.Add(time.Millisecond)},+ }+ for _, evt := range events {+ d.RecordActivityEvent(evt)+ }++ got := d.RecentEvents()+ if len(got) != 2 {+ t.Fatalf("recorded %d of 2 events sharing a request id: %+v", len(got), got)+ }++ tabs := map[string]bool{}+ for _, evt := range got {+ if tab, ok := evt.Details["tabId"].(string); ok {+ tabs[tab] = true+ }+ }+ if !tabs["tab-a"] || !tabs["tab-b"] {+ t.Errorf("both tabs should be represented, got %v", tabs)+ }+}++// Genuinely repeated ingestion of the same event must still collapse, or the+// re-sync poll would duplicate every row it re-reads.+func TestRecordActivityEventStillDedupesIdenticalEvents(t *testing.T) {+ d := NewDashboard(nil)++ evt := activity.Event{+ RequestID: "req-2", Source: "client", Method: "GET", Path: "/snapshot",+ TabID: "tab-a", Status: 200,+ Timestamp: time.Date(2026, 7, 29, 12, 0, 0, 0, time.UTC),+ }+ d.RecordActivityEvent(evt)+ d.RecordActivityEvent(evt)++ if got := d.RecentEvents(); len(got) != 1 {+ t.Errorf("identical event ingested twice produced %d rows, want 1", len(got))+ }+}++// requestIDFor returns the X-Request-Id header or empty — it never generates+// one — so most events carry no request id at all. normalizeEvent then mints a+// fresh random id per ingest, defeating dedup entirely for those events.+func TestRecordActivityEventDedupesEventsWithoutARequestID(t *testing.T) {+ d := NewDashboard(nil)++ evt := activity.Event{+ Source: "client", Method: "GET", Path: "/snapshot", TabID: "tab-a", Status: 200,+ Timestamp: time.Date(2026, 7, 29, 12, 0, 0, 0, time.UTC),+ }+ d.RecordActivityEvent(evt)+ d.RecordActivityEvent(evt)++ if got := d.RecentEvents(); len(got) != 1 {+ t.Errorf("event without a request id ingested twice produced %d rows, want 1", len(got))+ }+}diff --git a/internal/dashboard/activity_ingest.go b/internal/dashboard/activity_ingest.goindex 48caaabe..2f2b5afd 100644--- a/internal/dashboard/activity_ingest.go+++ b/internal/dashboard/activity_ingest.go@@ -52,7 +52,12 @@ func activityEventToLiveEvent(evt activity.Event) apiTypes.ActivityEvent {}return apiTypes.ActivityEvent{- ID: evt.RequestID,+ // Identity comes from the activity store's composite key, not RequestID:+ // requestIDFor returns the X-Request-Id header or empty and never+ // generates one, so keying on it would give most events a fresh random id+ // per ingest (defeating dedup), while collapsing distinct events that do+ // share a request id.+ ID: activity.EventIdentity(evt),AgentID: agentIDOrAnonymous(evt.AgentID),Channel: "tool_call",Type: classifyActivityType(evt),diff --git a/internal/dashboard/dashboard_test.go b/internal/dashboard/dashboard_test.goindex 0100c581..56411cdc 100644--- a/internal/dashboard/dashboard_test.go+++ b/internal/dashboard/dashboard_test.go@@ -5,6 +5,7 @@ import ("encoding/json""net/http""net/http/httptest"+ "strings""testing""time"@@ -349,8 +350,10 @@ func TestDashboardLoadPersistedAgentActivityRestoresAgentsAndEvents(t *testing.Tif len(events) != 3 {t.Fatalf("RecentEvents() len = %d, want 3", len(events))}- if events[0].ID != "req-1" || events[1].ID != "req-2" || events[2].ID != "req-3" {- t.Fatalf("RecentEvents() IDs = [%s, %s, %s], want [req-1, req-2, req-3]", events[0].ID, events[1].ID, events[2].ID)+ // Identity is the activity store's composite key, so assert on the request+ // id carried in Details rather than on the opaque event ID.+ if got := eventRequestIDs(events); got != "req-1,req-2,req-3" {+ t.Fatalf("RecentEvents() request ids = %s, want req-1,req-2,req-3", got)}}@@ -409,8 +412,8 @@ func TestDashboardIngestPersistedAgentActivityAddsNewEventsWithoutDuplicatingLivif len(events) != 2 {t.Fatalf("RecentEvents() len = %d, want 2", len(events))}- if events[0].ID != "req-live" || events[1].ID != "req-new" {- t.Fatalf("RecentEvents() IDs = [%s, %s], want [req-live, req-new]", events[0].ID, events[1].ID)+ if got := eventRequestIDs(events); got != "req-live,req-new" {+ t.Fatalf("RecentEvents() request ids = %s, want req-live,req-new", got)}agents := d.Agents()@@ -481,3 +484,14 @@ func TestMatchesMode(t *testing.T) {}}}++// eventRequestIDs joins the requestId detail of each event for order-sensitive+// assertions that do not depend on the internal event identity format.+func eventRequestIDs(events []apiTypes.ActivityEvent) string {+ ids := make([]string, 0, len(events))+ for _, evt := range events {+ id, _ := evt.Details["requestId"].(string)+ ids = append(ids, id)+ }+ return strings.Join(ids, ",")+}