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
Keep the share date when a shared trace is shared again
Claudeb541b0285e82
diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.goindex dbbf0c70..cfb04856 100644--- a/cli/beacon/cmd/share.go+++ b/cli/beacon/cmd/share.go@@ -159,6 +159,9 @@ type shareResult struct {EventCount int `json:"event_count"`// Uploaded is how many events this run sent; on a first share it equals the trace's count.Uploaded int `json:"uploaded"`+ // sharedAt is when beacon.sh created the trace, for a refresh or re-share to record as the+ // share date (empty when unknown).+ sharedAt string}// sharePayload is what --print shows: the external id the requests go to, the body of the PUT@@ -213,9 +216,11 @@ func runShare(cmd *cobra.Command) error {fmt.Fprintf(errOut, "Sharing %s session %s (%d events)%s.\n", subject.session.Harness, subject.session.ID, len(payload.Events), shareSourceNote(subject))}ctx := commandContext(cmd)- if state, found, err := client.GetTrace(ctx, payload.ExternalID); err != nil {+ state, found, err := client.GetTrace(ctx, payload.ExternalID)+ if err != nil {return err- } else if found {+ }+ if found {if subject, payload, err = alignShareSource(subject, payload, state); err != nil {return err}@@ -244,7 +249,11 @@ func runShare(cmd *cobra.Command) error {if uploaded.Batches == 0 {result.EventCount = trace.EventCount}- if err := recordShareEvent(subject.session, result, false); err != nil {+ // Sharing a trace that already exists updates it: the share date stays the trace's own.+ if found {+ result.sharedAt = state.CreatedAt+ }+ if err := recordShareEvent(subject.session, result, found); err != nil {fmt.Fprintf(errOut, "warning: the session was shared, but the runtime log was not updated: %v\n", err)}return printShareResult(cmd, result)@@ -318,6 +327,7 @@ func runShareRefresh(cmd *cobra.Command, args []string) error {if uploaded.Batches > 0 {result.EventCount = uploaded.EventCount}+ result.sharedAt = state.CreatedAtif err := recordShareEvent(subject.session, result, true); err != nil {fmt.Fprintf(cmd.ErrOrStderr(), "warning: the trace was refreshed, but the runtime log was not updated: %v\n", err)}@@ -839,6 +849,10 @@ func shareRecordEvent(session handoff.Session, result shareResult, refresh bool,}if !refresh {event.Raw["shared_at"] = stamp+ } else if created, err := time.Parse(time.RFC3339Nano, strings.TrimSpace(result.sharedAt)); err == nil {+ // A refresh keeps the share date: the trace's creation on beacon.sh, which also stands in+ // for a first record that has rotated out of the log.+ event.Raw["shared_at"] = created.UTC().Format(time.RFC3339)}return event}diff --git a/cli/beacon/cmd/share_test.go b/cli/beacon/cmd/share_test.goindex 7b8329e0..cfc8d405 100644--- a/cli/beacon/cmd/share_test.go+++ b/cli/beacon/cmd/share_test.go@@ -253,6 +253,7 @@ type fakeShareServer struct {server *httptest.Servertrace *asymptoteobserve.ShareTraceV1events []asymptoteobserve.TraceEventV1+ created stringrequests []stringauth map[string]bool}@@ -279,6 +280,10 @@ func newFakeShareServer(t *testing.T) *fakeShareServer {if trace.Visibility == "" {trace.Visibility = "direct"}+ if created {+ // beacon.sh stamps the trace when it creates it; the test clock stands in for it.+ f.created = shareNow().UTC().Format(time.RFC3339)+ }f.trace = &tracefmt.Fprintf(w, `{"id":"k3xabc","external_id":%q,"url":"https://beacon.sh/s/k3xabc","visibility":%q,"event_count":%d,"created":%v}`, id, trace.Visibility, len(f.events), created)case r.Method == http.MethodPost && strings.HasSuffix(id, "/events/batch"):@@ -313,7 +318,7 @@ func newFakeShareServer(t *testing.T) *fakeShareServer {last, maxNumber = e.ID, e.Number}}- fmt.Fprintf(w, `{"id":"k3xabc","url":"https://beacon.sh/s/k3xabc","visibility":%q,"event_count":%d,"last_event_id":%q,"max_number":%d}`, f.trace.Visibility, len(f.events), last, maxNumber)+ fmt.Fprintf(w, `{"id":"k3xabc","url":"https://beacon.sh/s/k3xabc","visibility":%q,"event_count":%d,"last_event_id":%q,"max_number":%d,"created_at":%q}`, f.trace.Visibility, len(f.events), last, maxNumber, f.created)default:http.NotFound(w, r)}@@ -712,3 +717,43 @@ func TestShareRefusesAnAmbiguousPrefix(t *testing.T) {t.Fatalf("requests = %v", srv.requests)}}++func TestShareAgainKeepsTheShareDate(t *testing.T) {+ env := newShareEnv(t)+ srv := newFakeShareServer(t)+ srv.signIn(account.ScopeTracesWrite)+ first := time.Date(2026, 10, 2, 9, 0, 0, 0, time.UTC)+ shareNow = func() time.Time { return first }+ t.Cleanup(func() { shareNow = time.Now })+ if _, stderr, err := runShareCommand(t, "--cwd", env.projectDir, "--log-path", env.logPath); err != nil {+ t.Fatalf("share: %v\n%s", err, stderr)+ }+ later := first.Add(3 * time.Hour)+ shareNow = func() time.Time { return later }+ if _, stderr, err := runShareCommand(t, "--cwd", env.projectDir, "--log-path", env.logPath); err != nil {+ t.Fatalf("share again: %v\n%s", err, stderr)+ }+ list, err := dashboard.ReadTraceList(env.logPath, dashboard.TraceQuery{State: "shared"})+ if err != nil {+ t.Fatal(err)+ }+ if len(list.Traces) != 1 {+ t.Fatalf("shared traces = %+v", list.Traces)+ }+ sharing := list.Traces[0].Sharing+ if sharing.SharedAt != first.Format(time.RFC3339) || sharing.LastRefreshedAt != later.Format(time.RFC3339) {+ t.Fatalf("sharing = %+v, want shared_at %s and last_refreshed_at %s", sharing, first.Format(time.RFC3339), later.Format(time.RFC3339))+ }+ data, err := os.ReadFile(env.logPath)+ if err != nil {+ t.Fatal(err)+ }+ lines := strings.Split(strings.TrimSpace(string(data)), "\n")+ var second schema.Event+ if err := json.Unmarshal([]byte(lines[len(lines)-1]), &second); err != nil {+ t.Fatal(err)+ }+ if second.Raw["shared_at"] != first.Format(time.RFC3339) || !strings.Contains(second.Message, "refreshed") {+ t.Fatalf("second record = %q %+v", second.Message, second.Raw)+ }+}