Skip to content

The agent that grows with you

refactor(desktop): render the batch clarify preview through the live form

teknium147ccd968bb33
diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx
index 1df4a4a4004..6580a3a8a74 100644
--- a/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx
@@ -658,6 +658,8 @@ describe('ClarifyTool batch card', () => {
expect(screen.getByText('0 of 2 answered')).toBeTruthy()
})
+ // #112855: the batch card spun forever while the gateway clarify request
+ // raced (or never came). The question text is already in the tool args.
it('paints batch questions from tool args while the gateway request is still racing', () => {
$activeSessionId.set('session-1')
$gateway.set({ request: vi.fn() } as never)
@@ -665,15 +667,18 @@ describe('ClarifyTool batch card', () => {
expect(screen.getByText('Color?')).toBeTruthy()
expect(screen.getByText('Name?')).toBeTruthy()
- expect(screen.getByText('red')).toBeTruthy()
expect(screen.queryByRole('status', { name: /loading question/i })).toBeNull()
expect(document.querySelector('[data-clarify-batch-preview]')).toBeTruthy()
- expect(screen.getByRole('button', { name: /Confirm and continue/ }).hasAttribute('disabled')).toBe(true)
+ // Nothing is answerable yet: no qids to respond with.
+ expect((screen.getByRole('button', { name: /red/ }) as HTMLButtonElement).disabled).toBe(true)
+ expect((screen.getByRole('button', { name: /Skip/ }) as HTMLButtonElement).disabled).toBe(true)
+ expect((screen.getByRole('button', { name: /Confirm and continue/ }) as HTMLButtonElement).disabled).toBe(true)
})
- it('becomes live once the gateway request lands over the preview', () => {
+ it('swaps the preview for the live form and answers with the request qids', async () => {
+ const request = vi.fn().mockResolvedValue({ ok: true, remaining: [] })
$activeSessionId.set('session-1')
- $gateway.set({ request: vi.fn().mockResolvedValue({ ok: true, remaining: [] }) } as never)
+ $gateway.set({ request } as never)
const { rerender } = renderClarify(<ClarifyTool {...liveBatchProps()} />)
expect(document.querySelector('[data-clarify-batch-preview]')).toBeTruthy()
@@ -696,6 +701,15 @@ describe('ClarifyTool batch card', () => {
expect(document.querySelector('[data-clarify-batch-preview]')).toBeNull()
expect(screen.getByText('0 of 2 answered')).toBeTruthy()
+
+ fireEvent.click(screen.getByRole('button', { name: /red/ }))
+ fireEvent.change(screen.getByPlaceholderText('Type your answer…'), { target: { value: 'packet' } })
+ fireEvent.submit(document.querySelector('form') as HTMLFormElement)
+
+ await waitFor(() => expect(request).toHaveBeenCalledTimes(2))
+ // Locks ride the live qids, never the preview's synthetic ones.
+ expect(request).toHaveBeenNthCalledWith(1, 'clarify.lock', { answer: 'red', question_id: 'q0', request_id: 'request-batch' })
+ expect(request).toHaveBeenNthCalledWith(2, 'clarify.lock', { answer: 'packet', question_id: 'q1', request_id: 'request-batch' })
})
it('stages locally and keeps the single confirm disabled until all answered', async () => {
diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
index 74533ac4d6a..59d631eff88 100644
--- a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
@@ -955,13 +955,15 @@ function ClarifyToolBatchPending({
// qids only exist on the gateway request — args are a hydration-race
// fallback for display, never answerable (no ids to respond with).
- const questions = request?.questions ?? []
- const ready = Boolean(request?.requestId) && questions.length > 0
+ const liveQuestions = request?.questions ?? []
+ const ready = Boolean(request?.requestId) && liveQuestions.length > 0
// Preview items from the tool args: same question text/choices, synthetic
// qids, shown disabled until the live request lands (or indefinitely when
// the caller has no gateway request at all — e.g. an external tool call —
- // so the user sees the question instead of an endless spinner).
+ // so the user sees the question instead of an endless spinner). ONE form
+ // renders both states: every control is disabled while !ready, so nothing
+ // is ever staged under a synthetic qid and the swap to live qids is clean.
const previewQuestions: ClarifyQuestion[] = useMemo(
() =>
(fromArgs?.questions ?? []).map((entry, index) => ({
@@ -973,6 +975,8 @@ function ClarifyToolBatchPending({
[fromArgs]
)
+ const questions = ready ? liveQuestions : previewQuestions
+
const [staged, setStaged] = useState<Record<string, { choices: string[]; draft: string }>>({})
const [submitting, setSubmitting] = useState(false)
@@ -1117,58 +1121,16 @@ function ClarifyToolBatchPending({
(event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
- if (allStaged) {
+ if (ready && allStaged) {
void confirmAll()
}
},
- [allStaged, confirmAll]
+ [allStaged, confirmAll, ready]
)
- if (!ready) {
- if (previewQuestions.length > 0) {
- return (
- <form
- aria-disabled="true"
- className="my-1.5 grid gap-4"
- data-clarify-batch={previewQuestions.length}
- data-clarify-batch-preview=""
- onSubmit={event => event.preventDefault()}
- >
- <ClarifyShell className="grid gap-3">
- <div className="flex items-start gap-2">
- <span className="flex-1 text-[0.6875rem] leading-4 text-(--ui-text-tertiary)">
- {copy.questionProgress(0, previewQuestions.length)}
- </span>
- <MessageQuestion aria-hidden className={CLARIFY_ICON_CLASS} />
- </div>
- {previewQuestions.map(question => (
- <BatchQuestionBlock
- disabled
- key={question.qid}
- locked={false}
- onDraft={() => {}}
- onToggle={() => {}}
- question={question}
- staged={emptyStage}
- />
- ))}
- </ClarifyShell>
-
- <div className="flex items-center justify-end gap-1">
- <Button disabled size="xs" type="button" variant="text">
- {copy.skip}
- </Button>
- <Button disabled size="xs" type="submit">
- {copy.confirmAndContinueLabel}
- <span aria-hidden className="ml-0.5 text-[0.625rem] opacity-70">
- ⏎
- </span>
- </Button>
- </div>
- </form>
- )
- }
+ const disabled = submitting || !ready
+ if (questions.length === 0) {
return (
<ClarifyShell aria-label={copy.loadingQuestion} className="my-1.5 grid min-h-12 place-items-center" role="status">
<Loader2 aria-hidden className="size-4 animate-spin text-(--ui-text-tertiary)" />
@@ -1178,8 +1140,10 @@ function ClarifyToolBatchPending({
return (
<form
+ aria-disabled={ready ? undefined : 'true'}
className="my-1.5 grid gap-4"
data-clarify-batch={questions.length}
+ data-clarify-batch-preview={ready ? undefined : ''}
onKeyDownCapture={handleClarifySubmitShortcut}
onSubmit={handleSubmit}
>
@@ -1192,7 +1156,7 @@ function ClarifyToolBatchPending({
</div>
{questions.map(question => (
<BatchQuestionBlock
- disabled={submitting}
+ disabled={disabled}
key={question.qid}
locked={false}
onDraft={value => draftFor(question, value)}
@@ -1204,10 +1168,10 @@ function ClarifyToolBatchPending({
</ClarifyShell>
<div className="flex items-center justify-end gap-1">
- <Button disabled={submitting} onClick={() => void cancelAll()} size="xs" type="button" variant="text">
+ <Button disabled={disabled} onClick={() => void cancelAll()} size="xs" type="button" variant="text">
{copy.skip}
</Button>
- <Button disabled={submitting || !allStaged} size="xs" type="submit">
+ <Button disabled={disabled || !allStaged} size="xs" type="submit">
{submitting ? (
<Loader2 className="size-3 animate-spin" />
) : (
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..e1fb605fb01
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+funkyotc