Migrate the reflection fetch onto runFetchAsync

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 18:12:10 -04:00
parent 59283be733
commit 895ad342c7
+17 -23
View File
@@ -243,29 +243,23 @@ func (c *Controller) startReflectionFetchLocked() {
// bounded to reflectionHistoryN summaries and runs once per Review entry, not // bounded to reflectionHistoryN summaries and runs once per Review entry, not
// on any hot path. // on any hot path.
history := buildReflectionHistory(c.auditPath) history := buildReflectionHistory(c.auditPath)
go func() { var refl ai.Reflection
ctx, cancel := context.WithTimeout(context.Background(), reflectionTimeout) var err error
defer cancel() c.runFetchAsync(reflectionTimeout,
refl, err := reviewer.Review(ctx, finished, history) func(ctx context.Context) { refl, err = reviewer.Review(ctx, finished, history) },
func() bool { return gen != c.reflectionGen },
c.mu.Lock() func() {
if gen != c.reflectionGen { if err != nil || strings.TrimSpace(refl.Recap) == "" {
c.mu.Unlock() c.reflectionStatus = reflectionAbsent
return // superseded review: discard c.reflectionRecap = ""
} c.carryForward = ""
if err != nil || strings.TrimSpace(refl.Recap) == "" { } else {
c.reflectionStatus = reflectionAbsent c.reflectionStatus = reflectionReady
c.reflectionRecap = "" c.reflectionRecap = refl.Recap
c.carryForward = "" c.carryForward = refl.CarryForward
} else { }
c.reflectionStatus = reflectionReady _ = c.persistLocked()
c.reflectionRecap = refl.Recap })
c.carryForward = refl.CarryForward
}
_ = c.persistLocked()
c.mu.Unlock()
c.notify()
}()
} }
// buildReflectionFinishedLocked renders the just-finished session as a compact // buildReflectionFinishedLocked renders the just-finished session as a compact