The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a stopped clarify no longer swallows the next turn's question
teknium185b93771d220
diff --git a/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx b/apps/desktop/src/components/assistant-ui/thread/message-parts.tsxindex 03fc1e5d370..0cb367cb330 100644--- a/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/message-parts.tsx@@ -105,6 +105,13 @@ const ChainToolFallback: FC<TimelineToolCallProps> = props => {}if (props.toolName === 'clarify') {+ // Stopped on this question, never answered: history. ClarifyTool reads+ // the session's live clarify request, so a later turn's question would+ // otherwise paint onto this row as a second live card.+ if (settledWithoutResult(props)) {+ return <ToolFallback {...props} />+ }+return (<><TimelineTimestamp className="mb-0.5 block" completedAt={props.completedAt} timestamp={props.timestamp} />diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.tsindex f5866561804..22fcebd25a8 100644--- a/apps/desktop/src/lib/chat-messages.test.ts+++ b/apps/desktop/src/lib/chat-messages.test.ts@@ -14,6 +14,7 @@ import {preserveLocalAssistantErrors,reasoningPart,renderMediaTags,+ restorePendingClarifyToolCall,sealOpenToolParts,stripPendingClarifyProjectionForCache,toChatMessages,@@ -1412,6 +1413,67 @@ describe('sealOpenToolParts', () => {...over}) as ChatMessage+ it('a sealed clarify never becomes the fallback row for a new, uncorrelated clarify request', () => {+ // Turn 1 blocked on a clarify, the user stopped it; settle sealed the call+ // (no result). A later turn raises a *different* clarify whose request id+ // and question match nothing on the transcript.+ const stopped = sealOpenToolParts([+ assistantWithParts(+ upsertToolPart(+ [],+ { tool_id: 'old-provider-id', name: 'clarify', args: { question: 'Old question?', choices: ['A', 'B'] } },+ 'running',+ 1+ ),+ { id: 'old-turn', pending: false }+ )+ ])++ const messages = [...stopped, { id: 'u2', role: 'user', parts: [{ type: 'text', text: 'ask something else' }] } as ChatMessage]++ const restored = restorePendingClarifyToolCall(+ messages,+ { id: 'new-request-id', name: 'clarify', args: { question: 'New question?', choices: ['C', 'D'] } },+ 3+ )++ expect(restored.streamId).not.toBe('old-turn')+ const oldTurn = restored.messages.find(message => message.id === 'old-turn')+ expect(oldTurn?.pending).not.toBe(true)++ const newQuestion = restored.messages+ .flatMap(message => message.parts)+ .find(part => part.type === 'tool-call' && part.toolCallId === 'new-request-id')++ expect(newQuestion).toBeDefined()+ })++ it('a sealed clarify is still re-armed when the resume request genuinely correlates to it', () => {+ const stopped = sealOpenToolParts([+ assistantWithParts(+ upsertToolPart(+ [],+ { tool_id: 'provider-id', name: 'clarify', args: { question: 'Same question?', choices: ['A', 'B'] } },+ 'running',+ 1+ ),+ { id: 'turn', pending: false }+ )+ ])++ const restored = restorePendingClarifyToolCall(+ stopped,+ { id: 'request-id', name: 'clarify', args: { question: 'Same question?', choices: ['A', 'B'] } },+ 2+ )++ expect(restored.streamId).toBe('turn')+ expect(restored.messages[0].pending).toBe(true)+ expect(restored.messages).toHaveLength(1)+ // The seal comes off so the row renders as the live question again.+ expect(restored.messages[0].parts[0].completedAt).toBeUndefined()+ })+it('seals open tool-call parts in settled assistant messages', () => {const messages = [assistantWithParts([toolPart()])]diff --git a/apps/desktop/src/lib/chat-messages/tool-parts.ts b/apps/desktop/src/lib/chat-messages/tool-parts.tsindex 228f96ef98e..f817cb9bd71 100644--- a/apps/desktop/src/lib/chat-messages/tool-parts.ts+++ b/apps/desktop/src/lib/chat-messages/tool-parts.ts@@ -398,15 +398,23 @@ function findPendingClarifyLocation(continue}- pendingCount += 1- solePending = { messageIndex, partIndex }-const exactId = Boolean(stableId && part.toolCallId === stableId)const contextual = hasToolMatchOverlap(matchValues, toolPartMatchValues(part))if (exactId || contextual) {return { messageIndex, partIndex }}++ // A sealed call (settle-time `completedAt`, no result) is a clarify the+ // turn stopped on without an answer. It is history, not the session's+ // open question, so it may only be re-armed by a genuine correlation+ // above, never adopted as the fallback for an uncorrelated request.+ if (part.completedAt !== undefined) {+ continue+ }++ pendingCount += 1+ solePending = { messageIndex, partIndex }}}@@ -536,13 +544,25 @@ export function restorePendingClarifyToolCall(if (location) {const message = messages[location.messageIndex]+ const part = message.parts[location.partIndex]+ // A correlated row that settle sealed (stop, lost completion) is live+ // again: drop the seal so the card renders as pending, not as history.+ const sealed = part.type === 'tool-call' && part.completedAt !== undefined && part.result === undefined- if (message.pending) {+ if (message.pending && !sealed) {return { messages, streamId: message.id }}const next = [...messages]- next[location.messageIndex] = { ...message, pending: true }++ if (sealed) {+ const { completedAt: _completedAt, ...unsealed } = part+ const parts = [...message.parts]+ parts[location.partIndex] = unsealed as ChatMessagePart+ next[location.messageIndex] = { ...message, parts, pending: true }+ } else {+ next[location.messageIndex] = { ...message, pending: true }+ }return { messages: next, streamId: message.id }}