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
fix(dshsession): discover session files that carry the format version
Tactile-Taco509dd7460304
diff --git a/cli/beacon/internal/dshsession/store.go b/cli/beacon/internal/dshsession/store.goindex 6cb9b79f..f92df0da 100644--- a/cli/beacon/internal/dshsession/store.go+++ b/cli/beacon/internal/dshsession/store.go@@ -53,8 +53,9 @@ func (s *Store) Exists() bool {func (s *Store) List() ([]SessionRef, error) {type candidate struct {- dir string- path string+ dir string+ path string+ compressed bool}byDir := map[string]candidate{}dirs := 0@@ -74,14 +75,16 @@ func (s *Store) List() ([]SessionRef, error) {if files > MaxFiles {return filepath.SkipAll}- name := d.Name()- if name != SessionFileZstd && name != SessionFileJSON {+ compressed, ok := classifySessionFile(d.Name())+ if !ok {return nil}dir := filepath.Dir(path)- prior, ok := byDir[dir]- if !ok || filepath.Base(path) == SessionFileZstd || filepath.Base(prior.path) != SessionFileZstd {- byDir[dir] = candidate{dir: dir, path: path}+ prior, exists := byDir[dir]+ // One directory can hold both spellings; the compressed frame is the one DSH+ // writes, and it wins whichever order the walk visits them in.+ if !exists || compressed || !prior.compressed {+ byDir[dir] = candidate{dir: dir, path: path, compressed: compressed}}return nil})@@ -104,7 +107,7 @@ func (s *Store) List() ([]SessionRef, error) {DSHHome: s.DSHHome,ModTimeUnixMS: info.ModTime().UnixMilli(),SizeBytes: info.Size(),- Compressed: filepath.Base(item.path) == SessionFileZstd,+ Compressed: item.compressed,}if meta := s.readMeta(ref); meta != nil {ref.Meta = metadiff --git a/cli/beacon/internal/dshsession/store_test.go b/cli/beacon/internal/dshsession/store_test.gonew file mode 100644index 00000000..b3eb4239--- /dev/null+++ b/cli/beacon/internal/dshsession/store_test.go@@ -0,0 +1,110 @@+package dshsession++import (+ "path/filepath"+ "testing"+)++// TestClassifySessionFile pins the name shape the store matches.+//+// DSH versions the session file: it writes `session.v3.jsonl.zstd`, and the `v3`+// is the session format version. Discovery compared the name for equality against+// the two unversioned spellings, so it found none of the 25 sessions in a real+// store and returned that as success with an empty list. This table is what+// should make that recurrence fail loudly.+func TestClassifySessionFile(t *testing.T) {+ cases := []struct {+ name string+ ok bool+ compressed bool+ }{+ {"session.jsonl", true, false},+ {"session.jsonl.zstd", true, true},+ {"session.v3.jsonl", true, false},+ {"session.v3.jsonl.zstd", true, true},+ {"session.v42.jsonl.zstd", true, true},+ {"session.lock", false, false},+ {"session.v3.jsonl.zstd.tmp", false, false},+ {"session.v3.jsonl.gz", false, false},+ {"sessions.jsonl", false, false},+ {"session.v.jsonl", false, false},+ {"session_v3.jsonl", false, false},+ {"", false, false},+ }+ for _, tc := range cases {+ compressed, ok := classifySessionFile(tc.name)+ if ok != tc.ok {+ t.Errorf("classifySessionFile(%q) ok = %v, want %v", tc.name, ok, tc.ok)+ continue+ }+ if ok && compressed != tc.compressed {+ t.Errorf("classifySessionFile(%q) compressed = %v, want %v", tc.name, compressed, tc.compressed)+ }+ }+}++// TestListFindsSessionsWrittenTheWayDSHWritesThem is the end-to-end half: a+// directory laid out as DSH leaves it -- the versioned compressed record beside+// its lock file -- must be discovered, marked compressed, and read.+func TestListFindsSessionsWrittenTheWayDSHWritesThem(t *testing.T) {+ root := t.TempDir()+ dir := filepath.Join(root, "sessions", "--home-me-repo--", "session-abc")+ writeBytes(t, filepath.Join(dir, "session.lock"), nil)+ writeBytes(t, filepath.Join(dir, "session.v3.jsonl.zstd"),+ zstdFrame(t, []byte(record("session", map[string]interface{}{"id": "versioned-1", "cwd": "/repo"})+"\n")))++ store, err := NewStore(root)+ if err != nil {+ t.Fatal(err)+ }+ refs, err := store.List()+ if err != nil {+ t.Fatal(err)+ }+ if len(refs) != 1 {+ t.Fatalf("want 1 session, got %d: %+v", len(refs), refs)+ }+ if !refs[0].Compressed {+ t.Error("a .zstd record must be marked compressed")+ }+ if refs[0].ID != "versioned-1" {+ t.Errorf("want the id from the record, got %q", refs[0].ID)+ }+ records, _, err := store.Read(refs[0])+ if err != nil {+ t.Fatal(err)+ }+ if len(records) != 1 {+ t.Fatalf("want 1 record, got %d", len(records))+ }+}++// TestListPrefersTheCompressedFrame keeps the precedence the collector already+// documented: when a directory holds both spellings, the compressed record is the+// one that counts, whichever order the walk visits them in.+func TestListPrefersTheCompressedFrame(t *testing.T) {+ root := t.TempDir()+ dir := filepath.Join(root, "sessions", "ws", "session-both")+ writeBytes(t, filepath.Join(dir, "session.v3.jsonl"),+ []byte(record("session", map[string]interface{}{"id": "plain"})+"\n"))+ writeBytes(t, filepath.Join(dir, "session.v3.jsonl.zstd"),+ zstdFrame(t, []byte(record("session", map[string]interface{}{"id": "compressed"})+"\n")))++ store, err := NewStore(root)+ if err != nil {+ t.Fatal(err)+ }+ refs, err := store.List()+ if err != nil {+ t.Fatal(err)+ }+ if len(refs) != 1 {+ t.Fatalf("want 1 session for one directory, got %d", len(refs))+ }+ if !refs[0].Compressed {+ t.Error("the compressed frame must win")+ }+ if refs[0].ID != "compressed" {+ t.Errorf("want the compressed record's id, got %q", refs[0].ID)+ }+}diff --git a/cli/beacon/internal/dshsession/types.go b/cli/beacon/internal/dshsession/types.goindex e74bfcba..133bf14d 100644--- a/cli/beacon/internal/dshsession/types.go+++ b/cli/beacon/internal/dshsession/types.go@@ -7,6 +7,7 @@ import ("errors""fmt""math"+ "regexp""strconv""strings""time"@@ -18,6 +19,10 @@ const (Harness = "deepseek_harness"StateVersion = 1+ // SessionFileZstd and SessionFileJSON are the unversioned spellings, kept for+ // fixtures and for callers that write a record file by hand. What DSH itself+ // writes carries the session *format* version -- session.v3.jsonl.zstd -- so+ // discovery matches the shape (sessionFileName) rather than these strings.SessionFileZstd = "session.jsonl.zstd"SessionFileJSON = "session.jsonl"@@ -26,6 +31,33 @@ const (MaxLineBytes = 8 * 1024 * 1024)+// sessionFileName matches the name DSH gives a session record file:+//+// session.jsonl+// session.jsonl.zstd+// session.v3.jsonl+// session.v3.jsonl.zstd+//+// The optional `vN` segment is the session format version, and it is part of the+// filename the store writes. Discovery compared the name for equality against the+// two unversioned constants above, so a store full of `session.v3.jsonl.zstd`+// yielded no sessions at all -- and returned that as success with an empty list,+// which is the part that made it a silent failure rather than a visible error.+//+// The version stays optional and unconstrained: a store written by a future DSH+// should still be discovered, and a record is validated by the decoder rather than+// by the name of the file holding it.+var sessionFileName = regexp.MustCompile(`^session(?:\.v[0-9]+)?\.jsonl(?:\.zstd)?$`)++// classifySessionFile reports whether a directory entry names a session record+// file, and whether its contents are zstd-compressed.+func classifySessionFile(name string) (compressed bool, ok bool) {+ if !sessionFileName.MatchString(name) {+ return false, false+ }+ return strings.HasSuffix(name, ".zstd"), true+}+type Record struct {Line intKind string