Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
awake: Keep awake turned on just as the setting is read takes hold at once, not up to a minute later (#3686)
JoeyWu-tech8ff90bee3dc1
diff --git a/internal/awake/awake.go b/internal/awake/awake.goindex b02771255..61688ebc3 100644--- a/internal/awake/awake.go+++ b/internal/awake/awake.go@@ -72,6 +72,8 @@ func Keep(ctx context.Context, level func() Level, state func() State) {defer let()failed := falsefor {+ // taken before the look, so a write made during it isn't missed+ written := filememo.Written()l := level()if l != Off && want(state(), time.Now()) {if release != nil && held != l {@@ -102,7 +104,7 @@ func Keep(ctx context.Context, level func() Level, state func() State) {// seconds (#3185: these looks woke an idle magpie)every, changed := tick, (<-chan struct{})(nil)if l == Off {- every, changed = filememo.OthersEvery(), filememo.Written()+ every, changed = filememo.OthersEvery(), written}select {case <-ctx.Done():diff --git a/internal/awake/awake_test.go b/internal/awake/awake_test.goindex 95b8df0cd..7f00b1895 100644--- a/internal/awake/awake_test.go+++ b/internal/awake/awake_test.go@@ -7,6 +7,7 @@ import ("testing""time"+ "github.com/yetone/magpie/internal/beat""github.com/yetone/magpie/internal/filememo")@@ -187,3 +188,65 @@ func TestKeepOffWaitsForTheSetting(t *testing.T) {}}}++// Turned off, a setting turned on while Keep looks, after the look read it,+// is looked at again at once, not at the beat after: Keep waits on the+// Written it took before the look, which that write closes.+func TestKeepOffSeesAWriteDuringTheLook(t *testing.T) {+ oldHold := hold+ defer func() { hold = oldHold }()+ hold = func(bool) (func(), error) { return func() {}, nil }+ type write struct{ at, next time.Time }+ wrote := make(chan write, 1)+ // when this test's level is asked again: a hold could be taken by a+ // Keep that another test's failure left running+ again := make(chan time.Time, 1)+ var on atomic.Bool+ ctx, cancel := context.WithCancel(context.Background())+ done := make(chan struct{})+ go func() {+ Keep(ctx, func() Level {+ if on.Load() {+ select {+ case again <- time.Now():+ default:+ }+ return System+ }+ // the beat Keep waits for, turned off (beat.Next: the next+ // multiple of OthersEvery on the clock), 2s away at least, so+ // that a look at once has room before it+ every := filememo.OthersEvery()+ next := time.Now().Truncate(every).Add(every)+ if time.Until(next) < 2*time.Second {+ <-beat.Next(every)+ next = time.Now().Truncate(every).Add(every)+ }+ // the user turns it on just after this read, as settings.save+ // writes it (filememo.Forget)+ at := time.Now()+ on.Store(true)+ filememo.Forget()+ wrote <- write{at, next}+ return Off+ }, func() State { return State{Busy: true} })+ close(done)+ }()+ defer func() { cancel(); <-done }()+ var w write+ select {+ case w = <-wrote:+ case <-time.After(10 * time.Second):+ t.Fatal("Keep never looked at the setting")+ }+ select {+ case at := <-again:+ // both on the wall clock, as beat.Next goes by it (Truncate drops+ // the monotonic reading)+ if !at.Before(w.next) {+ t.Fatalf("turned on during the look, the setting was looked at again %v after it was written, at the beat (%s), not at once", at.Sub(w.at), w.next.Format(time.TimeOnly))+ }+ case <-time.After(time.Until(w.next) + 10*time.Second):+ t.Fatal("turned on during the look, the setting was never looked at again")+ }+}