fix for review

This commit is contained in:
Cytown 2026-03-12 16:05:28 +08:00
parent 0fd7a401a2
commit ee959d5ba0
2 changed files with 14 additions and 3 deletions

View file

@ -488,9 +488,12 @@ func restartServices(
} }
// Wire up voice transcription with new config // Wire up voice transcription with new config
if transcriber := voice.DetectTranscriber(cfg); transcriber != nil { transcriber := voice.DetectTranscriber(cfg)
al.SetTranscriber(transcriber) al.SetTranscriber(transcriber) // This will set it to nil if disabled
logger.InfoCF("voice", "Transcription enabled (agent-level)", map[string]any{"provider": transcriber.Name()}) if transcriber != nil {
logger.InfoCF("voice", "Transcription re-enabled (agent-level)", map[string]any{"provider": transcriber.Name()})
} else {
logger.InfoCF("voice", "Transcription disabled", nil)
} }
return nil return nil

View file

@ -49,6 +49,8 @@ type AgentLoop struct {
cmdRegistry *commands.Registry cmdRegistry *commands.Registry
mcp mcpRuntime mcp mcpRuntime
mu sync.RWMutex mu sync.RWMutex
// Track active requests for safe provider cleanup
activeRequests sync.WaitGroup
} }
// processOptions configures how a message is processed // processOptions configures how a message is processed
@ -1059,6 +1061,9 @@ func (al *AgentLoop) runLLMIteration(
} }
callLLM := func() (*providers.LLMResponse, error) { callLLM := func() (*providers.LLMResponse, error) {
al.activeRequests.Add(1)
defer al.activeRequests.Done()
if len(activeCandidates) > 1 && al.fallback != nil { if len(activeCandidates) > 1 && al.fallback != nil {
fbResult, fbErr := al.fallback.Execute( fbResult, fbErr := al.fallback.Execute(
ctx, ctx,
@ -1716,6 +1721,7 @@ func (al *AgentLoop) retryLLMCall(
var err error var err error
for attempt := 0; attempt < maxRetries; attempt++ { for attempt := 0; attempt < maxRetries; attempt++ {
al.activeRequests.Add(1)
resp, err = agent.Provider.Chat( resp, err = agent.Provider.Chat(
ctx, ctx,
[]providers.Message{{Role: "user", Content: prompt}}, []providers.Message{{Role: "user", Content: prompt}},
@ -1727,6 +1733,8 @@ func (al *AgentLoop) retryLLMCall(
"prompt_cache_key": agent.ID, "prompt_cache_key": agent.ID,
}, },
) )
al.activeRequests.Done()
if err == nil && resp != nil && resp.Content != "" { if err == nil && resp != nil && resp.Content != "" {
return resp, nil return resp, nil
} }