The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep typed clarify answers when a lock fails or the card staged a pick
alt-glitchfb4a0d5e052a
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsxindex 31557705e27..d96c23f0a30 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx@@ -640,6 +640,34 @@ describe('useComposerSubmit with a clarify parked on the session', () => {expect(hasOpenServerRequest('req-two')).toBe(true)})+ it('rolls back only the answer whose lock failed', async () => {+ let failFirst: (error: Error) => void = () => {}++ const request = vi+ .fn()+ .mockImplementationOnce(() => new Promise((_resolve, reject) => (failFirst = reject)))+ .mockResolvedValue({ status: 'ok', remaining: ['q2'] })++ setGateway(request)+ rememberServerRequest({ fail: vi.fn(), id: 'req-three', method: 'clarify', params: {}, respond })+ $clarifyRequests.set({+ 'runtime-session': {+ requestId: 'req-three',+ questions: ['q0', 'q1', 'q2'].map(qid => ({ choices: null, multiSelect: false, qid, question: `${qid}?` })),+ sessionId: 'runtime-session'+ }+ })++ for (const text of ['first', 'second']) {+ const { hook } = renderSubmitHook({ busy: true, text })+ act(() => hook.result.current.submitDraft())+ }++ await act(async () => failFirst(new Error('socket closed')))++ await waitFor(() => expect($clarifyRequests.get()['runtime-session']?.lockedAnswers).toEqual({ q1: 'second' }))+ })+it('leaves the question alone for an empty Enter (Stop, not an answer)', () => {parkClarify('runtime-session')const { hook, onCancel } = renderSubmitHook({ busy: true })diff --git a/apps/desktop/src/components/assistant-ui/clarify/clarify-tool.test.tsx b/apps/desktop/src/components/assistant-ui/clarify/clarify-tool.test.tsxindex f8495ef2506..71d83b22170 100644--- a/apps/desktop/src/components/assistant-ui/clarify/clarify-tool.test.tsx+++ b/apps/desktop/src/components/assistant-ui/clarify/clarify-tool.test.tsx@@ -794,6 +794,26 @@ describe('ClarifyTool batch card', () => {expect(screen.getByText('1 of 2 answered')).toBeTruthy()})+ it('lets an answer locked from the composer replace the pick staged on the card', () => {+ renderLiveBatch()+ fireEvent.click(screen.getByRole('button', { name: /red/ }))++ act(() =>+ setClarifyRequest({+ lockedAnswers: { q0: 'blue' },+ questions: [+ { choices: ['red', 'blue'], multiSelect: false, qid: 'q0', question: 'Color?' },+ { choices: null, multiSelect: false, qid: 'q1', question: 'Name?' }+ ],+ requestId: 'request-batch',+ sessionId: 'session-1'+ })+ )++ expect(screen.getByRole('button', { name: /blue/ }).getAttribute('aria-pressed')).toBe('true')+ expect(screen.getByRole('button', { name: /red/ }).getAttribute('aria-pressed')).toBe('false')+ })+it('Skip cancels the whole batch with an empty response (no answers)', async () => {const { request, respond } = renderLiveBatch()diff --git a/apps/desktop/src/components/assistant-ui/clarify/pending.tsx b/apps/desktop/src/components/assistant-ui/clarify/pending.tsxindex 86778c1c369..bc15ac6a9fb 100644--- a/apps/desktop/src/components/assistant-ui/clarify/pending.tsx+++ b/apps/desktop/src/components/assistant-ui/clarify/pending.tsx@@ -77,9 +77,12 @@ export function ClarifyToolPending({const [staged, setStaged] = useState<Record<string, { choices: string[]; draft: string }>>({})const [submitting, setSubmitting] = useState(false)- // Reconnect replay: answers the server already locked (an earlier window's- // partial progress) pre-stage their questions so the restored card shows- // them selected instead of blank.+ // Locked answers (a reconnect replay, or text typed in the composer) stage+ // their questions. A newly locked answer replaces what the card staged, so+ // Confirm never re-sends an older pick; an answer seen before is left alone,+ // so a later edit on the card stands.+ const [seenLocks, setSeenLocks] = useState<Record<string, null | string>>({})+useEffect(() => {const lockedAnswers = request?.lockedAnswers@@ -87,13 +90,15 @@ export function ClarifyToolPending({return}+ setSeenLocks(lockedAnswers)+setStaged(current => {const next = { ...current }for (const question of questions) {const answer = lockedAnswers[question.qid]- if (answer === undefined || answer === null || next[question.qid]) {+ if (answer === undefined || answer === null || seenLocks[question.qid] === answer) {continue}diff --git a/apps/desktop/src/store/clarify.ts b/apps/desktop/src/store/clarify.tsindex 7b6512bc091..c9436520e25 100644--- a/apps/desktop/src/store/clarify.ts+++ b/apps/desktop/src/store/clarify.ts@@ -474,19 +474,39 @@ function lockTypedAnswer(request: ClarifyRequest, text: string): boolean {}).catch(error => {forgetSettledClarify(request.requestId)-- const current = $clarifyRequests.get()[keyFor(request.sessionId)]-- if (hasOpenServerRequest(request.requestId) && (!current || current.requestId === request.requestId)) {- setClarifyRequest(request)- }-+ rollBackTypedAnswer(request, lockedAnswers, question.qid, answer)notifyError(error, translateNow('assistant.clarify.sendFailed'))})return true}+/** Undo one failed lock without touching answers locked after it. */+function rollBackTypedAnswer(+ request: ClarifyRequest,+ lockedAnswers: Record<string, null | string>,+ qid: string,+ answer: string+): void {+ const current = $clarifyRequests.get()[keyFor(request.sessionId)]++ // The last answer cleared the card: bring it back while the server still waits.+ const live =+ current?.requestId === request.requestId+ ? current+ : !current && hasOpenServerRequest(request.requestId)+ ? { ...request, lockedAnswers }+ : null++ if (live?.lockedAnswers?.[qid] !== answer) {+ return+ }++ const kept = { ...live.lockedAnswers }+ delete kept[qid]+ setClarifyRequest({ ...live, lockedAnswers: kept })+}+/** The row typed text names, by id or label (any case). */function matchSetupRow(labels: Record<string, string>, text: string): string | undefined {const typed = text.trim().toLowerCase()