The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a voice_stopped prompt.submit reply is a settled send, not a mismatch
Tekniumff0698f3f0f8
diff --git a/apps/desktop/src/api/canonical-protocol.test.ts b/apps/desktop/src/api/canonical-protocol.test.tsindex bdcb61fb470..9be58a6f092 100644--- a/apps/desktop/src/api/canonical-protocol.test.ts+++ b/apps/desktop/src/api/canonical-protocol.test.ts@@ -101,6 +101,16 @@ test('canonical create retries retain identity', () => {expect(protocol.prepare('session.create', params).request_id).not.toBe(first.request_id)})+// TUI-26: a bare stop phrase typed into a LOCAL voice chat (turned on by another viewer) ends the+// chat on the owner and admits nothing; the owner answers `{voice_stopped: true}`.+test('a voice_stopped prompt.submit reply is a settled no-admission receipt, never a mismatch', () => {+ const protocol = new CanonicalDesktopProtocol()+ const params = protocol.prepare('prompt.submit', { session_id: 's', text: 'stop' })+ const receipt = protocol.result('prompt.submit', params, { voice_stopped: true, extra: 'dropped' })+ expect(receipt).toEqual({ voice_stopped: true, session_id: 's', submission_id: params.submission_id })+ expect(() => protocol.result('prompt.submit', params, { voice_stopped: false })).toThrow('destination')+})+test('canonical receipts preserve admission identity and replay restores fenced controls', () => {const protocol = new CanonicalDesktopProtocol()const receipt = protocol.result('prompt.submit', { session_id: 's', submission_id: 'input' }, { admission_id: 'admission', ref: { session_id: 's', profile_id: '/tmp/profile' }, status: 'queued' })diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.tsindex 1080c8db139..7173b03b534 100644--- a/apps/desktop/src/api/canonical-protocol.ts+++ b/apps/desktop/src/api/canonical-protocol.ts@@ -600,6 +600,12 @@ export class CanonicalDesktopProtocol {private admissionReceipt(method: string, params: Record<string, unknown>, value: any): any {if (method === 'prompt.submit') {+ // TUI-26: a bare stop phrase typed into a LOCAL voice chat ended that chat on the owner and+ // admitted nothing. An allowlisted no-admission variant: only these fields pass through.+ if (value.voice_stopped === true && value.admission_id === undefined && value.ref === undefined) {+ return { voice_stopped: true, session_id: params.session_id, submission_id: params.submission_id ?? params.input_id }+ }+if (value.ref?.session_id !== params.session_id || typeof value.admission_id !== 'string') {throw new Error('Canonical admission receipt destination mismatch')}diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsxnew file mode 100644index 00000000000..a0357628a9d--- /dev/null+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-voice-stopped.test.tsx@@ -0,0 +1,73 @@+import { act, cleanup, renderHook } from '@testing-library/react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'++import { en } from '@/i18n/en'+import { createClientSessionState } from '@/lib/chat-runtime'+import { $activeGatewayProfile } from '@/store/profile'+import { $connection, $sessions } from '@/store/session'+import { $sessionStates } from '@/store/session-states'++import { useSubmitPrompt } from './submit'+import type { GatewayRequest } from './utils'++vi.mock('@/store/gateway', async original => ({+ ...(await original<Record<string, unknown>>()),+ retainGatewayForSessionTurn: vi.fn(async () => () => undefined)+}))++beforeEach(() => {+ window.localStorage.clear()+ $sessions.set([])+ $sessionStates.set({})+ $connection.set(null)+ $activeGatewayProfile.set('default')+})+afterEach(() => {+ cleanup()+ vi.restoreAllMocks()+})++type ClientSessionState = ReturnType<typeof createClientSessionState>++// TUI-26: a Desktop viewer of a LOCAL session whose voice chat another viewer (Ink) turned on types+// a bare "stop". The owner ends that voice chat and admits nothing: `{voice_stopped: true}`. The send+// is settled (no error bubble, no retry identity left), and its bubble goes, since no turn holds it.+it('a voice_stopped receipt settles the send with no turn, no error and no retained retry', async () => {+ let state: ClientSessionState = createClientSessionState()++ const requestGateway = vi.fn(async (_method: string, params?: Record<string, unknown>) =>+ ({ voice_stopped: true, session_id: 'runtime-a', submission_id: params?.submission_id }) as never+ )++ const deps = {+ activeSessionIdRef: { current: 'runtime-a' as string | null },+ selectedStoredSessionIdRef: { current: 'stored-a' as string | null },+ busyRef: { current: false },+ copy: en.desktop,+ createBackendSessionForSend: vi.fn(async () => null),+ getRoutedStoredSessionId: () => null,+ getRuntimeIdForStoredSession: () => 'runtime-a',+ getRouteToken: () => 'same-route',+ requestGateway: requestGateway as GatewayRequest,+ runtimeIdByStoredSessionIdRef: { current: new Map([['stored-a', 'runtime-a']]) },+ resumeStoredSession: vi.fn(),+ syncAttachmentsForSubmit: vi.fn(async (sessionId: string) => ({ sessionId, attachments: [] })),+ updateSessionState: vi.fn((_sid: string, updater: (s: ClientSessionState) => ClientSessionState) => {+ state = updater(state)++ return state+ })+ }++ const { result } = renderHook(() => useSubmitPrompt(deps as never))+ await act(async () => {+ expect(await result.current('stop', { submission_id: 'stop-1' })).toBe(true)+ })++ expect(requestGateway.mock.calls.filter(([method]) => method === 'prompt.submit')).toHaveLength(1)+ expect(state.messages.filter(message => message.role === 'user')).toHaveLength(0)+ expect(state.messages.some(message => message.error)).toBe(false)+ expect(state.busy).toBe(false)+ expect(state.awaitingResponse).toBe(false)+ expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1') ?? '').not.toContain('stop-1')+})diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.tsindex 8fa8e0d3076..33398ff314b 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts@@ -67,6 +67,7 @@ import {isProviderSetupError,isSessionBusyError,isTargetSessionBusy,+ isVoiceStoppedReceipt,ownershipErrorSurface,refusalDroppedImages,releaseSubmitInFlight,@@ -196,6 +197,8 @@ type SubmitReceipt = Pick<PromptSubmitResult, 'forwarded' | 'user_row_id'> & {submission_id?: stringsession_id?: stringstatus?: string+ /** TUI-26: the owner ended the session's voice chat on a typed stop phrase and admitted nothing. */+ voice_stopped?: boolean}/** A refusal the backend issued before admitting anything, so an identityless retry cannot duplicate a turn. */@@ -1210,6 +1213,15 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {// Validate the admission receipt and bind it to the optimistic bubble.// Returns false when the receipt is not this send's admission.const applySubmitReceipt = (result: SubmitReceipt, receiptSessionId: string): boolean => {+ if (isVoiceStoppedReceipt(legacyAccepted, result)) {+ // Settled with no turn: the stop phrase ended the voice chat another viewer runs. No+ // turn holds the bubble, so it goes, and nothing is tracked as pending.+ dropOptimistic(receiptSessionId)+ releaseBusy()++ return true+ }+if (!legacyAccepted &&((result?.submission_id ?? result?.admission_id) !== submissionId ||diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.tsindex 4e6e181fe24..9b94d90e2ec 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts@@ -355,6 +355,11 @@ export function isForwardedReceipt(return legacyAccepted && result?.forwarded === true && result.status === 'queued'}+/** TUI-26: the owner ended the session's voice chat on a typed stop phrase and admitted nothing. */+export function isVoiceStoppedReceipt(legacyAccepted: boolean, result: { voice_stopped?: boolean } | undefined): boolean {+ return !legacyAccepted && result?.voice_stopped === true+}+const sleep = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms))// Retry a gateway call across transient "session busy" so it never reaches the