fix(ambient): re-check active mode after the judge call (coexistence TOCTOU)

This commit is contained in:
2026-06-05 21:39:46 -04:00
parent c963895599
commit 7507cc6d28
2 changed files with 46 additions and 0 deletions
+10
View File
@@ -236,6 +236,16 @@ func (s *Sentinel) evaluate(ctx context.Context) {
cancel()
s.mu.Lock()
// A mode may have activated during the (off-lock) brain call; re-check so a
// result computed while idle is not surfaced over an now-active mode.
if s.activeModeLocked() != "" {
changed := s.clearLocked()
s.mu.Unlock()
if changed {
s.fireOnChange()
}
return
}
s.lastEvalTitles = joined
if err != nil {
s.mu.Unlock()