The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): edge-TTS fallback flushes sealed interims and skips stream re-probes
kshitijk4poorfeb503d68f79
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 070213502fb..b5d3ee8f9c9 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@@ -296,7 +296,8 @@ describe('useVoiceConversation playback rearm', () => {await waitFor(() =>expect(mocks.playSpeechText).toHaveBeenCalledWith('Fallback reply', {- source: 'voice-conversation'+ source: 'voice-conversation',+ syncOnly: true}))await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(2))@@ -311,7 +312,8 @@ describe('useVoiceConversation playback rearm', () => {await waitFor(() =>expect(mocks.playSpeechText).toHaveBeenCalledWith('The first sentence is ready.', {- source: 'voice-conversation'+ source: 'voice-conversation',+ syncOnly: true}))expect(mocks.handle.start).toHaveBeenCalledTimes(1)@@ -320,7 +322,8 @@ describe('useVoiceConversation playback rearm', () => {await waitFor(() =>expect(mocks.playSpeechText).toHaveBeenCalledWith('The second sentence is ready.', {- source: 'voice-conversation'+ source: 'voice-conversation',+ syncOnly: true}))await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(2))@@ -345,4 +348,47 @@ describe('useVoiceConversation playback rearm', () => {expect(mocks.playSpeechText).toHaveBeenCalledTimes(1)expect(mocks.handle.start).toHaveBeenCalledTimes(1)})++ it('speaks a sealed interim bubble while a tool is still running', async () => {+ mocks.useFallbackSpeech()+ let releaseSubmit: () => void = () => {}+ let response: null | { id: string; pending: boolean; text: string } = null++ const hook = renderHook(+ ({ busy, enabled }) =>+ useVoiceConversation({+ busy,+ consumePendingResponse: vi.fn(),+ enabled,+ onSubmit: async () => {+ await new Promise<void>(resolve => {+ releaseSubmit = resolve+ })+ // Interim bubble sealed (trimmed, no trailing space); tool running.+ response = { id: 'reply-edge', pending: false, text: 'I will check the file for you now.' }+ },+ onTranscribeAudio: async () => 'Hello',+ pendingResponse: () => response+ }),+ { initialProps: { busy: false, enabled: false } }+ )++ hook.rerender({ busy: false, enabled: true })+ await waitFor(() => expect(mocks.handle.start).toHaveBeenCalledTimes(1))+ await act(async () => {+ mocks.triggerSilence()+ })+ hook.rerender({ busy: true, enabled: true })+ await act(async () => {+ releaseSubmit()+ })++ await waitFor(() =>+ expect(mocks.playSpeechText).toHaveBeenCalledWith('I will check the file for you now.', {+ source: 'voice-conversation',+ syncOnly: true+ })+ )+ expect(mocks.handle.start).toHaveBeenCalledTimes(1)+ })})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 cec90c14aea..1b25e29e941 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@@ -501,10 +501,16 @@ export function useVoiceConversation({ensureBargeMonitor()playing = true- const playback = playSpeechText(sentence, { ...ownerRef.current, source: 'voice-conversation' })- const sentenceStartSequence = $voicePlayback.get().sequence- ownedSequence = sentenceStartSequence- speechStartSequenceRef.current = sentenceStartSequence+ // The stream path (client-direct, else WS relay) already answered+ // `fallback` or was unavailable for this reply — POST each sentence+ // straight to /api/audio/speak (same server TTS) instead of re-probing.+ const playback = playSpeechText(sentence, {+ ...ownerRef.current,+ source: 'voice-conversation',+ syncOnly: true+ })+ ownedSequence = $voicePlayback.get().sequence+ speechStartSequenceRef.current = ownedSequencelet playbackFailed = falsevoid playback@@ -525,7 +531,7 @@ export function useVoiceConversation({return}- const stopped = $voicePlayback.get().sequence > sentenceStartSequence+ const stopped = $voicePlayback.get().sequence > ownedSequenceif (bargedRef.current || stopped) {finishFallback(bargedRef.current, stopped && !bargedRef.current)@@ -555,9 +561,12 @@ export function useVoiceConversation({sourceLength = response.text.length}- if (!response.pending && !busyRef.current && !responseFinished) {- responseFinished = true+ if (!response.pending && !responseFinished) {+ // A sealed interim bubble while a tool runs: speak its trimmed last+ // sentence now (mirrors feedSpeechSession's session.flush) instead+ // of holding it for the whole tool run. Finished only once idle.speechQueue.push(...sentenceBuffer.flush())+ responseFinished = !busyRef.current}playNext()diff --git a/apps/desktop/src/lib/voice-playback.ts b/apps/desktop/src/lib/voice-playback.tsindex 94ece9ec705..17cecc2f532 100644--- a/apps/desktop/src/lib/voice-playback.ts+++ b/apps/desktop/src/lib/voice-playback.ts@@ -72,6 +72,10 @@ function currentState(* halves → the active (connection, profile). */export interface VoicePlaybackOptions extends OwnerScope {messageId?: string | null+ /** Skip the client-direct/stream rungs and POST straight to /api/audio/speak.+ * For callers whose stream path (client-direct, else WS relay) already+ * answered `fallback` this reply; the relay may not have been probed. */+ syncOnly?: booleansource: VoicePlaybackSource}@@ -675,7 +679,7 @@ export async function playSpeechText(text: string, options: VoicePlaybackOptionstry {// Ladder: client-direct synthesis (profile's own TTS, no gateway audio// hop) → streaming WS relay → POST data-URL fallback.- const direct = await directTtsConfig(options).catch(() => null)+ const direct = options.syncOnly ? null : await directTtsConfig(options).catch(() => null)if (direct && isCurrent()) {const session = openClientDirectSpeechSession(direct, options)@@ -699,7 +703,7 @@ export async function playSpeechText(text: string, options: VoicePlaybackOptionsreturn false}- const streamUrl = await resolveSpeakStreamUrl(options)+ const streamUrl = options.syncOnly ? null : await resolveSpeakStreamUrl(options)if (streamUrl && isCurrent()) {const outcome = await playSpeechStream(streamUrl, speakableText, options)