The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): rearm voice conversation after stop (#108301)
Tranquil-Flowef6a3d0690d9
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation-rearm.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation-rearm.test.tsxindex 49a364d9eb0..abb9f3d32b5 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation-rearm.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation-rearm.test.tsx@@ -48,6 +48,7 @@ const mocks = vi.hoisted(() => {resolveStreamStart?.()resolveStreamStart = null},+ consumePendingResponse: vi.fn(),deferFallbackPlayback() {deferFallbackPlayback = true},@@ -152,7 +153,7 @@ function renderRearmConversation(responseId: string, responseText: string) {({ enabled }) =>useVoiceConversation({busy: false,- consumePendingResponse: vi.fn(),+ consumePendingResponse: mocks.consumePendingResponse,enabled,onSubmit: async () => {response = { id: responseId, pending: false, text: responseText }@@ -262,9 +263,11 @@ describe('useVoiceConversation playback rearm', () => {mocks.continueStreamStart()})- await waitFor(() => expect(hook.result.current.status).toBe('idle'))+ // The reply is silenced, but the conversation stays live and re-listens.+ await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(2))expect(mocks.stopVoicePlayback).toHaveBeenCalledTimes(2)- expect(mocks.handle.start).toHaveBeenCalledTimes(1)+ expect(mocks.consumePendingResponse).toHaveBeenCalledTimes(2)+ expect(hook.result.current.status).toBe('listening')})it('does not start fallback playback after Stop during stream discovery', async () => {@@ -280,12 +283,14 @@ describe('useVoiceConversation playback rearm', () => {mocks.continueStreamStart()})- await waitFor(() => expect(hook.result.current.status).toBe('idle'))+ // No fallback playback, but the loop re-arms the mic instead of wedging.+ await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(2))expect(mocks.playSpeechText).not.toHaveBeenCalled()- expect(mocks.handle.start).toHaveBeenCalledTimes(1)+ expect(mocks.consumePendingResponse).toHaveBeenCalledTimes(2)+ expect(hook.result.current.status).toBe('listening')})- it('does not re-arm after an external Stop during streaming playback', async () => {+ it('re-arms and consumes the pending response after an external Stop during streaming playback', async () => {const hook = renderRearmConversation('reply-stopped', 'Playing now')await beginReply(hook)@@ -296,8 +301,9 @@ describe('useVoiceConversation playback rearm', () => {mocks.finishSpeech('done')})- await waitFor(() => expect(hook.result.current.status).toBe('idle'))- expect(mocks.handle.start).toHaveBeenCalledTimes(1)+ await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(2))+ expect(mocks.consumePendingResponse).toHaveBeenCalledTimes(2)+ expect(hook.result.current.status).toBe('listening')})it('re-arms the microphone after normal fallback playback completes', async () => {diff --git a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.ts b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.tsindex 45000574bd9..68d91a9d820 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.ts@@ -405,7 +405,11 @@ export function useVoiceConversation({const settleAfterSpeech = useCallback((barged: boolean, stoppedDuringSetup = false) => {- if (barged || !awaitingSpokenResponseRef.current) {+ const stoppedExternally =+ stoppedDuringSetup ||+ (speechStartSequenceRef.current > 0 && $voicePlayback.get().sequence > speechStartSequenceRef.current)++ if (barged || stoppedExternally || !awaitingSpokenResponseRef.current) {awaitingSpokenResponseRef.current = falseconsumePendingResponse()}@@ -424,16 +428,13 @@ export function useVoiceConversation({dropSpeechSession()- // If stopVoicePlayback() was called externally (Stop button, end), the- // voice-playback sequence has advanced past what we captured at speech- // start — don't auto-start the next sentence, the user chose to stop.- const stoppedByUser =- stoppedDuringSetup ||- (speechStartSequenceRef.current > 0 && $voicePlayback.get().sequence > speechStartSequenceRef.current)-+ // An external stopVoicePlayback() (Stop/Esc) silences the current reply;+ // it does not end hands-free conversation mode. end() owns that path and+ // clears pendingStartRef before disabling the loop. While still enabled,+ // always re-arm so the user can speak immediately after cutting TTS.speechStartSequenceRef.current = 0- if (enabledRef.current && !stoppedByUser) {+ if (enabledRef.current) {pendingStartRef.current = true}