Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
sessions: a hold counts holds, not times (#4114, #4177)
yetone168dcf455d00
diff --git a/internal/sessions/one_listing.go b/internal/sessions/one_listing.goindex 54a74c752..8e214c5f7 100644--- a/internal/sessions/one_listing.go+++ b/internal/sessions/one_listing.go@@ -3,7 +3,6 @@ package sessionsimport ("slices""sync"- "time")// held is the session folders' listings kept while a request that reads@@ -13,13 +12,18 @@ import (// twice a poll.var held struct {sync.Mutex- n int- since time.Time // when the latest hold began+ n int+ // gen counts the holds begun: a listing is taken after the latest+ // hold began when it carries that hold's gen. A count, not a time:+ // on Windows two time.Now() a moment apart can be the same, and a+ // hold begun in the tick a listing was taken in counted that older+ // listing as its own (#4114)+ gen uint64lists map[string]*heldList}type heldList struct {- at time.Time+ gen uint64 // held.gen when it was takenfiles []file// closed once files is in: a read that comes while the folder is// being listed waits for that listing rather than taking its own@@ -33,7 +37,7 @@ type heldList struct {func OneListing() (done func()) {held.Lock()held.n++- held.since = time.Now()+ held.gen++held.Unlock()return letGo()}@@ -48,7 +52,7 @@ func ShareListing() (done func()) {held.Lock()defer held.Unlock()if held.n++; held.n == 1 {- held.since = time.Now()+ held.gen++}return letGo()}@@ -75,7 +79,7 @@ func heldFiles(key string, list func() []file) []file {held.Unlock()return list()}- if l, ok := held.lists[key]; ok && !l.at.Before(held.since) {+ if l, ok := held.lists[key]; ok && l.gen == held.gen {held.Unlock()if heldWaiting != nil {heldWaiting()@@ -83,7 +87,7 @@ func heldFiles(key string, list func() []file) []file {<-l.readyreturn slices.Clone(l.files)}- mine := &heldList{at: time.Now(), ready: make(chan struct{})}+ mine := &heldList{gen: held.gen, ready: make(chan struct{})}if held.lists == nil {held.lists = map[string]*heldList{}}diff --git a/internal/sessions/one_listing_test.go b/internal/sessions/one_listing_test.goindex 2fc31ed21..23f597e13 100644--- a/internal/sessions/one_listing_test.go+++ b/internal/sessions/one_listing_test.go@@ -5,10 +5,22 @@ import ("testing")+// holdsEnd ends, when the test does, every hold it left: one that fails+// before its done() would otherwise have every later test in the package+// read the listing it held (#4177).+func holdsEnd(t *testing.T) {+ t.Cleanup(func() {+ held.Lock()+ held.n, held.lists = 0, nil+ held.Unlock()+ })+}+// Under a hold a folder is listed once; a hold begun after a listing has// it listed again, so no request reads files from before it came; with// no hold left every read lists.func TestOneListing(t *testing.T) {+ holdsEnd(t)n := 0list := func() []file { n++; return []file{{path: "a"}} }read := func() {@@ -54,6 +66,7 @@ func TestOneListing(t *testing.T) {// that listing; a shared hold reads the listing a hold before it took, and// begins one of its own when there is none.func TestShareListing(t *testing.T) {+ holdsEnd(t)var n atomic.Int32listing, release := make(chan struct{}), make(chan struct{})slow := func() []file {@@ -69,7 +82,11 @@ func TestShareListing(t *testing.T) {done := OneListing()got := make(chan []file, 2)go func() { got <- heldFiles("k", slow) }()- <-listing+ select {+ case <-listing:+ case <-got:+ t.Fatal("a hold's first read didn't list: a listing was left from before it")+ }shared := ShareListing()go func() { got <- heldFiles("k", slow) }()select {diff --git a/internal/sessions/refresh_shared_test.go b/internal/sessions/refresh_shared_test.goindex 2db7fc196..a088cec89 100644--- a/internal/sessions/refresh_shared_test.go+++ b/internal/sessions/refresh_shared_test.go@@ -51,7 +51,13 @@ func TestReadNotHeldByAnotherRead(t *testing.T) {warm := make(chan struct{})go func() { defer close(warm); statsAt(0, statsNow) }()- <-started+ // a warm-up that parses nothing (its files listed before they grew)+ // is a red here, not a wait until the package's timeout (#4177)+ select {+ case <-started:+ case <-warm:+ t.Fatal("the warm-up parsed none of the files that grew")+ }listed := make(chan []Session, 1)go func() { listed <- List(0) }()@@ -108,7 +114,11 @@ func TestReadWaitsForAFirstReadUnderWay(t *testing.T) {warm := make(chan struct{})go func() { defer close(warm); statsAt(0, statsNow) }()- <-started+ select {+ case <-started:+ case <-warm:+ t.Fatal("the warm-up parsed none of the new files")+ }before := parsed.Load()listed := make(chan []Session, 1)