The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): STT filter trailing strip + live barge-in disarm (#127275)
Brooklyn Nicholson4b3cbf8c60bb
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.test.tsxindex f35eadffec3..31ef5a149dd 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-voice-conversation.test.tsx@@ -301,6 +301,31 @@ describe('useVoiceConversation full-duplex barge-in', () => {expect(monitorCalls.length).toBe(armed)})++ it('disarms the live monitor when voice.barge_in flips off mid-turn (#126708)', async () => {+ const { hook } = renderConversation()++ try {+ await act(async () => {+ await hook.result.current.start()+ })+ await enterThinking(hook)+ await waitFor(() => expect(monitorCalls.length).toBeGreaterThan(0))+ expect(stopMonitor).not.toHaveBeenCalled()++ // The config refresh lands mid-turn: barge-in off must stop the LIVE+ // monitor, not just gate future ones.+ act(() => {+ $bargeInEnabled.set(false)+ })++ await waitFor(() => expect(stopMonitor).toHaveBeenCalledTimes(1))+ } finally {+ act(() => {+ $bargeInEnabled.set(true)+ })+ }+ })})// #126708 — over speakers the reply bleeds into the mic and trips thediff --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 2feaafd6215..9e962d97296 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@@ -634,6 +634,38 @@ export function useVoiceConversation({})}, [pendingResponse, submitCapturedUtterance])+ // `voice.barge_in` flipping off MID-TURN disarms the live monitor too: the+ // gate above only covers creation, so a config refresh that says barge-in is+ // off must also stop a monitor that already armed, or the rest of the turn+ // keeps interrupting on speech while the pref says off. A capture that was+ // mid-flight is dropped (the pref changed under it) and the loop resumes+ // normal listening the way a failed capture does.+ // eslint-disable-next-line no-restricted-syntax -- atom-edge CLEANUP of the live monitor handle, not a mirror: nothing copies atom state into a ref+ useEffect(() => {+ const unsubscribe = $bargeInEnabled.subscribe(enabled => {+ if (enabled) {+ return+ }++ stopBargeMonitorRef.current?.()+ stopBargeMonitorRef.current = null++ if (bargeCapturePendingRef.current) {+ bargeCapturePendingRef.current = false+ bargedRef.current = false+ bargeEchoTextRef.current = ''++ if (enabledRef.current && !mutedRef.current) {+ pendingStartRef.current = true+ }++ setStatus('idle')+ }+ })++ return unsubscribe+ }, [])+/** Push any new reply text into the live session; finish when complete. */const feedSpeechSession = useCallback((responseId: string) => {diff --git a/apps/desktop/src/lib/voice-client-direct.test.ts b/apps/desktop/src/lib/voice-client-direct.test.tsindex e32cdb267af..19cb91580ff 100644--- a/apps/desktop/src/lib/voice-client-direct.test.ts+++ b/apps/desktop/src/lib/voice-client-direct.test.ts@@ -218,6 +218,23 @@ describe('transcribeAudioClientDirect', () => {expect(isSttSilenceHallucination('Thank you.', null)).toBe(false)})+ it('strips only trailing .! like the relay rstrip — internal punctuation is a real turn', () => {+ const filter = {+ phrases: ['thank you', 'bye', 'you', 'the end'],+ repeat_regex: '^(?:thank you|thanks|bye|you|ok|okay|the end|[.,!\\\\s])+$'+ }++ // Internal punctuation survives the strip, so `thank. you` is not the+ // phrase `thank you` — the relay keeps it as a real turn, and the+ // client-direct path must agree (wire parity).+ expect(isSttSilenceHallucination('thank. you', filter)).toBe(false)+ expect(isSttSilenceHallucination('Than-k you. thank! you', filter)).toBe(false)++ // Trailing punctuation is still stripped the way `rstrip('.!')` does.+ expect(isSttSilenceHallucination('Thank you.!', filter)).toBe(true)+ expect(isSttSilenceHallucination('The end...', filter)).toBe(true)+ })+it('surfaces provider rejections instead of silently relaying', async () => {mockDesktopApi({ ok: true, stt: directStt, tts: relay })vi.stubGlobal(diff --git a/apps/desktop/src/lib/voice-client-direct.ts b/apps/desktop/src/lib/voice-client-direct.tsindex a4a1269cc26..2b751faa82c 100644--- a/apps/desktop/src/lib/voice-client-direct.ts+++ b/apps/desktop/src/lib/voice-client-direct.ts@@ -229,7 +229,10 @@ export function isSttSilenceHallucination(return true}- if (filter.phrases.includes(cleaned.replaceAll('!', '').replaceAll('.', ''))) {+ // Trailing `.!` only — the relay strips `cleaned.rstrip('.!')`, so an+ // internal period (`thank. you`) stays internal and the transcript stays+ // a real turn on both paths, never just one.+ if (filter.phrases.includes(cleaned.replace(/[.!]+$/, ''))) {return true}