agent: fix missed-wakeup race in WaitChange

notifyChange must hold changeMu when broadcasting. Without the lock,
the broadcast can fire between the consumer's value check and its
cond.Wait call — the signal is lost and the consumer sleeps until the
next change, causing an apparent off-by-one lag.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-04-19 16:25:43 +02:00
parent fdc77618ab
commit f03ccadd43
1 changed files with 2 additions and 0 deletions

View File

@ -328,7 +328,9 @@ func (s *agentCore) State() string {
}
func (s *agentCore) notifyChange() {
s.changeMu.Lock()
s.changeCond.Broadcast()
s.changeMu.Unlock()
}
// WaitChange blocks until the named field changes from current, then returns