Skip to content

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

Do not let a share's own events make a session shared from inside itself stale

Claude47a07a3b5abb
diff --git a/cli/beacon/internal/endpoint/dashboard/history_ingest.go b/cli/beacon/internal/endpoint/dashboard/history_ingest.go
index 484fa86e..c3290e09 100644
--- a/cli/beacon/internal/endpoint/dashboard/history_ingest.go
+++ b/cli/beacon/internal/endpoint/dashboard/history_ingest.go
@@ -805,6 +805,7 @@ type traceAggregateState struct {
TitlePriority int `json:"title_priority"`
LastActivity string `json:"last_activity,omitempty"`
LastShareRecord string `json:"last_share_record,omitempty"`
+ Share shareActivity `json:"share,omitempty"`
}
func (a *traceAggregate) state() traceAggregateState {
@@ -815,6 +816,7 @@ func (a *traceAggregate) state() traceAggregateState {
TitlePriority: a.titlePriority,
LastActivity: a.lastActivity,
LastShareRecord: a.lastShareRecord,
+ Share: a.share,
}
}
@@ -831,6 +833,7 @@ func decodeTraceAggregate(raw string) (*traceAggregate, error) {
titlePriority: state.TitlePriority,
lastActivity: state.LastActivity,
lastShareRecord: state.LastShareRecord,
+ share: state.Share,
}
for _, model := range state.Models {
agg.models[model] = true
diff --git a/cli/beacon/internal/endpoint/dashboard/history_store.go b/cli/beacon/internal/endpoint/dashboard/history_store.go
index 15a10a31..4c51245d 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 = 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)
+ historyDerivationVersion = 7 // 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); 7: a share's own events (its command, the reply about it) do not make it stale
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.go
index 32947c6b..61021e98 100644
--- a/cli/beacon/internal/endpoint/dashboard/history_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/history_test.go
@@ -204,7 +204,7 @@ func parityFixture() [][]byte {
// its last activity, and the commit link after that does not make it stale.
`{"timestamp":"2026-06-11T15:00:00Z","event":{"id":"h1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code","collection_method":"hook"},"session":{"id":"s7"},"prompt":{"text":"share me"}}`,
`{"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-11T15:02:00Z","event":{"id":"h3","action":"command.executed","category":"command"},"harness":{"name":"claude_code","collection_method":"hook"},"session":{"id":"s7"},"command":{"command":"go test ./..."},"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","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"}`,
diff --git a/cli/beacon/internal/endpoint/dashboard/sessions.go b/cli/beacon/internal/endpoint/dashboard/sessions.go
index cc60f382..4db678e4 100644
--- a/cli/beacon/internal/endpoint/dashboard/sessions.go
+++ b/cli/beacon/internal/endpoint/dashboard/sessions.go
@@ -185,12 +185,14 @@ type sessionAccumulator struct {
// lastActivity and lastShared drive SessionSharing.State: see traceAggregate.
lastActivity time.Time
lastShared time.Time
+ share shareActivity
}
// noteSharing reads a session.shared record, and otherwise notes when the session last did
// something of its own.
func (acc *sessionAccumulator) noteSharing(record EventRecord) {
event := record.Event
+ counts := acc.share.counts(event)
if event.Event.Action == "session.shared" {
url := rawString(event.Raw, "shared_url")
if url == "" {
@@ -221,7 +223,7 @@ func (acc *sessionAccumulator) noteSharing(record EventRecord) {
}
return
}
- if !shareBookkeeping(event.Event.Action) && record.Parsed.After(acc.lastActivity) {
+ if counts && record.Parsed.After(acc.lastActivity) {
acc.lastActivity = record.Parsed
}
}
diff --git a/cli/beacon/internal/endpoint/dashboard/share_activity.go b/cli/beacon/internal/endpoint/dashboard/share_activity.go
new file mode 100644
index 00000000..0a8bba56
--- /dev/null
+++ b/cli/beacon/internal/endpoint/dashboard/share_activity.go
@@ -0,0 +1,103 @@
+package dashboard
+
+import (
+ "regexp"
+ "strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
+)
+
+// shareActivity decides which of a session's events count as activity that makes its shared trace
+// stale. Besides Beacon's own bookkeeping, a share made from inside the session is followed by
+// events about the share itself: the runtime's events for the `beacon share` command (its call and
+// its completion, matched by gen_ai.tool.call.id) and the agent's reply about it. Counting those
+// would leave a session shared or refreshed from inside itself stale forever. Anything else -- a
+// new prompt, another tool call, a file write, a command that is not the share -- still counts.
+//
+// It is state carried across a session's events in log order, so the trace projection persists it
+// with the rest of its running state (traceAggregateState).
+type shareActivity struct {
+ // ShareCalls are the tool call ids of `beacon share` invocations.
+ ShareCalls map[string]bool `json:"share_calls,omitempty"`
+ // SharePrompts are the turns (prompt.id) that ran `beacon share`.
+ SharePrompts map[string]bool `json:"share_prompts,omitempty"`
+ // QuietSinceShare is true from a session.shared record until the next event that counts.
+ QuietSinceShare bool `json:"quiet_since_share,omitempty"`
+}
+
+// beaconShareCommand matches a shell command that runs `beacon share`, with any subcommand or
+// flags, as a whole word (`beacon share`, `/opt/beacon/bin/beacon share refresh ...`, `x && beacon
+// share --current`).
+var beaconShareCommand = regexp.MustCompile(`(^|[\s/;&|(` + "`" + `'"])beacon(\.exe)?\s+share(\s|$|[;&|)'"])`)
+
+func isBeaconShareCommand(command string) bool {
+ return command != "" && beaconShareCommand.MatchString(command)
+}
+
+// counts reports whether event is activity that makes a share stale, and updates the state.
+func (s *shareActivity) counts(event schema.Event) bool {
+ action := event.Event.Action
+ if action == "session.shared" {
+ s.QuietSinceShare = true
+ return false
+ }
+ if shareBookkeeping(action) {
+ return false
+ }
+ callID := asymptoteobserve.ToolCallID(&event)
+ promptID := asymptoteobserve.PromptID(&event)
+ if isShareCallEvent(event) {
+ if callID != "" {
+ if s.ShareCalls == nil {
+ s.ShareCalls = map[string]bool{}
+ }
+ s.ShareCalls[callID] = true
+ }
+ if promptID != "" {
+ if s.SharePrompts == nil {
+ s.SharePrompts = map[string]bool{}
+ }
+ s.SharePrompts[promptID] = true
+ }
+ return false
+ }
+ if callID != "" && s.ShareCalls[callID] {
+ return false // the share call's completion, which may not repeat the command
+ }
+ if isAssistantOutput(event) {
+ if s.QuietSinceShare || (promptID != "" && s.SharePrompts[promptID]) {
+ return false
+ }
+ return true
+ }
+ s.QuietSinceShare = false
+ return true
+}
+
+func isShareCallEvent(event schema.Event) bool {
+ if event.Command != nil && isBeaconShareCommand(event.Command.Command) {
+ return true
+ }
+ return event.Tool != nil && isBeaconShareCommand(event.Tool.Command)
+}
+
+// isAssistantOutput is an event that only carries the agent's own output or what it cost: no
+// prompt, tool call, command or file activity.
+func isAssistantOutput(event schema.Event) bool {
+ switch event.Event.Action {
+ case "agent.message", "agent.reasoning", "token.usage":
+ return true
+ }
+ if event.Command != nil || event.Tool != nil || event.File != nil || event.MCP != nil {
+ return false
+ }
+ if event.Prompt != nil && strings.TrimSpace(event.Prompt.Text) != "" {
+ return false
+ }
+ switch event.Event.Category {
+ case "prompt", "tool", "command", "file", "mcp", "approval":
+ return false
+ }
+ return event.GenAI != nil && event.GenAI.Usage != nil
+}
diff --git a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
index b6dba31d..ee53e199 100644
--- a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
@@ -163,3 +163,45 @@ func mustTime(t *testing.T, s string) time.Time {
}
return v
}
+
+// A share made from inside the session is followed by the runtime's events for the `beacon share`
+// command and the agent's reply about it; those do not make it stale. A later unrelated tool call
+// does.
+func TestShareFromInsideTheSessionIsNotStale(t *testing.T) {
+ inside := []string{
+ `{"timestamp":"2026-06-11T10:00:00Z","event":{"id":"e1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1","text":"share this session"}}`,
+ `{"timestamp":"2026-06-11T10:00:05Z","event":{"id":"e2","action":"tool.invoked","category":"tool"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1"},"tool":{"name":"Bash","command":"beacon share --current"},"gen_ai":{"tool":{"call":{"id":"call-share"}}}}`,
+ `{"timestamp":"2026-06-11T10:00:09Z","event":{"id":"e3","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"raw":{"shared_url":"https://beacon.sh/s/in1","visibility":"direct","shared_at":"2026-06-11T10:00:09Z","last_refreshed_at":"2026-06-11T10:00:09Z","shared_through":"2026-06-11T10:00:06Z"}}`,
+ `{"timestamp":"2026-06-11T10:00:10Z","event":{"id":"e4","action":"tool.completed","category":"tool"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1"},"tool":{"name":"Bash"},"gen_ai":{"tool":{"call":{"id":"call-share"}}}}`,
+ `{"timestamp":"2026-06-11T10:00:11Z","event":{"id":"e5","action":"command.executed","category":"command"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1"},"command":{"command":"beacon share --current"}}`,
+ `{"timestamp":"2026-06-11T10:00:15Z","event":{"id":"e6","action":"agent.message","category":"agent"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1"},"message":"Shared: https://beacon.sh/s/in1"}`,
+ }
+ check := func(t *testing.T, lines []string, want string) {
+ t.Helper()
+ path := newTestLog(t, sharingLines(lines...))
+ withoutHistory(t)
+ if s := sessionSharing(t, path, EventQuery{})["in1"]; s == nil || s.State != want {
+ t.Fatalf("session sharing = %+v, want %s", s, want)
+ }
+ list, err := ReadTraceList(path, TraceQuery{Limit: 50})
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, trace := range list.Traces {
+ if trace.ID == "session:claude_code:in1" && trace.Sharing.State != want {
+ t.Fatalf("trace sharing = %+v, want %s", trace.Sharing, want)
+ }
+ }
+ }
+ t.Run("share and its reply", func(t *testing.T) { check(t, inside, "shared") })
+ t.Run("later tool call", func(t *testing.T) {
+ check(t, append(append([]string{}, inside...),
+ `{"timestamp":"2026-06-11T10:05:00Z","event":{"id":"e7","action":"tool.invoked","category":"tool"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p1"},"tool":{"name":"Edit","path":"main.go"},"gen_ai":{"tool":{"call":{"id":"call-edit"}}}}`,
+ ), "stale")
+ })
+ t.Run("reply after later work", func(t *testing.T) {
+ check(t, append(append([]string{}, inside...),
+ `{"timestamp":"2026-06-11T10:05:00Z","event":{"id":"e8","action":"prompt.submitted","category":"prompt"},"harness":{"name":"claude_code"},"session":{"id":"in1"},"prompt":{"id":"p2","text":"now fix the bug"}}`,
+ ), "stale")
+ })
+}
diff --git a/cli/beacon/internal/endpoint/dashboard/traces.go b/cli/beacon/internal/endpoint/dashboard/traces.go
index b7ed5d76..41ad03a3 100644
--- a/cli/beacon/internal/endpoint/dashboard/traces.go
+++ b/cli/beacon/internal/endpoint/dashboard/traces.go
@@ -71,6 +71,8 @@ type traceAggregate struct {
// its timestamp); a shared trace whose session has activity after that is stale.
lastActivity string
lastShareRecord string
+ // share tells the share's own events (a share made from inside the session) from activity.
+ share shareActivity
}
// shareBookkeeping is an event Beacon writes into a session's timeline about the session, rather
@@ -386,12 +388,12 @@ func (a *traceAggregate) update(event schema.Event, traceEvent TraceEventV1) {
}
updateContentSummary(&a.summary.Content, event.Content)
a.updateRawMetadata(event.Raw)
- switch {
- case event.Event.Action == "session.shared":
+ if event.Event.Action == "session.shared" {
// 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):
+ }
+ if a.share.counts(event) {
a.lastActivity = laterTimestamp(a.lastActivity, event.Timestamp)
}
}