mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-06-06 05:51:19 +08:00
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:
@@ -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)
|
||||
}()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nofx/mcp"
|
||||
"nofx/store"
|
||||
@@ -2757,7 +2758,9 @@ func (a *Agent) handleTraderDiagnosisSkill(storeUserID, lang, text string) strin
|
||||
}
|
||||
|
||||
evidence := a.collectTraderDiagnosisEvidence(storeUserID, target.ID, target.Name)
|
||||
if answer, ok := a.generateTraderDiagnosisAnswerWithLLM(context.Background(), lang, text, evidence); ok {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
if answer, ok := a.generateTraderDiagnosisAnswerWithLLM(ctx, lang, text, evidence); ok {
|
||||
return answer
|
||||
}
|
||||
return formatTraderDiagnosisEvidence(lang, evidence)
|
||||
|
||||
Reference in New Issue
Block a user