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
Read the runtime log once per push when resolving linked sessions
Claude4ab576cb8e75
diff --git a/cli/beacon/cmd/git_share_sessions.go b/cli/beacon/cmd/git_share_sessions.goindex e30325c3..a4a67cd5 100644--- a/cli/beacon/cmd/git_share_sessions.go+++ b/cli/beacon/cmd/git_share_sessions.go@@ -50,8 +50,17 @@ var (gitShareUploadBudget = gitShareBudget - gitShareNotesReserve - gitShareNoteWriteBudget// gitShareUpload is shareUpload; tests replace it.gitShareUpload = shareUpload+ // gitShareLogSessions lists the sessions in the runtime log; tests replace it to count reads.+ gitShareLogSessions = func(logPath string) ([]handoff.Session, error) {+ return handoff.LogSessions(logPath, handoff.Filter{})+ })+// gitShareMaxResolve bounds how many linked sessions one push tries to find on this machine,+// counting the ones that are not here (teammates' sessions), so a note full of them cannot use up+// the budget.+const gitShareMaxResolve = 50+// gitAllowShareHosts admits the configured Beacon service's host besides beacon.sh.func gitAllowShareHosts() {for _, raw := range []string{account.ResolveBaseURL("")} {@@ -178,19 +187,38 @@ func gitShareSessionsOnPush(parent context.Context, repo gitlink.Repo, remote, s// must not use up a slot that one of this person's sessions needs. Resolving reads only// the local stores, inside the upload budget.sources := handoffSources(handoff.StoreDirs{})- for _, link := range toShare {- if ctx.Err() != nil || len(subjects) >= gitShareMaxSessions {+ logPath := shareLogPath()+ var inLog map[string]bool // read once, on the first link the stores do not have+ for i, link := range toShare {+ if ctx.Err() != nil || len(subjects) >= gitShareMaxSessions || i >= gitShareMaxResolve {break}harness, err := handoff.ParseHarness(link.Harness)if err != nil {continue}- subject, err := resolveShareID(sources, harness, link.SessionID)- if err != nil || subject.session.ID != link.SessionID {+ if session, err := handoff.Find(sources, harness, link.SessionID); err == nil {+ if session.ID == link.SessionID {+ subjects = append(subjects, linkedSubject{link: link, subject: shareSubject{session: session}})+ }+ continue+ }+ if inLog == nil {+ inLog = map[string]bool{}+ if sessions, err := gitShareLogSessions(logPath); err == nil {+ for _, s := range sessions {+ inLog[s.Harness+"\x00"+s.ID] = true+ }+ }+ }+ if !inLog[harness+"\x00"+link.SessionID] {continue // a teammate's session, or one this machine no longer has}- subjects = append(subjects, linkedSubject{link: link, subject: subject})+ session, events, found, err := handoff.LogSession(logPath, link.SessionID, harness)+ if err != nil || !found || session.ID != link.SessionID || session.Harness != harness {+ continue+ }+ subjects = append(subjects, linkedSubject{link: link, subject: shareSubject{session: session, fromLog: true, logEvents: events}})}}if len(subjects) > 0 {diff --git a/cli/beacon/cmd/git_share_sessions_test.go b/cli/beacon/cmd/git_share_sessions_test.goindex 7c7a2c66..440415e0 100644--- a/cli/beacon/cmd/git_share_sessions_test.go+++ b/cli/beacon/cmd/git_share_sessions_test.go@@ -317,6 +317,13 @@ func TestGitShareOnPushCapsOnlySessionsThatResolve(t *testing.T) {prevOpts := shareOptsshareOpts = shareOptions{logPath: env.logPath}t.Cleanup(func() { shareOpts = prevOpts })+ logReads := 0+ prevLogSessions := gitShareLogSessions+ gitShareLogSessions = func(logPath string) ([]handoff.Session, error) {+ logReads+++ return prevLogSessions(logPath)+ }+ t.Cleanup(func() { gitShareLogSessions = prevLogSessions })var uploaded []stringprevUpload := gitShareUploadgitShareUpload = func(ctx context.Context, _ *account.ShareClient, subject shareSubject, _ shareUploadOptions) (shareResult, shareSubject, error) {@@ -344,6 +351,9 @@ func TestGitShareOnPushCapsOnlySessionsThatResolve(t *testing.T) {if len(uploaded) != 1 || uploaded[0] != shareTestSession {t.Fatalf("uploaded %v, want only this machine's session", uploaded)}+ if logReads != 1 {+ t.Fatalf("runtime log read %d times for the teammates' links, want once", logReads)+ }if note := mustGit(t, root, "notes", "--ref="+gitlink.NotesRef, "show", sha); !strings.Contains(note, "beacon:claude_code/"+shareTestSession+" https://beacon.sh/s/mine01") {t.Fatalf("note %q lacks the URL", note)}