Skip to content

The agent that grows with you

fix(desktop): demote unanswered clarify cards on Stop

Brooklyn Nicholsone4dac8415f44
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 b315f4d6165..638a7b7913e 100644
--- a/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx
@@ -28,14 +28,18 @@ afterEach(() => {
vi.clearAllMocks()
})
-function renderClarify(ui: ReactNode) {
- return render(
+function clarifyTree(ui: ReactNode) {
+ return (
<I18nProvider configClient={null} initialLocale="en">
{ui}
</I18nProvider>
)
}
+function renderClarify(ui: ReactNode) {
+ return render(clarifyTree(ui))
+}
+
function settledClarifyProps(
args: ToolCallMessagePartProps['args'],
result: ToolCallMessagePartProps['result'],
@@ -86,9 +90,9 @@ function renderLiveClarify({ multiSelect = false }: { multiSelect?: boolean } =
requestId: 'request-1',
sessionId: 'session-1'
})
- renderClarify(<ClarifyTool {...liveClarifyProps()} />)
+ const { rerender } = renderClarify(<ClarifyTool {...liveClarifyProps()} />)
- return request
+ return { request, rerender }
}
describe('ClarifyTool live card stays mounted across settle', () => {
@@ -111,17 +115,34 @@ describe('ClarifyTool live card stays mounted across settle', () => {
expect(screen.queryByRole('button', { name: /Continue/ })).toBeNull()
})
- it('holds the card through the gap between answering and the settled result', () => {
+ it('holds the card through the gap between answering and the settled result', async () => {
+ const { request, rerender } = renderLiveClarify()
+
+ fireEvent.click(screen.getByRole('button', { name: /staging/ }))
+ fireEvent.click(screen.getByRole('button', { name: /Continue/ }))
+
+ await waitFor(() => {
+ expect(request).toHaveBeenCalled()
+ })
+
+ // tool.complete is what swaps in the settled card; the turn can already
+ // read as not-running in that gap.
+ messageRunning = false
+ rerender(clarifyTree(<ClarifyTool {...liveClarifyProps()} />))
+
+ expect(document.querySelector('[data-clarify-choices]')).toBeTruthy()
+ })
+
+ it('demotes when the turn is stopped after the card was live but never answered', () => {
renderLiveClarify()
expect(document.querySelector('[data-clarify-choices]')).toBeTruthy()
- // Answering clears the request; the settled card only arrives with
- // tool.complete, and the turn can already read as not-running by then.
messageRunning = false
act(() => clearClarifyRequest('request-1', 'session-1'))
- expect(document.querySelector('[data-clarify-choices]')).toBeTruthy()
+ expect(document.querySelector('[data-clarify-choices]')).toBeNull()
+ expect(screen.queryByRole('button', { name: /Continue/ })).toBeNull()
})
it('paints the question from tool args instead of a spinner while request_id is still racing', () => {
@@ -137,7 +158,7 @@ describe('ClarifyTool live card stays mounted across settle', () => {
describe('ClarifyTool choice selection', () => {
it('selects independently, deselects and submits multi-select choices as a JSON array', async () => {
- const request = renderLiveClarify({ multiSelect: true })
+ const { request } = renderLiveClarify({ multiSelect: true })
const staging = screen.getByRole('button', { name: /staging/ })
const production = screen.getByRole('button', { name: /production/ })
@@ -165,7 +186,7 @@ describe('ClarifyTool choice selection', () => {
})
it('keeps single-select replacement and plain-string submission', async () => {
- const request = renderLiveClarify()
+ const { request } = renderLiveClarify()
const staging = screen.getByRole('button', { name: /staging/ })
const production = screen.getByRole('button', { name: /production/ })
@@ -357,7 +378,7 @@ describe('ClarifyTool keyboard navigation', () => {
})
it('selects by number and confirms the answer with Enter', async () => {
- const request = renderLiveClarify()
+ const { request } = renderLiveClarify()
fireEvent.keyDown(window, { key: '2' })
fireEvent.keyDown(window, { key: 'Enter' })
@@ -371,7 +392,7 @@ describe('ClarifyTool keyboard navigation', () => {
})
it('stages a highlighted multi-select choice with Enter and submits it with Continue', async () => {
- const request = renderLiveClarify({ multiSelect: true })
+ const { request } = renderLiveClarify({ multiSelect: true })
const production = screen.getByRole('button', { name: /production/ })
fireEvent.keyDown(window, { key: 'ArrowDown' })
@@ -405,7 +426,7 @@ describe('ClarifyTool keyboard navigation', () => {
})
it('does not intercept keyboard events while an action button has focus', () => {
- const request = renderLiveClarify()
+ const { request } = renderLiveClarify()
const skip = screen.getByRole('button', { name: 'Skip' })
skip.focus()
diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
index 2cd8f6c402e..295abce16b8 100644
--- a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx
@@ -375,34 +375,36 @@ function ClarifyToolPending(props: ToolCallMessagePartProps) {
const fromArgs = useMemo(() => readClarifyArgs(props.args), [props.args])
const messageRunning = useAuiState(selectMessageRunning)
// Answering clears the request a beat before `tool.complete` swaps in the
- // settled card. Latch that this card was live so that gap doesn't demote it.
- const [wasLive, setWasLive] = useState(false)
-
- if (request && !wasLive) {
- setWasLive(true)
- }
+ // settled card. Latch submit so that gap doesn't demote; Stop also clears
+ // the request and must still collapse an unanswered card.
+ const [answered, setAnswered] = useState(false)
// Stopped mid-prompt with no result — don't leave a dead interactive panel.
- // The turn's running flag alone can't decide that: `session.info` reports
- // running=false while clarify is blocking on the user, and demoting there
- // remounts the question as a tool row and jumps the transcript. The live
- // request is the real signal — every path that ends a turn (complete, stop,
- // error) clears it for the session, so a request that never arrived on a
- // settled turn means there is nothing left to answer.
- if (!messageRunning && !request && !wasLive) {
+ // `session.info` reports running=false while clarify is blocking, so the
+ // running flag alone would remount the question as a tool row. Keep the
+ // card while a request is open or this instance already submitted.
+ if (!messageRunning && !request && !answered) {
return <ToolFallback {...props} />
}
// 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.
if (request?.questions?.length || fromArgs.questions) {
- return <ClarifyToolBatchPending request={request} />
+ return <ClarifyToolBatchPending onAnswered={() => setAnswered(true)} request={request} />
}
- return <ClarifyToolSinglePending fromArgs={fromArgs} request={request} />
+ return <ClarifyToolSinglePending fromArgs={fromArgs} onAnswered={() => setAnswered(true)} request={request} />
}
-function ClarifyToolSinglePending({ fromArgs, request }: { fromArgs: ClarifyArgs; request: ClarifyRequest | null }) {
+function ClarifyToolSinglePending({
+ fromArgs,
+ onAnswered,
+ request
+}: {
+ fromArgs: ClarifyArgs
+ onAnswered: () => void
+ request: ClarifyRequest | null
+}) {
const { t } = useI18n()
const copy = t.assistant.clarify
const gateway = useStore($gateway)
@@ -472,6 +474,7 @@ function ClarifyToolSinglePending({ fromArgs, request }: { fromArgs: ClarifyArgs
answer
})
triggerHaptic('submit')
+ onAnswered()
clearClarifyRequest(matchingRequest.requestId, matchingRequest.sessionId)
// tool.complete lands next → ClarifyToolSettled.
} catch (error) {
@@ -479,7 +482,7 @@ function ClarifyToolSinglePending({ fromArgs, request }: { fromArgs: ClarifyArgs
setSubmitting(false)
}
},
- [copy.gatewayDisconnected, copy.notReady, copy.sendFailed, gateway, matchingRequest, ready]
+ [copy.gatewayDisconnected, copy.notReady, copy.sendFailed, gateway, matchingRequest, onAnswered, ready]
)
const trimmedDraft = draft.trim()
@@ -916,7 +919,13 @@ 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({ request }: { request: ClarifyRequest | null }) {
+function ClarifyToolBatchPending({
+ onAnswered,
+ request
+}: {
+ onAnswered: () => void
+ request: ClarifyRequest | null
+}) {
const { t } = useI18n()
const copy = t.assistant.clarify
const gateway = useStore($gateway)
@@ -1003,13 +1012,14 @@ function ClarifyToolBatchPending({ request }: { request: ClarifyRequest | null }
}
triggerHaptic('submit')
+ onAnswered()
// tool.complete lands next → ClarifyToolBatchSettled.
clearClarifyRequest(request.requestId, request.sessionId)
} catch (error) {
notifyError(error, copy.sendFailed)
setSubmitting(false)
}
- }, [copy, gateway, questions, request, stagedAnswer])
+ }, [copy, gateway, onAnswered, questions, request, stagedAnswer])
const toggleChoice = useCallback((question: ClarifyQuestion, choice: string) => {
setStaged(current => {
@@ -1034,6 +1044,7 @@ function ClarifyToolBatchPending({ request }: { request: ClarifyRequest | null }
return
}
+ onAnswered()
clearClarifyRequest(request.requestId, request.sessionId)
try {
@@ -1041,7 +1052,7 @@ function ClarifyToolBatchPending({ request }: { request: ClarifyRequest | null }
} catch {
// The tool times out on its own; a failed skip must never block the UI.
}
- }, [gateway, request])
+ }, [gateway, onAnswered, request])
const handleSubmit = useCallback(
(event: FormEvent<HTMLFormElement>) => {