The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): park an undeliverable voice transcript instead of dropping it
Brooklyn Nicholsona236180b40ad
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.test.tsxindex 098dc0ba6f6..c76bdbf4a15 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.test.tsx@@ -12,9 +12,15 @@ const mocks = vi.hoisted(() => ({}))vi.mock('@nanostores/react', () => ({- useStore: (store: { get: () => unknown }) => store.get()+ useStore: (store: unknown) => store}))+vi.mock('nanostores', async () => {+ const actual = await vi.importActual<typeof import('nanostores')>('nanostores')++ return { ...actual, computed: (deps: unknown, fn: unknown) => fn }+})+vi.mock('@/i18n', () => ({useI18n: () => ({t: {@@ -75,11 +81,13 @@ vi.mock('@/store/wake-word', () => ({}))vi.mock('../focus', () => ({+ onComposerDictationRequest: vi.fn(() => () => undefined),onComposerVoiceToggleRequest: vi.fn(() => () => undefined)}))vi.mock('../scope', () => ({- useComposerScope: () => ({ $messages: { get: () => [] } })+ useComposerScope: () => ({ $messages: { get: () => [] } }),+ useComposerSurfaceId: () => null}))vi.mock('./use-auto-speak-replies', () => ({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 19ad0c0b7d2..f35eadffec3 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@@ -455,3 +455,94 @@ describe('useVoiceConversation honors the read-aloud toggle (#44263)', () => {await waitFor(() => expect(playSpeechTextMock).toHaveBeenCalled())})})++// #123357 Part 1 — when a barge capture genuinely cannot submit (live busy+// never clears within the settle window), the transcript must still reach the+// composer instead of vanishing: it is parked in the input so the user sees+// and can send it, and the loop goes back to listening.+describe('useVoiceConversation parks an undeliverable barge transcript (#123357)', () => {+ const parkText = vi.fn()+ const focusInput = vi.fn()++ beforeEach(() => {+ monitorCalls.length = 0+ vi.clearAllMocks()+ micHandle.start.mockResolvedValue(undefined)+ micHandle.stop.mockResolvedValue(null)+ })++ afterEach(cleanup)++ it('parks the transcript in the composer when live busy never clears', async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true })+ parkText.mockClear()+ focusInput.mockClear()++ const submitted: string[] = []+ const transcriptions: string[] = ['kick off the task', 'what about the other approach']++ const hook = renderHook(+ ({ busy }: HookProps) =>+ useVoiceConversation({+ busy,+ consumePendingResponse: vi.fn(),+ enabled: true,+ focusInput,+ onSubmit: async text => {+ submitted.push(text)+ // Mirrors the real wiring: a submitted turn makes the agent busy+ // (renderConversation's onBusyChange), so the drive effect arms+ // the full-duplex monitor for the generation phase.+ hook.rerender({ busy: true })+ },+ onTranscribeAudio: async () => transcriptions.shift() ?? '',+ parkText,+ pendingResponse: () => null+ }),+ { initialProps: { busy: false } }+ )++ await act(async () => {+ await hook.result.current.start()+ })+ await waitFor(() => expect(hook.result.current.status).toBe('listening'))++ micHandle.stop.mockResolvedValueOnce({+ audio: new Blob(['q'], { type: 'audio/webm' }),+ durationMs: 900,+ heardSpeech: true+ })+ await act(async () => {+ hook.result.current.stopTurn()+ })+ expect(submitted).toEqual(['kick off the task'])++ // The turn stays busy the whole time; the monitor is armed mid-generation+ // by the drive effect above (busy=true while status is 'thinking').+ await waitFor(() => expect(monitorCalls.length).toBeGreaterThan(0))++ const monitor = monitorCalls.at(-1)++ act(() => {+ monitor?.onSpeech()+ })++ // The interrupt never settles: busy stays true through the whole window.+ await act(async () => {+ await vi.advanceTimersByTimeAsync(6_000)+ })+ await act(async () => {+ await monitor?.onUtterance?.(new Blob(['barge'], { type: 'audio/webm' }))+ })+ await act(async () => {+ await vi.advanceTimersByTimeAsync(6_000)+ })++ expect(parkText).toHaveBeenCalledTimes(1)+ expect(parkText).toHaveBeenCalledWith('what about the other approach')+ expect(focusInput).toHaveBeenCalled()+ expect(submitted).toEqual(['kick off the task'])++ vi.useRealTimers()+ })+})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 68d91a9d820..176010f6e5f 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@@ -44,6 +44,11 @@ interface VoiceConversationOptions {onTranscribeAudio?: (audio: Blob, owner?: ResolvedOwner) => Promise<string>pendingResponse: () => PendingVoiceResponse | nullconsumePendingResponse: () => void+ /** Surface a transcript that cannot be delivered as a turn (live busy never+ * settled): park it in the composer input and focus it, so a spoken+ * interruption is never silently dropped (#123357). */+ parkText?: (text: string) => void+ focusInput?: () => void/** Awaited right before the mic is opened. Used to let the wake-word listener* fully release the capture device first, so the two never contend. */beforeMicOpen?: () => Promise<void> | void@@ -83,6 +88,8 @@ export function useVoiceConversation({onTranscribeAudio,pendingResponse,consumePendingResponse,+ parkText,+ focusInput,beforeMicOpen}: VoiceConversationOptions) {const { t } = useI18n()@@ -123,12 +130,23 @@ export function useVoiceConversation({const wasEnabledRef = useRef(enabled)const onStopWordRef = useRef(onStopWord)const onInterruptRef = useRef(onInterrupt)+ // `submitVoiceTurn` (the composer's real `onSubmit`) re-creates per render+ // and its busy guard captures THAT render's state; the barge monitor arms+ // once per turn, so `submitCapturedUtterance` can outlive the render that+ // created it and would otherwise hold that stale submit forever. Read the+ // latest callback at call time, mirroring `onInterruptRef` (#123357).+ const onSubmitRef = useRef(onSubmit)// eslint-disable-next-line no-restricted-syntax -- legitimate non-atom ref write (see eslint rule comment)useEffect(() => {onInterruptRef.current = onInterrupt}, [onInterrupt])+ // eslint-disable-next-line no-restricted-syntax -- legitimate non-atom ref write (see eslint rule comment)+ useEffect(() => {+ onSubmitRef.current = onSubmit+ }, [onSubmit])+// eslint-disable-next-line no-restricted-syntax -- legitimate non-atom ref write (see eslint rule comment)useEffect(() => {onStopWordRef.current = onStopWord@@ -534,10 +552,23 @@ export function useVoiceConversation({return}+ // Live busy never settled: submitting would be refused by the+ // composer's live-busy guard and the spoken interruption would be+ // lost. Park the transcript in the composer input instead — visible,+ // editable, one Enter away from sending — and resume listening.+ // Never drop a transcribed turn without a trace (#123357).+ if (busyRef.current) {+ parkText?.(transcript)+ focusInput?.()+ resumeListening()++ return+ }+awaitingSpokenResponseRef.current = truedropSpeechSession()consumePendingResponse()- await onSubmit(transcript)+ await onSubmitRef.current(transcript)if (live()) {setStatus('thinking')@@ -549,7 +580,7 @@ export function useVoiceConversation({}}},- [consumePendingResponse, onSubmit, onTranscribeAudio, voiceCopy.transcriptionFailed]+ [consumePendingResponse, onTranscribeAudio, voiceCopy.transcriptionFailed])/**