Skip to content

The agent that grows with you

fix(desktop): paint batch clarify questions from tool args while request races

funky05f928bc5145
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 1e2c0473271..1df4a4a4004 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,46 @@ describe('ClarifyTool batch card', () => {
expect(screen.getByText('0 of 2 answered')).toBeTruthy()
})
+ 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)
+ renderClarify(<ClarifyTool {...liveBatchProps()} />)
+
+ 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)
+ })
+
+ it('becomes live once the gateway request lands over the preview', () => {
+ $activeSessionId.set('session-1')
+ $gateway.set({ request: vi.fn().mockResolvedValue({ ok: true, remaining: [] }) } as never)
+ const { rerender } = renderClarify(<ClarifyTool {...liveBatchProps()} />)
+
+ expect(document.querySelector('[data-clarify-batch-preview]')).toBeTruthy()
+
+ act(() => {
+ liveServerRequest('request-batch')
+ setClarifyRequest({
+ choices: null,
+ multiSelect: false,
+ question: '',
+ questions: [
+ { choices: ['red', 'blue'], multiSelect: false, qid: 'q0', question: 'Color?' },
+ { choices: null, multiSelect: false, qid: 'q1', question: 'Name?' }
+ ],
+ requestId: 'request-batch',
+ sessionId: 'session-1'
+ })
+ })
+ rerender(clarifyTree(<ClarifyTool {...liveBatchProps()} />))
+
+ expect(document.querySelector('[data-clarify-batch-preview]')).toBeNull()
+ expect(screen.getByText('0 of 2 answered')).toBeTruthy()
+ })
+
it('stages locally and keeps the single confirm disabled until all answered', async () => {
const { request } = renderLiveBatch()
const confirm = screen.getByRole('button', { name: /Confirm and continue/ })
diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
index 349a3dd1df8..74533ac4d6a 100644
--- a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
@@ -394,9 +394,12 @@ function ClarifyToolPending(props: ToolCallMessagePartProps) {
}
// Batch: the gateway request carries qid-keyed questions. Args alone can't
- // drive the form (no qids to respond with), so batch waits for the request.
+ // drive the form (no qids to respond with), so the live form waits for the
+ // request — but the question TEXT is already in the tool args, so paint a
+ // disabled preview immediately instead of a spinner (the single-question
+ // card does the same while request_id races the tool block).
if (request?.questions?.length || fromArgs.questions) {
- return <ClarifyToolBatchPending onAnswered={() => setAnswered(true)} request={request} />
+ return <ClarifyToolBatchPending fromArgs={fromArgs} onAnswered={() => setAnswered(true)} request={request} />
}
return <ClarifyToolSinglePending fromArgs={fromArgs} onAnswered={() => setAnswered(true)} request={request} />
@@ -937,7 +940,15 @@ const emptyStage = { choices: [] as string[], draft: '' }
* back-to-back and completes the batch. Staged answers stay editable up to
* that moment. The per-question wire protocol is unchanged (the TUI/CLI
* still lock incrementally); this card just batches its locks at the end. */
-function ClarifyToolBatchPending({ onAnswered, request }: { onAnswered: () => void; request: ClarifyRequest | null }) {
+function ClarifyToolBatchPending({
+ fromArgs,
+ onAnswered,
+ request
+}: {
+ fromArgs?: ClarifyArgs
+ onAnswered: () => void
+ request: ClarifyRequest | null
+}) {
const { t } = useI18n()
const copy = t.assistant.clarify
const gateway = useStore($gateway)
@@ -947,6 +958,21 @@ function ClarifyToolBatchPending({ onAnswered, request }: { onAnswered: () => vo
const questions = request?.questions ?? []
const ready = Boolean(request?.requestId) && questions.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).
+ const previewQuestions: ClarifyQuestion[] = useMemo(
+ () =>
+ (fromArgs?.questions ?? []).map((entry, index) => ({
+ choices: entry.choices ?? null,
+ multiSelect: entry.multiSelect ?? false,
+ qid: `args-${index}`,
+ question: entry.question
+ })),
+ [fromArgs]
+ )
+
const [staged, setStaged] = useState<Record<string, { choices: string[]; draft: string }>>({})
const [submitting, setSubmitting] = useState(false)
@@ -1099,6 +1125,50 @@ function ClarifyToolBatchPending({ onAnswered, request }: { onAnswered: () => vo
)
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>
+ )
+ }
+
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)" />