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 an existing trace's title and record what each upload covered
Clauded173f5ef0bb0
diff --git a/cli/beacon/cmd/git_share_sessions_test.go b/cli/beacon/cmd/git_share_sessions_test.goindex bee9f62c..07364e60 100644--- a/cli/beacon/cmd/git_share_sessions_test.go+++ b/cli/beacon/cmd/git_share_sessions_test.go@@ -203,3 +203,42 @@ func TestGitPrePushWithoutTheBlockLeavesStdinAlone(t *testing.T) {t.Fatalf("remote note %q, want the session shared from HEAD", note)}}++// Pre-push sharing to a trace that already exists keeps the title set on it earlier (with --title+// or a rename on beacon.sh) and its visibility.+func TestGitPrePushKeepsAnExistingTracesTitle(t *testing.T) {+ root, remote := gitCommandTeam(t)+ env := newShareEnv(t)+ srv := newFakeShareServer(t)+ srv.signIn(account.ScopeTracesWrite)+ // Shared from elsewhere (another log, so this machine's log has no record of it), titled.+ elsewhere := filepath.Join(t.TempDir(), "other.jsonl")+ if _, stderr, err := runShareCommand(t, "--cwd", env.projectDir, "--title", "Login fix", "--visibility", "private", "--log-path", elsewhere); err != nil {+ t.Fatalf("share: %v\n%s", err, stderr)+ }+ prevOpts := shareOpts+ shareOpts = shareOptions{logPath: env.logPath}+ t.Cleanup(func() { shareOpts = prevOpts })+ t.Setenv(gitlink.HookStdinEnv, "1")++ old := mustGit(t, root, "rev-parse", "HEAD")+ mustGit(t, root, "commit", "-q", "--allow-empty", "-m", "agent work")+ sha := mustGit(t, root, "rev-parse", "HEAD")+ mustGit(t, root, "notes", "--ref="+gitlink.NotesRef, "add", "-m", "beacon:claude_code/"+shareTestSession, sha)+ if _, err := runGit(t, "setup", "--cwd", root, "--share-sessions"); err != nil {+ t.Fatal(err)+ }+ rootCmd.SetIn(strings.NewReader("refs/heads/main " + sha + " refs/heads/main " + old + "\n"))+ t.Cleanup(func() { rootCmd.SetIn(nil) })+ var stderr bytes.Buffer+ before := len(srv.requests)+ if _, err := runGitStderr(t, &stderr, "hook", "pre-push", "--cwd", root, "origin", remote); err != nil || stderr.Len() != 0 {+ t.Fatalf("pre-push: %v %q", err, stderr.String())+ }+ if len(srv.requests) == before {+ t.Fatal("pre-push made no share request")+ }+ if srv.trace.Title != "Login fix" || srv.trace.Visibility != "private" {+ t.Fatalf("trace title %q visibility %q, want the ones set earlier", srv.trace.Title, srv.trace.Visibility)+ }+}diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.goindex c85af78d..ce441df3 100644--- a/cli/beacon/cmd/share.go+++ b/cli/beacon/cmd/share.go@@ -181,6 +181,10 @@ type shareResult struct {Uploaded int `json:"uploaded"`// SelectedBy says how the session was chosen: session, source_path, env, active or recent.SelectedBy string `json:"selected_by,omitempty"`+ // SharedThrough is when the session was read for this upload: an event logged after it was+ // not sent, however soon the upload finished. The session.shared record carries it as+ // shared_through, which is what the dashboard compares later activity against.+ SharedThrough time.Time `json:"-"`}// sharePayload is what --print shows: the trace metadata of the PUT request and every message the@@ -208,6 +212,7 @@ func runShare(cmd *cobra.Command) error {if err != nil {return err}+ readAt := shareNow()payload, err := buildSharePayload(subject)if err != nil {return err@@ -252,14 +257,15 @@ func runShare(cmd *cobra.Command) error {return fmt.Errorf("the trace was created at %s, but uploading its messages failed (run the same command again to retry): %w", trace.URL, err)}result := shareResult{- TraceID: trace.ID,- ExternalID: payload.ExternalID,- SharedURL: trace.URL,- Visibility: trace.Visibility,- AgentID: payload.Trace.AgentID,- MessageCount: uploaded.MessageCount,- Uploaded: len(payload.Messages),- SelectedBy: subject.selectedBy,+ TraceID: trace.ID,+ ExternalID: payload.ExternalID,+ SharedURL: trace.URL,+ Visibility: trace.Visibility,+ AgentID: payload.Trace.AgentID,+ MessageCount: uploaded.MessageCount,+ Uploaded: len(payload.Messages),+ SelectedBy: subject.selectedBy,+ SharedThrough: readAt,}if uploaded.Batches == 0 {result.MessageCount = trace.MessageCount@@ -294,6 +300,7 @@ func runShareRefresh(cmd *cobra.Command, args []string) error {if err != nil {return err}+ readAt := shareNow()payload, err := buildSharePayload(subject)if err != nil {return err@@ -327,14 +334,15 @@ func runShareRefresh(cmd *cobra.Command, args []string) error {return err}result := shareResult{- TraceID: trace.ID,- ExternalID: payload.ExternalID,- SharedURL: trace.URL,- Visibility: trace.Visibility,- AgentID: payload.Trace.AgentID,- MessageCount: state.MessageCount,- Uploaded: len(pending),- SelectedBy: subject.selectedBy,+ TraceID: trace.ID,+ ExternalID: payload.ExternalID,+ SharedURL: trace.URL,+ Visibility: trace.Visibility,+ AgentID: payload.Trace.AgentID,+ MessageCount: state.MessageCount,+ Uploaded: len(pending),+ SelectedBy: subject.selectedBy,+ SharedThrough: readAt,}if uploaded.Batches > 0 {result.MessageCount = uploaded.MessageCount@@ -955,6 +963,9 @@ func shareRecordEvent(session handoff.Session, result shareResult, refresh bool,if !refresh {event.Raw["shared_at"] = stamp}+ if !result.SharedThrough.IsZero() {+ event.Raw["shared_through"] = schema.FormatTimestamp(result.SharedThrough)+ }return event}diff --git a/cli/beacon/cmd/share_test.go b/cli/beacon/cmd/share_test.goindex 64190618..9e9f1ced 100644--- a/cli/beacon/cmd/share_test.go+++ b/cli/beacon/cmd/share_test.go@@ -3,6 +3,7 @@ package cmdimport ("bytes""compress/gzip"+ "context""encoding/json""errors""fmt"@@ -604,3 +605,61 @@ func TestShareAlignSwitchesFromTheLogToTheStore(t *testing.T) {t.Fatalf("did not switch to the store copy: fromLog=%v", subject.fromLog)}}++// The session.shared record says what the upload covered: shared_through is when the session was+// read, which precedes the record's own timestamp (taken after the upload). Share, refresh and the+// non-interactive upload path all write it.+func TestShareRecordCarriesSharedThrough(t *testing.T) {+ env := newShareEnv(t)+ srv := newFakeShareServer(t)+ srv.signIn(account.ScopeTracesWrite)+ base := time.Date(2026, 10, 2, 9, 0, 0, 0, time.UTC)+ calls := 0+ shareNow = func() time.Time { calls++; return base.Add(time.Duration(calls) * time.Minute) }+ t.Cleanup(func() { shareNow = time.Now })++ check := func(what string) {+ t.Helper()+ data, err := os.ReadFile(env.logPath)+ if err != nil {+ t.Fatal(err)+ }+ lines := strings.Split(strings.TrimSpace(string(data)), "\n")+ var event schema.Event+ if err := json.Unmarshal([]byte(lines[len(lines)-1]), &event); err != nil {+ t.Fatal(err)+ }+ through, _ := event.Raw["shared_through"].(string)+ readAt, err := time.Parse(time.RFC3339Nano, through)+ if err != nil {+ t.Fatalf("%s: shared_through %q: %v", what, through, err)+ }+ recorded, err := time.Parse(time.RFC3339Nano, event.Timestamp)+ if err != nil || !readAt.Before(recorded) {+ t.Fatalf("%s: shared_through %s, record at %s: want the read before the record", what, through, event.Timestamp)+ }+ }+ if _, stderr, err := runShareCommand(t, "--cwd", env.projectDir, "--log-path", env.logPath); err != nil {+ t.Fatalf("share: %v\n%s", err, stderr)+ }+ check("share")+ if _, _, err := runShareCommand(t, "refresh", "claude_code:"+shareTestSession, "--log-path", env.logPath); err != nil {+ t.Fatalf("refresh: %v", err)+ }+ check("refresh")+ prevOpts := shareOpts+ shareOpts = shareOptions{logPath: env.logPath}+ t.Cleanup(func() { shareOpts = prevOpts })+ subject, err := resolveShareSubject(handoff.HarnessClaude, shareTestSession)+ if err != nil {+ t.Fatal(err)+ }+ client, err := newShareClient()+ if err != nil {+ t.Fatal(err)+ }+ if _, _, err := shareUpload(context.Background(), client, subject, shareUploadOptions{Record: true}); err != nil {+ t.Fatalf("upload: %v", err)+ }+ check("upload")+}diff --git a/cli/beacon/cmd/share_upload.go b/cli/beacon/cmd/share_upload.goindex 142c0267..cc9b13c8 100644--- a/cli/beacon/cmd/share_upload.go+++ b/cli/beacon/cmd/share_upload.go@@ -9,8 +9,14 @@ import (// shareUploadOptions configures shareUpload.type shareUploadOptions struct {- // Visibility is applied when the trace is created; an existing trace keeps its own.- Visibility string+ // Visibility is applied when the trace is created. An existing trace keeps its own unless+ // ExplicitVisibility says the person asked for this one (--visibility), as plain share does.+ Visibility string+ ExplicitVisibility bool+ // ExplicitTitle keeps the payload's title for an existing trace (--title). Otherwise an+ // existing trace keeps its title, so a --title or a rename on beacon.sh is not replaced by the+ // derived one (keepSharedTitle).+ ExplicitTitle bool// Record writes the session.shared event after the upload.Record bool}@@ -21,6 +27,7 @@ type shareUploadOptions struct {// (alignShareSource) and only the messages after the last one beacon.sh holds are sent// (messagesAfter), which re-sends open calls and that last message.func shareUpload(ctx context.Context, client *account.ShareClient, subject shareSubject, opts shareUploadOptions) (shareResult, shareSubject, error) {+ readAt := shareNow()payload, err := buildSharePayload(subject)if err != nil {return shareResult{}, subject, err@@ -34,7 +41,14 @@ func shareUpload(ctx context.Context, client *account.ShareClient, subject shareif subject, payload, err = alignShareSource(subject, payload, state); err != nil {return shareResult{}, subject, err}- payload.Trace.Visibility = ""+ if opts.ExplicitVisibility && opts.Visibility != "" {+ payload.Trace.Visibility = opts.Visibility+ } else {+ payload.Trace.Visibility = ""+ }+ if !opts.ExplicitTitle {+ payload.Trace.Title = ""+ }pending = messagesAfter(payload.Messages, state.LastMessageID, state.MaxOrder)} else if opts.Visibility != "" {payload.Trace.Visibility = opts.Visibility@@ -48,14 +62,15 @@ func shareUpload(ctx context.Context, client *account.ShareClient, subject sharereturn shareResult{}, subject, fmt.Errorf("upload messages to %s: %w", trace.URL, err)}result := shareResult{- TraceID: trace.ID,- ExternalID: payload.ExternalID,- SharedURL: trace.URL,- Visibility: trace.Visibility,- AgentID: payload.Trace.AgentID,- MessageCount: trace.MessageCount,- Uploaded: len(pending),- SelectedBy: subject.selectedBy,+ TraceID: trace.ID,+ ExternalID: payload.ExternalID,+ SharedURL: trace.URL,+ Visibility: trace.Visibility,+ AgentID: payload.Trace.AgentID,+ MessageCount: trace.MessageCount,+ Uploaded: len(pending),+ SelectedBy: subject.selectedBy,+ SharedThrough: readAt,}if found {result.MessageCount = state.MessageCount