fix(agent): guard async maintenance goroutine and add timeout to diagnosis ctx

- Add stopCh check in runPostResponseMaintenanceAsync to respect agent
  shutdown, preventing goroutine leak on Agent.Stop()
- Replace bare context.Background() in handleTraderDiagnosisSkill with
  a 30s timeout context for proper deadline propagation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shinchan-zhai
2026-05-11 16:37:30 +08:00
parent e67a927a4f
commit 94844b7139
2 changed files with 10 additions and 1 deletions

View File

@@ -2628,6 +2628,12 @@ func (a *Agent) runPostResponseMaintenanceAsync(userID int64) {
}()
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// Respect agent shutdown: abort early if stopCh is closed.
select {
case <-a.stopCh:
return
default:
}
a.maybeUpdateTaskStateIncrementally(ctx, userID)
a.maybeCompressHistory(ctx, userID)
}()