Skip to content

The agent that grows with you

fix(desktop): reset the clarify card when the gateway sends the next question

Tekniumc89b736df2eb
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.tsx
index 446a842e6f2..7981fff3634 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
@@ -217,6 +217,39 @@ describe('ClarifyTool live card stays mounted across settle', () => {
expect(screen.getByRole('button', { name: /staging/ }).hasAttribute('disabled')).toBe(false)
expect(screen.queryByText('Which region?')).toBeNull()
})
+
+ it('the next card of a one-at-a-time batch is answerable after the first was confirmed', async () => {
+ // The same tool row stays mounted from question 1 to question 2; the first
+ // confirm's submitting latch must not carry over and disable the second card.
+ $activeSessionId.set('session-1')
+ $gateway.set({ request: vi.fn().mockResolvedValue({ ok: true }) } as never)
+ setClarifyRequest({
+ questions: [{ choices: ['staging', 'production'], multiSelect: false, qid: 'request-1', question: 'Which deployment target?' }],
+ requestId: 'request-1',
+ sessionId: 'session-1'
+ })
+ const args = {
+ questions: [
+ { question: 'Which deployment target?', choices: ['staging', 'production'] },
+ { question: 'Which region?', choices: ['us', 'eu'] }
+ ]
+ }
+ const props = { ...liveClarifyProps(), args, argsText: JSON.stringify(args) }
+ renderClarify(<ClarifyTool {...props} />)
+
+ fireEvent.click(screen.getByRole('button', { name: /staging/ }))
+ fireEvent.click(screen.getByRole('button', { name: /Confirm and continue/ }))
+ await waitFor(() => expect(gatewayMocks.requestGatewayForAgent.mock.calls.length + 0).toBeGreaterThanOrEqual(0))
+ await act(async () => {
+ setClarifyRequest({
+ questions: [{ choices: ['us', 'eu'], multiSelect: false, qid: 'request-2', question: 'Which region?' }],
+ requestId: 'request-2',
+ sessionId: 'session-1'
+ })
+ })
+
+ await waitFor(() => expect(screen.getByRole('button', { name: /^.*eu/ }).hasAttribute('disabled')).toBe(false))
+ })
})
describe('ClarifyTool choice selection', () => {
diff --git a/apps/desktop/src/components/assistant-ui/clarify/pending.tsx b/apps/desktop/src/components/assistant-ui/clarify/pending.tsx
index 5f6d61e1874..645cfba8e3e 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/pending.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/pending.tsx
@@ -71,6 +71,21 @@ export function ClarifyToolPending({
const [staged, setStaged] = useState<Record<string, { choices: string[]; draft: string }>>({})
const [submitting, setSubmitting] = useState(false)
+ // A canonical gateway answers a batch one card at a time through the SAME
+ // mounted tool row: a new live request is a new card, so the previous card's
+ // submit latch and staged picks must not carry over (that left question 2
+ // disabled behind question 1's spinner).
+ const [cardRequestId, setCardRequestId] = useState(request?.requestId)
+
+ if (request?.requestId !== cardRequestId) {
+ setCardRequestId(request?.requestId)
+
+ if (request?.requestId) {
+ setSubmitting(false)
+ setStaged({})
+ }
+ }
+
// 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.