Migrate the coach fetch onto runFetchAsync
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -357,16 +357,12 @@ 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 {
|
|
||||||
c.mu.Unlock()
|
|
||||||
return // stale or left planning: discard
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.coachStatus = coachError
|
c.coachStatus = coachError
|
||||||
c.coachErr = coachErrorMessage(err)
|
c.coachErr = coachErrorMessage(err)
|
||||||
@@ -376,9 +372,7 @@ func (c *Controller) RequestCoach(intent string) error {
|
|||||||
c.coachProposal = &prop
|
c.coachProposal = &prop
|
||||||
c.coachErr = ""
|
c.coachErr = ""
|
||||||
}
|
}
|
||||||
c.mu.Unlock()
|
})
|
||||||
c.notify()
|
|
||||||
}()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user