The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): typing over an ordinary clarify card skips it and sends the message again
alt-glitchffc251c0cc67
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 9484f3f2bd6..7d9a84c86eb 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@@ -585,7 +585,7 @@ describe('useComposerSubmit with a clarify parked on the session', () => {expect(hasOpenServerRequest('req-runtime-session')).toBe(false)})- it('answers the question with the typed message on an idle session', async () => {+ it('skips the question and still sends the typed message on an idle session', async () => {parkClarify('runtime-session')const { hook, onSubmit } = renderSubmitHook({ text: 'actually do this instead' })@@ -593,13 +593,15 @@ describe('useComposerSubmit with a clarify parked on the session', () => {hook.result.current.submitDraft()})- await waitFor(() => expect(respond).toHaveBeenCalledWith({ answers: { q0: 'actually do this instead' } }))- expect(onSubmit).not.toHaveBeenCalled()+ await waitFor(() => expect(respond).toHaveBeenCalledWith({}))+ await waitFor(() =>+ expect(onSubmit).toHaveBeenCalledWith('actually do this instead', expect.objectContaining({ attachments: [] }))+ )expect($clarifyRequests.get()['runtime-session']).toBeUndefined()expect(hasOpenServerRequest('req-runtime-session')).toBe(false)})- it('answers the question instead of steering a busy turn', async () => {+ it('skips the question before steering a busy turn', async () => {parkClarify('runtime-session')const { hook, onSteer } = renderSubmitHook({ busy: true, text: 'change course' })@@ -607,8 +609,8 @@ describe('useComposerSubmit with a clarify parked on the session', () => {hook.result.current.submitDraft()})- await waitFor(() => expect(respond).toHaveBeenCalledWith({ answers: { q0: 'change course' } }))- expect(onSteer).not.toHaveBeenCalled()+ await waitFor(() => expect(onSteer).toHaveBeenCalledWith('change course'))+ expect(respond).toHaveBeenCalledWith({})})it('leaves the question alone for an empty Enter (Stop, not an answer)', () => {diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.tsindex a15c82f93f7..ad1714f5853 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts@@ -6,7 +6,7 @@ import { translateNow, useI18n } from '@/i18n'import { isSlashCommandText } from '@/lib/chat-runtime'import { isSideTaskSlashCommand } from '@/lib/desktop-slash-commands'import { triggerHaptic } from '@/lib/haptics'-import { answerClarifyRequest, hasClarifyRequest, skipClarifyRequest } from '@/store/clarify'+import { answerSetupCard, hasClarifyRequest, skipClarifyRequest } from '@/store/clarify'import {clearSessionDraft,type ComposerAttachment,@@ -270,21 +270,22 @@ export function useComposerSubmit({return true}- // True when the draft was consumed as a parked clarify card's answer.+ // True when the draft was consumed as a parked setup card's answer.const answerParkedCard = (text: string, payloadPresent: boolean) => {- // A clarify or setup card parked on this session owns the turn: the agent- // is blocked inside its tool batch waiting on the card's answer, so a- // follow-up routed through steer/queue sits undelivered until the card's- // own timeout (default 5 min) — the message looks sent and nothing- // happens. Typed words instead of a pick ARE the answer: they go back as- // the card's answer, the card settles showing them, and the turn carries- // on with no interrupt.+ // A clarify card parked on this session owns the turn: the agent is blocked+ // inside its tool batch waiting on `clarify.respond`, so a follow-up routed+ // through steer/queue sits undelivered until the clarify's own timeout+ // (default 5 min) — the message looks sent and nothing happens. Typing a+ // real message instead of picking an option IS the answer "none of these":+ // skip the question so the tool returns, then route the words normally.+ // A setup card is the exception: the setup turn reads typed words as its+ // answer, so they go back as the card's answer and the turn carries on.//- // A slash command or attachments cannot be an answer: those skip the card- // so the tool returns, then route normally. The skip is fire-and-forget:- // it clears the card synchronously and both RPCs ride the same socket in- // call order, so the gateway resolves the card before it sees the- // follow-up.+ // A slash command or attachments cannot be a setup answer either. The skip+ // is fire-and-forget, not awaited: it clears the card synchronously and+ // both RPCs ride the same socket in call order, so the gateway resolves the+ // clarify before it sees the follow-up. Awaiting first would leave the draft+ // live for a tick — long enough for a second Enter to send it twice.//// /btw and /bg run beside the turn (snapshot / separate session) and answer// neither parked card. With attachments the draft isn't routed as a slash@@ -296,7 +297,7 @@ export function useComposerSubmit({cardParked &&!attachments.length &&!SLASH_COMMAND_RE.test(text.trim()) &&- answerClarifyRequest(sessionId, text.trim())+ answerSetupCard(sessionId, text.trim())) {triggerHaptic('submit')resetBrowseState(sessionId)diff --git a/apps/desktop/src/store/clarify.ts b/apps/desktop/src/store/clarify.tsindex 497cd884489..273b2303372 100644--- a/apps/desktop/src/store/clarify.ts+++ b/apps/desktop/src/store/clarify.ts@@ -355,42 +355,15 @@ export async function skipClarifyRequest(sessionId: string | null | undefined):}/**- * Answer the card parked on `sessionId` with text the user typed in the- * composer. A card blocks the agent inside its tool batch, so the typed words- * ARE the answer: the tool returns them and the turn carries on, with no- * interrupt. A batch takes the text as its first open question's answer. False when- * no card is parked or its request is gone; the caller then sends the words as- * an ordinary message.+ * Answer the setup card parked on `sessionId` with text the user typed in the+ * composer: the setup turn reads typed words as the card's answer. False when+ * no setup card is parked (an ordinary clarify card included) or its request is+ * gone; the caller then skips any card and sends the words as a message.*/-export function answerClarifyRequest(sessionId: string | null | undefined, text: string): boolean {+export function answerSetupCard(sessionId: string | null | undefined, text: string): boolean {const request = $clarifyRequests.get()[keyFor(sessionId)]- if (!request) {- return false- }-- if (request.setup) {- return answerSetupChoose(request, request.setup, text)- }-- // A reconnect replay can arrive with answers already locked server-side;- // the backend merges this response over them, so the typed text goes to- // the first question still open and the locks stand.- const locked = request.lockedAnswers ?? {}- const target = request.questions.find(question => !(question.qid in locked)) ?? request.questions[0]- const answers = { [target.qid]: target.multiSelect ? JSON.stringify([text]) : text }-- if (!respondToServerRequest(request.requestId, { answers })) {- return false- }-- clearClarifyRequest(request.requestId, request.sessionId)- settleClarify(request, {- outcome: 'submitted',- responses: request.questions.map(question => settledResponse(question, { ...locked, ...answers }))- })-- return true+ return request?.setup ? answerSetupChoose(request, request.setup, text) : false}/** The row typed text names, by id or label (any case). */@@ -440,32 +413,3 @@ function answerSetupChoose(request: ClarifyRequest, setup: SetupChooseSpec, textreturn true}--/** One row of a clarify result, shaped like `tools/clarify_tool.py::_result`. */-function settledResponse(question: ClarifyQuestion, answers: Record<string, null | string>) {- const raw = answers[question.qid]-- if (!raw) {- return {- question: question.question,- status: question.qid in answers ? 'skipped' : 'unanswered',- user_response: null- }- }-- let answer: string | string[] = raw-- if (question.multiSelect) {- try {- const parsed: unknown = JSON.parse(raw)-- if (Array.isArray(parsed)) {- answer = parsed.map(String)- }- } catch {- // A non-JSON multi-select answer stays one value.- }- }-- return { question: question.question, status: 'answered', user_response: answer }-}