The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): repaint a tool row when a re-arm changes its args or binding
Austin Pickette15f9b92397e
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex 87288fd254f..505ffe21267 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -279,13 +279,19 @@ export function chatPartsEquivalent(aPart: ChatMessage['parts'][number], bPart:}if (aPart.type === 'tool-call') {- const aCall = aPart as { toolCallId?: string; toolName?: string; result?: unknown }- const bCall = bPart as { toolCallId?: string; toolName?: string; result?: unknown }+ const aCall = aPart as { argsText?: string; toolCallId?: string; toolName?: string; result?: unknown }+ const bCall = bPart as { argsText?: string; toolCallId?: string; toolName?: string; result?: unknown }if (aCall.toolCallId !== bCall.toolCallId || aCall.toolName !== bCall.toolName) {return false}+ // A clarify re-arm changes only the row's args and its request binding;+ // a view that kept the old ones would never show the next card.+ if (aCall.argsText !== bCall.argsText || aPart.clarifyRequestId !== bPart.clarifyRequestId) {+ return false+ }+// Compare whether result is present (undefined on both or defined on both)const aHasResult = aCall.result !== undefinedconst bHasResult = bCall.result !== undefined@@ -2413,8 +2419,11 @@ function publishRuntimeToComposer(state: SessionRuntimeStatePatch): void {/** Session-independent side effects of one runtime info snapshot. */function reportRuntimeInfoAppState(info: SessionRuntimeInfo, owner: SessionOwnerScope): void {if (info.stored_session_id) {- reconcilePendingSubmissions(info.stored_session_id, info.pending_submissions,- pendingSnapshotFence(info.replay_epoch, info.last_sequence))+ reconcilePendingSubmissions(+ info.stored_session_id,+ info.pending_submissions,+ pendingSnapshotFence(info.replay_epoch, info.last_sequence)+ )}// App/profile-level reporting is session-independent — a tile's runtimediff --git a/apps/desktop/src/components/assistant-ui/clarify/clarify-one-card-per-question.test.tsx b/apps/desktop/src/components/assistant-ui/clarify/clarify-one-card-per-question.test.tsxindex b630076dc32..e5b3893de3b 100644--- a/apps/desktop/src/components/assistant-ui/clarify/clarify-one-card-per-question.test.tsx+++ b/apps/desktop/src/components/assistant-ui/clarify/clarify-one-card-per-question.test.tsx@@ -4,6 +4,7 @@ import type { ReactNode } from 'react'import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'import { pendingClarifyToolPayload } from '@/app/session/hooks/use-session-actions/restore-pending-clarify'+import { chatMessageArraysEquivalent } from '@/app/session/hooks/use-session-actions/utils'import { I18nProvider } from '@/i18n'import { type ChatMessage, restorePendingClarifyToolCall } from '@/lib/chat-messages'import { $settledClarifyResults, type ClarifyRequest, clearClarifyRequest, setClarifyRequest } from '@/store/clarify'@@ -94,24 +95,47 @@ const liveCards = (container: HTMLElement) =>choices.querySelector('button:not([disabled])')).length-/** Assistant messages (one per argument) whose clarify rows re-arm the way `parkClarify` does. */+/**+ * Assistant messages (one per argument) whose clarify rows re-arm the way `parkClarify` does. Rows+ * render from what the view last published: like `use-session-state-cache`, it takes a new+ * transcript only when `chatMessageArraysEquivalent` sees a change.+ */function transcript(...rows: ReturnType<typeof clarifyCall>[][]) {+ return transcriptOf(rows, { pending: true })+}++/** A transcript hydrated from REST: its messages are settled until the first re-arm. */+function resumedTranscript(...rows: ReturnType<typeof clarifyCall>[][]) {+ return transcriptOf(rows, { pending: false })+}++function transcriptOf(rows: ReturnType<typeof clarifyCall>[][], { pending }: { pending: boolean }) {const request = vi.fn().mockResolvedValue({ ok: true })let messages: ChatMessage[] = rows.map((parts, index) => ({id: `m${index + 1}`,parts,- pending: true,+ pending,role: 'assistant'}))+ let shown = messages++ const publish = (next: ChatMessage[]) => {+ messages = next++ if (!chatMessageArraysEquivalent(next, shown)) {+ shown = next+ }+ }+$activeSessionId.set('session-1')$gateway.set({ request } as never)return {add(call: ReturnType<typeof clarifyCall>) {const tail = messages.at(-1)!- messages = [...messages.slice(0, -1), { ...tail, parts: [...tail.parts, call] }]+ publish([...messages.slice(0, -1), { ...tail, parts: [...tail.parts, call] }])},locks: () =>[...request.mock.calls, ...gatewayMocks.requestGatewayForAgent.mock.calls].filter(call =>@@ -122,14 +146,14 @@ function transcript(...rows: ReturnType<typeof clarifyCall>[][]) {rememberServerRequest({ fail: vi.fn(), id: next.requestId, method: 'clarify', params: {}, respond: vi.fn() })setClarifyRequest(next)const before = clarifyParts(messages).length- messages = restorePendingClarifyToolCall(messages, pendingClarifyToolPayload(next)).messages+ publish(restorePendingClarifyToolCall(messages, pendingClarifyToolPayload(next)).messages)expect(clarifyParts(messages)).toHaveLength(before + (appends ? 1 : 0))},- props: (toolCallId: string) => rowProps(clarifyParts(messages).find(part => part.toolCallId === toolCallId)!),- /** Every clarify row, in transcript order. */+ props: (toolCallId: string) => rowProps(clarifyParts(shown).find(part => part.toolCallId === toolCallId)!),+ /** Every clarify row the view shows, in transcript order. */rows: () => (<>- {clarifyParts(messages).map((part, index) => (+ {clarifyParts(shown).map((part, index) => (<ClarifyTool key={index} {...rowProps(part)} />))}</>@@ -264,4 +288,38 @@ describe('a clarify asked one card per question', () => {expect(liveCards(view.container)).toBe(1)})++ // A resumed or switched-to session publishes the row with its first card's binding. The next card's+ // re-arm changes only the row's args and binding, and the view has to take that change.+ it('shows the next card after a resume when its own Confirm answered the first', async () => {+ const chat = resumedTranscript([clarifyCall('call-1', [TARGET, REGION])])+ chat.park(card('prompt-1', TARGET))+ const view = render(tree(chat.rows()))++ fireEvent.click(screen.getByRole('button', { name: /staging/ }))+ fireEvent.click(screen.getByRole('button', { name: /Confirm and continue/ }))+ await waitFor(() => expect(chat.locks()).toHaveLength(1))++ act(() => chat.park(card('prompt-2', REGION)))+ view.rerender(tree(chat.rows()))++ expect(liveCards(view.container)).toBe(1)+ expect(screen.getByText('Which region?')).toBeTruthy()+ })++ it('shows the next card after a resume when the chat bar answered the first', () => {+ const chat = resumedTranscript([clarifyCall('call-1', [TARGET, REGION])])+ chat.park(card('prompt-1', TARGET))+ const view = render(tree(chat.rows()))++ act(() => {+ expect(answerParkedCard('session-1', 'staging')).toBe(true)+ })++ act(() => chat.park(card('prompt-2', REGION)))+ view.rerender(tree(chat.rows()))++ expect(liveCards(view.container)).toBe(1)+ expect(screen.getByText('Which region?')).toBeTruthy()+ })})