Skip to content

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

Find the store copy by its own listing when switching from the log

Claudee3b1c8f95335
diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.go
index fbc8cf95..e4b52d0f 100644
--- a/cli/beacon/cmd/share.go
+++ b/cli/beacon/cmd/share.go
@@ -441,7 +441,13 @@ func alignShareSource(subject shareSubject, payload sharePayload, state *asympto
}
var other shareSubject
if subject.fromLog {
- other = shareSubject{session: subject.session}
+ // A session found in the log carries no store path, which store readers match on, so the
+ // store's own listing has to name it.
+ if dirs, err := shareStoreDirs(); err == nil {
+ if session, err := handoff.Find(handoffSources(dirs), subject.session.Harness, subject.session.ID); err == nil {
+ other = shareSubject{session: session}
+ }
+ }
} else if logSubject, err := resolveShareLog(subject.session); err == nil {
other = logSubject
}
diff --git a/cli/beacon/cmd/share_test.go b/cli/beacon/cmd/share_test.go
index 4b0e422f..d2ce7e8c 100644
--- a/cli/beacon/cmd/share_test.go
+++ b/cli/beacon/cmd/share_test.go
@@ -562,3 +562,45 @@ func TestShareRefreshKeepsATitleSetEarlier(t *testing.T) {
t.Fatalf("an explicit --title did not apply: %q", srv.trace.Title)
}
}
+
+// pathMatchingSource is a store that, like the real ones, finds a session's events only by the
+// store path it listed the session with.
+type pathMatchingSource struct{ stubHandoffSource }
+
+func (s pathMatchingSource) Events(session handoff.Session) ([]schema.Event, error) {
+ if len(s.sessions) == 0 || session.SourcePath != s.sessions[0].SourcePath {
+ return nil, handoff.ErrNotFound
+ }
+ return s.events, nil
+}
+
+func TestShareAlignSwitchesFromTheLogToTheStore(t *testing.T) {
+ env := newShareEnv(t)
+ storeSession := handoff.Session{Harness: handoff.HarnessClaude, ID: shareTestSession, Directory: env.projectDir, SourcePath: filepath.Join(env.home, "store", shareTestSession+".jsonl"), UpdatedAt: time.Now()}
+ stubHandoffSources(t, pathMatchingSource{stubHandoffSource{harness: handoff.HarnessClaude, sessions: []handoff.Session{storeSession}, events: shareFixtureEvents(env.projectDir)}})
+ shareOpts = shareOptions{logPath: env.logPath}
+
+ stored, err := buildSharePayload(shareSubject{session: storeSession})
+ if err != nil {
+ t.Fatal(err)
+ }
+ var logEvents []schema.Event
+ for _, event := range shareFixtureEvents(env.projectDir) {
+ event.Harness.CollectionMethod = schema.CollectionMethodHook
+ logEvents = append(logEvents, event)
+ }
+ // Found in the log: no store path.
+ logSubject := shareSubject{session: handoff.Session{Harness: handoff.HarnessClaude, ID: shareTestSession, Directory: env.projectDir}, fromLog: true, logEvents: logEvents}
+ logPayload, err := buildSharePayload(logSubject)
+ if err != nil {
+ t.Fatal(err)
+ }
+ state := &asymptoteobserve.ShareTraceStateV1{LastMessageID: stored.Messages[len(stored.Messages)-1].ID}
+ subject, payload, err := alignShareSource(logSubject, logPayload, state)
+ if err != nil {
+ t.Fatalf("align: %v", err)
+ }
+ if subject.fromLog || !hasShareMessage(payload.Messages, state.LastMessageID) {
+ t.Fatalf("did not switch to the store copy: fromLog=%v", subject.fromLog)
+ }
+}