From ee959d5ba00f415cabfe990914f4a9074f396893 Mon Sep 17 00:00:00 2001 From: Cytown Date: Thu, 12 Mar 2026 16:05:28 +0800 Subject: [PATCH] fix for review --- cmd/picoclaw/internal/gateway/helpers.go | 9 ++++++--- pkg/agent/loop.go | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/picoclaw/internal/gateway/helpers.go b/cmd/picoclaw/internal/gateway/helpers.go index a449927bf..4929738b2 100644 --- a/cmd/picoclaw/internal/gateway/helpers.go +++ b/cmd/picoclaw/internal/gateway/helpers.go @@ -488,9 +488,12 @@ func restartServices( } // Wire up voice transcription with new config - if transcriber := voice.DetectTranscriber(cfg); transcriber != nil { - al.SetTranscriber(transcriber) - logger.InfoCF("voice", "Transcription enabled (agent-level)", map[string]any{"provider": transcriber.Name()}) + transcriber := voice.DetectTranscriber(cfg) + al.SetTranscriber(transcriber) // This will set it to nil if disabled + 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 diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 5038b70d9..a99f67bec 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -49,6 +49,8 @@ type AgentLoop struct { cmdRegistry *commands.Registry mcp mcpRuntime mu sync.RWMutex + // Track active requests for safe provider cleanup + activeRequests sync.WaitGroup } // processOptions configures how a message is processed @@ -1059,6 +1061,9 @@ func (al *AgentLoop) runLLMIteration( } callLLM := func() (*providers.LLMResponse, error) { + al.activeRequests.Add(1) + defer al.activeRequests.Done() + if len(activeCandidates) > 1 && al.fallback != nil { fbResult, fbErr := al.fallback.Execute( ctx, @@ -1716,6 +1721,7 @@ func (al *AgentLoop) retryLLMCall( var err error for attempt := 0; attempt < maxRetries; attempt++ { + al.activeRequests.Add(1) resp, err = agent.Provider.Chat( ctx, []providers.Message{{Role: "user", Content: prompt}}, @@ -1727,6 +1733,8 @@ func (al *AgentLoop) retryLLMCall( "prompt_cache_key": agent.ID, }, ) + al.activeRequests.Done() + if err == nil && resp != nil && resp.Content != "" { return resp, nil }