Migrate the coach fetch onto runFetchAsync

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 18:08:48 -04:00
parent fbbff6966d
commit 59283be733
+16 -22
View File
@@ -357,28 +357,22 @@ func (c *Controller) RequestCoach(intent string) error {
c.mu.Unlock() c.mu.Unlock()
c.notify() c.notify()
go func() { var prop ai.Proposal
ctx, cancel := context.WithTimeout(context.Background(), coachTimeout) var err error
defer cancel() c.runFetchAsync(coachTimeout,
prop, err := coach.Coach(ctx, intent, grounding) func(ctx context.Context) { prop, err = coach.Coach(ctx, intent, grounding) },
func() bool { return gen != c.coachGen || c.runtimeState != domain.RuntimePlanning },
c.mu.Lock() func() {
if gen != c.coachGen || c.runtimeState != domain.RuntimePlanning { if err != nil {
c.mu.Unlock() c.coachStatus = coachError
return // stale or left planning: discard c.coachErr = coachErrorMessage(err)
} c.coachProposal = nil
if err != nil { } else {
c.coachStatus = coachError c.coachStatus = coachReady
c.coachErr = coachErrorMessage(err) c.coachProposal = &prop
c.coachProposal = nil c.coachErr = ""
} else { }
c.coachStatus = coachReady })
c.coachProposal = &prop
c.coachErr = ""
}
c.mu.Unlock()
c.notify()
}()
return nil return nil
} }