Skip to content

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

Never let an event the share projection skips make a share stale

Claude556a9753b3e6
diff --git a/cli/beacon/internal/endpoint/dashboard/history_store.go b/cli/beacon/internal/endpoint/dashboard/history_store.go
index a34a41a8..0b375953 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 = 9 // 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; 8: only when the session holds the share call; 9: and the turn-end event after it
+ historyDerivationVersion = 10 // 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; 8: only when the session holds the share call; 9: and the turn-end event after it; 10: events the share projection skips never count
defaultHistoryRetentionDays = 90
// maxHistoryRetentionDays is 100 years: a retention this long or longer means nothing expires.
diff --git a/cli/beacon/internal/endpoint/dashboard/share_activity.go b/cli/beacon/internal/endpoint/dashboard/share_activity.go
index 607e5c54..c57652fe 100644
--- a/cli/beacon/internal/endpoint/dashboard/share_activity.go
+++ b/cli/beacon/internal/endpoint/dashboard/share_activity.go
@@ -52,6 +52,12 @@ func (s *shareActivity) counts(event schema.Event) bool {
if shareBookkeeping(action) {
return false
}
+ // An event the share projection would not upload (status and idle lifecycle, metrics,
+ // token-only telemetry, ...) cannot make the shared trace out of date: a refresh would send
+ // nothing for it.
+ if !asymptoteobserve.ShareProjects(event) {
+ return false
+ }
callID := asymptoteobserve.ToolCallID(&event)
promptID := asymptoteobserve.PromptID(&event)
if isShareCallEvent(event) {
@@ -96,7 +102,7 @@ func isShareCallEvent(event schema.Event) bool {
// file payload) and the plugin runtimes' agent.response / agent.response.completed.
func isAssistantOutput(event schema.Event) bool {
switch event.Event.Action {
- case "agent.message", "agent.reasoning", "token.usage", "agent.response", "agent.response.completed":
+ case "agent.message", "agent.reasoning", "agent.response", "agent.response.completed":
return true
case "tool.completed":
return isPayloadlessTurnEnd(event)
diff --git a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
index 480f04d4..6732f0da 100644
--- a/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/sharing_view_test.go
@@ -331,3 +331,39 @@ func TestStateSharedIncludesStale(t *testing.T) {
optIn(t, path)
check("history")
}
+
+// OpenCode ends a turn with agent.response and an idle session.status. Neither makes a share run
+// from inside the session stale (the projection skips status events, so a refresh would send
+// nothing); a later real tool call does.
+func TestOpenCodeShareFromInsideTheSessionIsNotStale(t *testing.T) {
+ inside := []string{
+ `{"timestamp":"2026-06-11T10:00:00Z","event":{"id":"q1","action":"prompt.submitted","category":"prompt"},"harness":{"name":"opencode","collection_method":"plugin"},"session":{"id":"oc1"},"prompt":{"text":"share this session"}}`,
+ `{"timestamp":"2026-06-11T10:00:05Z","event":{"id":"q2","action":"command.invoked","category":"command"},"harness":{"name":"opencode","collection_method":"plugin"},"session":{"id":"oc1"},"command":{"command":"beacon share --current --harness opencode --json"},"gen_ai":{"tool":{"call":{"id":"oc-call"}}}}`,
+ `{"timestamp":"2026-06-11T10:00:09Z","event":{"id":"q3","action":"session.shared","category":"session","fidelity":"inferred"},"harness":{"name":"opencode"},"session":{"id":"oc1"},"raw":{"shared_url":"https://beacon.sh/s/oc1","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:12Z","event":{"id":"q4","action":"agent.response","category":"session"},"harness":{"name":"opencode","collection_method":"plugin"},"session":{"id":"oc1"},"message":"opencode assistant response captured"}`,
+ `{"timestamp":"2026-06-11T10:00:13Z","event":{"id":"q5","action":"session.status","category":"session"},"harness":{"name":"opencode","collection_method":"plugin"},"session":{"id":"oc1"},"message":"idle"}`,
+ }
+ check := func(t *testing.T, lines []string, want string) {
+ t.Helper()
+ path := newTestLog(t, sharingLines(lines...))
+ withoutHistory(t)
+ if s := sessionSharing(t, path, EventQuery{})["oc1"]; 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:opencode:oc1" && trace.Sharing.State != want {
+ t.Fatalf("trace sharing = %+v, want %s", trace.Sharing, want)
+ }
+ }
+ }
+ t.Run("share, reply and idle", 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:04:00Z","event":{"id":"q6","action":"tool.invoked","category":"tool"},"harness":{"name":"opencode","collection_method":"plugin"},"session":{"id":"oc1"},"tool":{"name":"edit","path":"main.go"},"gen_ai":{"tool":{"call":{"id":"oc-edit"}}}}`,
+ ), "stale")
+ })
+}
diff --git a/pkg/asymptoteobserve/share.go b/pkg/asymptoteobserve/share.go
index 69a0264f..23301574 100644
--- a/pkg/asymptoteobserve/share.go
+++ b/pkg/asymptoteobserve/share.go
@@ -577,6 +577,14 @@ const (
shareError
)
+// ShareProjects reports whether BuildShareMessages considers event at all: false for the events it
+// always skips (Beacon's own share records, metrics, inventory, health, token-only telemetry, idle
+// and status lifecycle, tool listings). An event it rejects never yields a message, so local views
+// use it to decide that such an event cannot make a shared trace out of date.
+func ShareProjects(event Event) bool {
+ return classifyShareEvent(event) != shareSkip
+}
+
func classifyShareEvent(event Event) shareEventClass {
action := strings.ToLower(strings.TrimSpace(event.Event.Action))
category := strings.ToLower(strings.TrimSpace(event.Event.Category))
diff --git a/pkg/asymptoteobserve/share_test.go b/pkg/asymptoteobserve/share_test.go
index edb8200f..ab070415 100644
--- a/pkg/asymptoteobserve/share_test.go
+++ b/pkg/asymptoteobserve/share_test.go
@@ -616,3 +616,46 @@ func TestBuildShareMessagesPairsPromptCapturesOnlyAcrossPaths(t *testing.T) {
t.Fatalf("unrelated prompts merged: %+v", got)
}
}
+
+// ShareProjects agrees with BuildShareMessages: every event it rejects yields no message, even with
+// content that would otherwise be shared, and the events it accepts are the ones the projection
+// writes.
+func TestShareProjectsAgreesWithBuildShareMessages(t *testing.T) {
+ withText := func(e Event) Event {
+ e.Message = "something happened"
+ e.Prompt = &PromptInfo{Text: "a prompt-shaped field"}
+ e.GenAI = &GenAIInfo{Output: &GenAIOutputInfo{Messages: TextOutputMessages("assistant-shaped text")}}
+ return e
+ }
+ rejected := []Event{
+ shareEventAt("2026-10-01T10:00:00Z", "opencode", "plugin", "session.status", "session"),
+ shareEventAt("2026-10-01T10:00:01Z", "opencode", "plugin", "session.idle", "session"),
+ shareEventAt("2026-10-01T10:00:02Z", "claude_code", "hook", "session.activity", "session"),
+ shareEventAt("2026-10-01T10:00:03Z", "claude_code", "hook", "session.lock", "session"),
+ shareEventAt("2026-10-01T10:00:04Z", "claude_code", "otlp", "token.usage", "model"),
+ shareEventAt("2026-10-01T10:00:05Z", "claude_code", "otlp", "metric.point", "metric"),
+ shareEventAt("2026-10-01T10:00:06Z", "claude_code", "", "session.shared", "session"),
+ shareEventAt("2026-10-01T10:00:07Z", "claude_code", "", "session.share_requested", "session"),
+ shareEventAt("2026-10-01T10:00:08Z", "cursor", "hook", "mcp.tool_listed", "mcp"),
+ }
+ for _, e := range rejected {
+ if ShareProjects(e) {
+ t.Fatalf("ShareProjects(%s) = true, want false", e.Event.Action)
+ }
+ if got := BuildShareMessagesWithOptions([]Event{withText(e)}, shareTestOpts); len(got) != 0 {
+ t.Fatalf("%s: ShareProjects rejects it, but BuildShareMessages wrote %d message(s)", e.Event.Action, len(got))
+ }
+ }
+ prompt := shareEventAt("2026-10-01T10:01:00Z", "claude_code", "hook", "prompt.submitted", "prompt")
+ prompt.Prompt = &PromptInfo{Text: "fix the bug"}
+ reply := shareEventAt("2026-10-01T10:01:05Z", "claude_code", "hook", "agent.message", "agent")
+ reply.GenAI = &GenAIInfo{Output: &GenAIOutputInfo{Messages: TextOutputMessages("done")}}
+ for _, e := range []Event{prompt, reply} {
+ if !ShareProjects(e) {
+ t.Fatalf("ShareProjects(%s) = false, want true", e.Event.Action)
+ }
+ if got := BuildShareMessagesWithOptions([]Event{e}, shareTestOpts); len(got) != 1 {
+ t.Fatalf("%s: ShareProjects accepts it, but BuildShareMessages wrote %d message(s)", e.Event.Action, len(got))
+ }
+ }
+}