The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Work out session sharing from every event and compare against what a share covered
Claude50e464cf03ec
diff --git a/cli/beacon/internal/endpoint/dashboard/events.go b/cli/beacon/internal/endpoint/dashboard/events.goindex 797e19bc..a1c60bfb 100644--- a/cli/beacon/internal/endpoint/dashboard/events.go+++ b/cli/beacon/internal/endpoint/dashboard/events.go@@ -233,7 +233,7 @@ type sessionClassification struct {}func sessionIDsForState(path string, query EventQuery, state string) (map[string]bool, error) {- classifications, err := classifySessions(path, query)+ classifications, _, err := classifySessions(path, query)if err != nil {return nil, err}@@ -249,7 +249,11 @@ func sessionIDsForState(path string, query EventQuery, state string) (map[string// classifySessions assigns one mutually exclusive category to every session active// in the selected time window. Recurrence is computed over that complete set before// any event or session result limit is applied.-func classifySessions(path string, query EventQuery) (map[string]sessionClassification, error) {+//+// It also returns each shared session's sharing state, worked out from every event of the session+// whatever the filters are: a session.shared record outside the selected window or filters still+// marks the session shared, and activity outside them still makes the share stale.+func classifySessions(path string, query EventQuery) (map[string]sessionClassification, map[string]*SessionSharing, error) {// Session state is a property of the whole session, not the filtered slice.// Only the selected time window scopes recurrence. The owner is part of the// recurrence key; content, harness and individual-session filters must not@@ -259,10 +263,19 @@ func classifySessions(path string, query EventQuery) (map[string]sessionClassifiUntil: query.Until,}stats := map[string]*sessionStateStats{}+ sharingAcc := map[string]*sessionAccumulator{}for _, source := range eventSources(path) {- if err := collectSessionStateStats(source, stateQuery, stats); err != nil {- return nil, err+ if err := collectSessionStateStats(source, stateQuery, stats, sharingAcc); err != nil {+ return nil, nil, err+ }+ }+ sharing := map[string]*SessionSharing{}+ for id, acc := range sharingAcc {+ if acc.record.Sharing == nil {+ continue}+ acc.finish()+ sharing[id] = acc.record.Sharing}groupCounts := map[string]int{}groupKeys := map[string]string{}@@ -285,10 +298,10 @@ func classifySessions(path string, query EventQuery) (map[string]sessionClassifi}classifications[id] = classification}- return classifications, nil+ return classifications, sharing, nil}-func collectSessionStateStats(source eventSource, query EventQuery, stats map[string]*sessionStateStats) error {+func collectSessionStateStats(source eventSource, query EventQuery, stats map[string]*sessionStateStats, sharing map[string]*sessionAccumulator) error {file, err := os.Open(source.path)if err != nil {if os.IsNotExist(err) {@@ -321,7 +334,16 @@ func collectSessionStateStats(source eventSource, query EventQuery, stats map[stParsed: parsed,WazuhLevel: WazuhLevel(event.Event.Action),}- if !matchesQuery(record, query) || event.Session == nil || event.Session.ID == "" {+ if event.Session == nil || event.Session.ID == "" {+ continue+ }+ if acc := sharing[event.Session.ID]; acc == nil {+ sharing[event.Session.ID] = &sessionAccumulator{record: SessionRecord{ID: event.Session.ID, Harness: event.Harness.Name}}+ } else if acc.record.Harness == "" {+ acc.record.Harness = event.Harness.Name+ }+ sharing[event.Session.ID].noteSharing(record)+ if !matchesQuery(record, query) {continue}stat := stats[event.Session.ID]diff --git a/cli/beacon/internal/endpoint/dashboard/history_line.go b/cli/beacon/internal/endpoint/dashboard/history_line.goindex 0fb3f994..dc8af105 100644--- a/cli/beacon/internal/endpoint/dashboard/history_line.go+++ b/cli/beacon/internal/endpoint/dashboard/history_line.go@@ -26,6 +26,7 @@ var historyRawKeys = map[string]bool{"remote_title": true,"shared_at": true,"shared_event_count": true,+ "shared_through": true,"shared_url": true,"shared_visibility": true,"sharedUrl": true,diff --git a/cli/beacon/internal/endpoint/dashboard/history_store.go b/cli/beacon/internal/endpoint/dashboard/history_store.goindex ee2609b9..15a10a31 100644--- a/cli/beacon/internal/endpoint/dashboard/history_store.go+++ b/cli/beacon/internal/endpoint/dashboard/history_store.go@@ -41,7 +41,7 @@ const (// historyDerivationVersion covers everything computed from a stored line: trace keys, event// numbers, types, summaries and search text. Bump it when that projection changes; the next// catch-up recomputes it from the stored lines, so history survives the change.- historyDerivationVersion = 5 // 2: trace events carry the event's policy block; 3: and its error; 4: usage carries the 1h cache-write split; 5: sharing goes stale on newer activity and carries a refresh command+ historyDerivationVersion = 6 // 2: trace events carry the event's policy block; 3: and its error; 4: usage carries the 1h cache-write split; 5: sharing goes stale on newer activity and carries a refresh command; 6: staleness compares against what a share covered (shared_through)defaultHistoryRetentionDays = 90// maxHistoryRetentionDays is 100 years: a retention this long or longer means nothing expires.diff --git a/cli/beacon/internal/endpoint/dashboard/history_test.go b/cli/beacon/internal/endpoint/dashboard/history_test.goindex 7b18c695..32947c6b 100644--- a/cli/beacon/internal/endpoint/dashboard/history_test.go+++ b/cli/beacon/internal/endpoint/dashboard/history_test.go@@ -206,7 +206,7 @@ func parityFixture() [][]byte {`{"timestamp":"2026-06-11T15:01:00Z","event":{"id":"h2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"s7"},"raw":{"shared_url":"https://beacon.sh/s/s7trace","visibility":"direct","shared_at":"2026-06-11T15:01:00Z","last_refreshed_at":"2026-06-11T15:01:00Z"}}`,`{"timestamp":"2026-06-11T15:02:00Z","event":{"id":"h3","action":"agent.message","category":"agent"},"harness":{"name":"claude_code","collection_method":"hook"},"session":{"id":"s7"},"message":"later work"}`,`{"timestamp":"2026-06-11T16:00:00Z","event":{"id":"k1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code","collection_method":"hook"},"session":{"id":"s8"},"prompt":{"text":"shared and current"}}`,- `{"timestamp":"2026-06-11T16:01:00Z","event":{"id":"k2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"s8"},"raw":{"shared_url":"https://beacon.sh/s/s8trace","visibility":"private","shared_at":"2026-06-11T16:01:00Z","last_refreshed_at":"2026-06-11T16:01:00Z"}}`,+ `{"timestamp":"2026-06-11T16:01:00Z","event":{"id":"k2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"s8"},"raw":{"shared_url":"https://beacon.sh/s/s8trace","visibility":"private","shared_at":"2026-06-11T16:01:00Z","last_refreshed_at":"2026-06-11T16:01:00Z","shared_through":"2026-06-11T16:00:59Z"}}`,`{"timestamp":"2026-06-11T16:02:00Z","event":{"id":"k3","action":"session.commit_linked","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"s8"},"message":"commit linked"}`,}out := make([][]byte, len(lines))diff --git a/cli/beacon/internal/endpoint/dashboard/sessions.go b/cli/beacon/internal/endpoint/dashboard/sessions.goindex 42ccc6f0..cc60f382 100644--- a/cli/beacon/internal/endpoint/dashboard/sessions.go+++ b/cli/beacon/internal/endpoint/dashboard/sessions.go@@ -77,7 +77,7 @@ type SessionDetail struct {func ReadSessions(path string, query EventQuery) (SessionResult, error) {limit := normalizeLimit(query.Limit)- classifications, err := classifySessions(path, query)+ classifications, sharing, err := classifySessions(path, query)if err != nil {return SessionResult{}, err}@@ -113,6 +113,8 @@ func ReadSessions(path string, query EventQuery) (SessionResult, error) {sessions := make([]SessionRecord, 0, len(byID))for id, acc := range byID {acc.finish()+ // Sharing is a property of the whole session, not of the events the filters kept.+ acc.record.Sharing = sharing[id]if classification := classifications[id]; classification.state == "recurring" {acc.record.IsRecurring = trueacc.record.RecurrenceCount = classification.recurrenceCount@@ -208,8 +210,14 @@ func (acc *sessionAccumulator) noteSharing(record EventRecord) {if v := rawString(event.Raw, "last_refreshed_at"); v != "" {s.LastRefreshedAt = v}- if record.Parsed.After(acc.lastShared) {- acc.lastShared = record.Parsed+ // What the upload covered: the session as read for it (shared_through), or, for a+ // record from before that field, the record's own time.+ covered := record.Parsed+ if through, err := asymptoteobserve.ParseTimestamp(rawString(event.Raw, "shared_through")); err == nil && !through.IsZero() {+ covered = through+ }+ if covered.After(acc.lastShared) {+ acc.lastShared = covered}return}diff --git a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.goindex 307bf452..b6dba31d 100644--- a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go+++ b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go@@ -2,6 +2,7 @@ package dashboardimport ("testing"+ "time")func TestTraceSharingStateAndRefreshCommand(t *testing.T) {@@ -63,3 +64,102 @@ func TestSessionsCarrySharingState(t *testing.T) {t.Fatalf("detail = %+v %v %v", detail.Session.Sharing, ok, err)}}++func sharingLines(lines ...string) [][]byte {+ out := make([][]byte, len(lines))+ for i, l := range lines {+ out[i] = []byte(l)+ }+ return out+}++func sessionSharing(t *testing.T, path string, query EventQuery) map[string]*SessionSharing {+ t.Helper()+ query.Limit = 50+ result, err := ReadSessions(path, query)+ if err != nil {+ t.Fatal(err)+ }+ got := map[string]*SessionSharing{}+ for _, s := range result.Sessions {+ got[s.ID] = s.Sharing+ }+ return got+}++// A session's sharing state comes from all of its events, not the ones the filters kept: a share+// record outside the time range or another model's events still marks it shared, and activity+// outside them still makes the share stale.+func TestSessionSharingIgnoresFilters(t *testing.T) {+ path := newTestLog(t, sharingLines(+ // sh1: shared at 10:01, nothing after.+ `{"timestamp":"2026-06-11T10:00:00Z","event":{"id":"a1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"model":"opus","session":{"id":"sh1"},"prompt":{"text":"one"}}`,+ `{"timestamp":"2026-06-11T10:01:00Z","event":{"id":"a2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"sh1"},"raw":{"shared_url":"https://beacon.sh/s/sh1","visibility":"direct","shared_at":"2026-06-11T10:01:00Z","last_refreshed_at":"2026-06-11T10:01:00Z"}}`,+ // sh2: shared at 10:01, then activity at 12:00 on another model.+ `{"timestamp":"2026-06-11T10:00:00Z","event":{"id":"b1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"model":"opus","session":{"id":"sh2"},"prompt":{"text":"two"}}`,+ `{"timestamp":"2026-06-11T10:01:00Z","event":{"id":"b2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"sh2"},"raw":{"shared_url":"https://beacon.sh/s/sh2","visibility":"direct","shared_at":"2026-06-11T10:01:00Z","last_refreshed_at":"2026-06-11T10:01:00Z"}}`,+ `{"timestamp":"2026-06-11T12:00:00Z","event":{"id":"b3","action":"command.executed","category":"command"},"harness":{"name":"claude_code"},"model":"sonnet","session":{"id":"sh2"}}`,+ ))+ withoutHistory(t)+ for name, query := range map[string]EventQuery{+ "time range": {Since: mustTime(t, "2026-06-11T09:59:00Z"), Until: mustTime(t, "2026-06-11T10:00:30Z")},+ "model": {Model: "opus"},+ "none": {},+ } {+ got := sessionSharing(t, path, query)+ if s := got["sh1"]; s == nil || s.State != "shared" || s.URL != "https://beacon.sh/s/sh1" {+ t.Fatalf("%s: sh1 = %+v, want shared", name, s)+ }+ if s := got["sh2"]; s == nil || s.State != "stale" {+ t.Fatalf("%s: sh2 = %+v, want stale from activity the filter hides", name, s)+ }+ }+}++// A share record says what its upload covered (shared_through, when the session was read): an+// event logged between that read and the record was not uploaded, so the share is stale even+// though the record is newer. A session followed with refreshes after its last events is not.+func TestSharingStalenessUsesSharedThrough(t *testing.T) {+ path := newTestLog(t, sharingLines(+ // st1: read at 10:01, event at 10:01:30 during the upload, record at 10:02.+ `{"timestamp":"2026-06-11T10:00:00Z","event":{"id":"c1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"session":{"id":"st1"},"prompt":{"text":"one"}}`,+ `{"timestamp":"2026-06-11T10:01:30Z","event":{"id":"c2","action":"agent.message","category":"agent"},"harness":{"name":"claude_code"},"session":{"id":"st1"}}`,+ `{"timestamp":"2026-06-11T10:02:00Z","event":{"id":"c3","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"st1"},"raw":{"shared_url":"https://beacon.sh/s/st1","visibility":"direct","shared_at":"2026-06-11T10:02:00Z","last_refreshed_at":"2026-06-11T10:02:00Z","shared_through":"2026-06-11T10:01:00Z"}}`,+ // st2: followed; each upload's refresh covers the events before it.+ `{"timestamp":"2026-06-11T11:00:00Z","event":{"id":"d1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"session":{"id":"st2"},"prompt":{"text":"two"}}`,+ `{"timestamp":"2026-06-11T11:00:05Z","event":{"id":"d2","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"st2"},"raw":{"shared_url":"https://beacon.sh/s/st2","visibility":"direct","shared_at":"2026-06-11T11:00:05Z","last_refreshed_at":"2026-06-11T11:00:05Z","shared_through":"2026-06-11T11:00:04Z"}}`,+ `{"timestamp":"2026-06-11T11:00:20Z","event":{"id":"d3","action":"agent.message","category":"agent"},"harness":{"name":"claude_code"},"session":{"id":"st2"}}`,+ `{"timestamp":"2026-06-11T11:00:31Z","event":{"id":"d4","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"st2"},"raw":{"shared_url":"https://beacon.sh/s/st2","visibility":"direct","last_refreshed_at":"2026-06-11T11:00:31Z","shared_through":"2026-06-11T11:00:30Z"}}`,+ ))+ withoutHistory(t)+ got := sessionSharing(t, path, EventQuery{})+ if s := got["st1"]; s == nil || s.State != "stale" {+ t.Fatalf("st1 = %+v, want stale: an event came in during the upload", s)+ }+ if s := got["st2"]; s == nil || s.State != "shared" {+ t.Fatalf("st2 = %+v, want shared: the follow's refresh covered every event", s)+ }+ list, err := ReadTraceList(path, TraceQuery{Limit: 50})+ if err != nil {+ t.Fatal(err)+ }+ byID := map[string]TraceSummaryV1{}+ for _, trace := range list.Traces {+ byID[trace.ID] = trace+ }+ if s := byID["session:claude_code:st1"].Sharing.State; s != "stale" {+ t.Fatalf("trace st1 sharing = %q, want stale", s)+ }+ if s := byID["session:claude_code:st2"].Sharing.State; s != "shared" {+ t.Fatalf("trace st2 sharing = %q, want shared", s)+ }+}++func mustTime(t *testing.T, s string) time.Time {+ t.Helper()+ v, err := time.Parse(time.RFC3339, s)+ if err != nil {+ t.Fatal(err)+ }+ return v+}diff --git a/cli/beacon/internal/endpoint/dashboard/traces.go b/cli/beacon/internal/endpoint/dashboard/traces.goindex 2dbd9798..b7ed5d76 100644--- a/cli/beacon/internal/endpoint/dashboard/traces.go+++ b/cli/beacon/internal/endpoint/dashboard/traces.go@@ -67,8 +67,8 @@ type traceAggregate struct {methods map[string]booltitlePriority int// lastActivity is the newest timestamp of an event the session itself produced, and- // lastShareRecord the newest session.shared record's; a shared trace whose session has- // activity after its last share or refresh is stale.+ // lastShareRecord the newest point a session.shared record covered (its shared_through, else+ // its timestamp); a shared trace whose session has activity after that is stale.lastActivity stringlastShareRecord string}@@ -388,7 +388,9 @@ func (a *traceAggregate) update(event schema.Event, traceEvent TraceEventV1) {a.updateRawMetadata(event.Raw)switch {case event.Event.Action == "session.shared":- a.lastShareRecord = laterTimestamp(a.lastShareRecord, event.Timestamp)+ // What the upload covered (shared_through, when the session was read for it), or the+ // record's own time for a record from before that field.+ a.lastShareRecord = laterTimestamp(a.lastShareRecord, firstNonEmpty(rawString(event.Raw, "shared_through"), event.Timestamp))case !shareBookkeeping(event.Event.Action):a.lastActivity = laterTimestamp(a.lastActivity, event.Timestamp)}