The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): an exact-retry receipt with status unknown is an admitted send
Tekniumc4880d6949d3
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsxindex 61e4b594229..6859841104f 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx@@ -89,7 +89,7 @@ describe('durable submit acknowledgement', () => {const requestGateway = vi.fn(async (_method: string, params?: Record<string, unknown>) => {expect(Object.values(journal.read())).toHaveLength(1)- return { admission_id: 'server-admission', submission_id: params?.submission_id, session_id: params?.session_id, status: accepted ? 'queued' : 'unknown' } as never+ return { admission_id: 'server-admission', submission_id: accepted ? params?.submission_id : 'other-input', session_id: params?.session_id, status: 'queued' } as never})try {@@ -154,7 +154,7 @@ describe('durable submit acknowledgement', () => {const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {if (method === 'slash.exec') {return { type: 'skill', name: 'private-skill', message: 'expanded skill' } as never}- return { admission_id: params?.submission_id, status: 'unknown' } as never+ return { admission_id: 'other-input', status: 'queued' } as never})let handle: HarnessHandle | null = null@@ -176,7 +176,8 @@ describe('durable submit acknowledgement', () => {[{ admission_id: 'entry-id', status: 'terminal' }, true],[{ admission_id: 'canonical-admission', submission_id: 'entry-id', session_id: RUNTIME_SESSION_ID, status: 'queued' }, true],[{ admission_id: 'canonical-admission', submission_id: 'entry-id', session_id: 'wrong-destination', status: 'queued' }, false],- [{ admission_id: 'entry-id', status: 'unknown' }, false]+ // An exact retry of an admission the owner lost mid-turn: admitted, never replayed (Discard resolves it).+ [{ admission_id: 'entry-id', status: 'unknown' }, true]])('requires the matching authoritative receipt: %j', async (receipt, accepted) => {const requestGateway = vi.fn(async () => receipt as never)let handle: HarnessHandle | null = nulldiff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsxindex af7c17c8dd9..f065eb53c8f 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx@@ -322,7 +322,7 @@ describe('submission intent destinations', () => {expect(expansions).toBe(slash ? 1 : 0)})- it.each(['missing', 'wrong', 'unknown', '4094', 'lost-legacy'])(+ it.each(['missing', 'wrong', '4094', 'lost-legacy'])('requires a matching receipt or one pre-admission legacy refusal: %s',async mode => {const { deps, requestGateway } = setup()@@ -344,7 +344,7 @@ describe('submission intent destinations', () => {return { ok: true } as never}- return { admission_id: mode === 'wrong' ? 'wrong-id' : params?.submission_id, status: 'unknown' } as never+ return { admission_id: 'wrong-id', status: 'queued' } as never})let hook = renderHook(() => useSubmitPrompt(deps))await act(async () => {diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsxnew file mode 100644index 00000000000..1a943ab2ae6--- /dev/null+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit-unknown-receipt.test.tsx@@ -0,0 +1,80 @@+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 { readPendingSubmissions } from '@/store/pending-submissions'+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>++// Adolanium reg-4: the owner answers an exact retry with the EXISTING admission, which may be+// `unknown` (claimed, then the owner died mid-turn). That send was admitted; dropping it as a+// rejection hid the user's message and the retry identity, and invited a duplicate resend.+it('an exact retry answered `unknown` keeps the bubble, retires the retry identity and never replays', async () => {+ let state: ClientSessionState = createClientSessionState()++ const requestGateway = vi.fn(async (_method: string, params?: Record<string, unknown>) => {+ if (requestGateway.mock.calls.length === 1) {+ throw new Error('connection closed')+ }++ return { admission_id: params?.submission_id, session_id: 'runtime-a', status: 'unknown' } 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('lost turn', { submission_id: 'lost-1' })).toBe(false)+ })+ await act(async () => {+ expect(await result.current('lost turn', { submission_id: 'lost-1' })).toBe(true)+ })++ expect(requestGateway.mock.calls.filter(([method]) => method === 'prompt.submit')).toHaveLength(2)+ expect(state.messages.filter(message => message.role === 'user')).toHaveLength(1)+ expect(state.busy).toBe(false)+ expect(readPendingSubmissions('stored-a')['lost-1']).toMatchObject({ status: 'unknown', text: 'lost turn' })+ expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1') ?? '').not.toContain('lost turn')+})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 8d79ab77199..5eb0ce4ac34 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@@ -1184,7 +1184,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {!legacyAccepted &&((result?.submission_id ?? result?.admission_id) !== submissionId ||(result?.session_id !== undefined && result.session_id !== receiptSessionId) ||- !['queued', 'started', 'terminal'].includes(result?.status ?? ''))+ !['queued', 'started', 'terminal', 'unknown'].includes(result?.status ?? ''))) {dropOptimistic(sessionId)releaseBusy()@@ -1203,7 +1203,10 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {// Queued is also the initial receipt for an idle session's first// turn. Keep its input and any start event that raced this ACK;// explicit queue-only sends never inserted an optimistic bubble.- if (result.status === 'terminal') {+ // An exact retry of an admission the owner lost mid-turn answers `unknown`: it was+ // admitted (never replay it) and no turn will run. Keep the bubble; the pending+ // fanout's lost card offers Discard (prompt.resolve_unknown).+ if (result.status === 'terminal' || result.status === 'unknown') {// Deduplication does not start a turn or promise another terminal// event. Remove our duplicate bubble, but preserve any live turn// that an owner event established while the receipt was in flight.@@ -1211,7 +1214,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {receiptSessionId,state => ({...state,- messages: state.messages.filter(message => message.id !== optimisticId),+ messages: result.status === 'unknown' ? state.messages : state.messages.filter(message => message.id !== optimisticId),...(!state.turnLive &&!state.streamId &&!state.sawAssistantPayload && {