The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): mark replies the user stopped as "Response stopped"
Adolan159542e251c8
diff --git a/agent/turn_api_call.py b/agent/turn_api_call.pyindex 36d8c977aba..04c0a27d9cc 100644--- a/agent/turn_api_call.py+++ b/agent/turn_api_call.py@@ -204,7 +204,9 @@ def handle_api_interrupt(})final_response = REPETITION_LOOP_INTERRUPTEDelif _partial:- append_message(messages, {"role": "assistant", "content": _partial})+ append_message(messages, {+ "role": "assistant", "content": _partial, "display_metadata": {"interrupted": True},+ })final_response = _partialelse:final_response = f"{INTERRUPT_WAITING_FOR_MODEL_PREFIX}{api_elapsed:.1f}s elapsed)."diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.tsindex 2818421714d..17d7b261e4e 100644--- a/apps/desktop/src/app/chat/session-tile-actions.ts+++ b/apps/desktop/src/app/chat/session-tile-actions.ts@@ -52,7 +52,7 @@ import {applyReloadOptimistic,applyRewindOptimistic,durableRowIdsForRebind,- finalizeUserInterruptedMessages,+ finalizeStoppedMessages,planEdit,planReload,planRestore,@@ -355,7 +355,7 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, storedupdate(state => ({...state,- messages: finalizeUserInterruptedMessages(state.messages, state.streamId),+ messages: finalizeStoppedMessages(state.messages, state.streamId),busy: false,awaitingResponse: false,streamId: null,diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.tsindex 949a27de6d8..03bb7367c23 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts@@ -61,7 +61,7 @@ import {applyReloadOptimistic,applyRewindOptimistic,durableRowIdsForRebind,- finalizeUserInterruptedMessages,+ finalizeStoppedMessages,planEdit,planReload,planRestore,@@ -705,7 +705,7 @@ export function usePromptActions({if (!sessionId) {releaseBusy()- setMessages(finalizeUserInterruptedMessages($messages.get()))+ setMessages(finalizeStoppedMessages($messages.get()))return}@@ -716,7 +716,7 @@ export function usePromptActions({updateSessionState(sessionId, state => {const streamId = state.streamId- const messages = finalizeUserInterruptedMessages(state.messages, streamId)+ const messages = finalizeStoppedMessages(state.messages, streamId)return {...state,diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.tsindex acae282482a..84048033fec 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.test.ts@@ -7,6 +7,7 @@ import {appendMidTurnUserMessage,applyReloadOptimistic,applyRewindOptimistic,+ finalizeStoppedMessages,finalizeUserInterruptedMessages,planEdit,planReload,@@ -342,6 +343,15 @@ describe('finalizeUserInterruptedMessages', () => {expect(message.parts[1].interrupted).toBeUndefined()})+ it('flags the live reply as interrupted on stop, but not on a redirect finalize', () => {+ const [stopped] = finalizeStoppedMessages([toolTurn()], 'assistant-tool', 11.25)+ const [redirected] = finalizeUserInterruptedMessages([toolTurn()], 'assistant-tool', 11.25)++ expect(stopped.interrupted).toBe(true)+ expect(stopped.parts[1].interrupted).toBe(true)+ expect(redirected.interrupted).toBeUndefined()+ })+it('does not mark calls sealed by the non-user settle path', () => {const [message] = finalizeInterruptedMessages([toolTurn()], 'assistant-tool', 11.25)diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.tsindex 82c4ef97879..1457b8283c9 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/rewind.ts@@ -417,6 +417,21 @@ export function finalizeUserInterruptedMessages(return finalizeInterruptedMessages(marked, streamId, occurredAt)}+/** Stop finalize: the live reply is also flagged `interrupted` so it reads as cut short. */+export function finalizeStoppedMessages(+ messages: ChatMessage[],+ streamId?: null | string,+ occurredAt = Date.now() / 1000+): ChatMessage[] {+ const flagged = messages.map(message =>+ message.role === 'assistant' && (message.pending || message.id === streamId)+ ? { ...message, interrupted: true }+ : message+ )++ return finalizeUserInterruptedMessages(flagged, streamId, occurredAt)+}+/*** Arrival-ordered mid-turn user insert (#73793, #83151).*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 a3785ca62b5..640177f7baa 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@@ -228,6 +228,7 @@ const COMPARED_FIELDS = ['hidden','branchGroupId','interim',+ 'interrupted','reactions','timestamp','completedAt',diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsxindex 88c17523a8a..171feee7ba5 100644--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx@@ -215,6 +215,23 @@ describe('AssistantMessage branch button visibility (bug #2 fix)', () => {})})+describe('stopped reply marker', () => {+ it('marks a reply the user stopped', async () => {+ const base = assistantMessage()+ const stopped = { ...base, metadata: { ...base.metadata, custom: { interrupted: true } } } as ThreadMessage+ render(<Harness assistant={stopped} />)++ expect(await screen.findByText(en.assistant.thread.responseStopped)).toBeTruthy()+ })++ it('leaves a finished reply unmarked', async () => {+ render(<Harness />)+ await screen.findByText('done')++ expect(screen.queryByText(en.assistant.thread.responseStopped)).toBeNull()+ })+})+describe('ownership refusal recovery (#106217)', () => {it('offers Start new session and suppresses Retry for live-owner refusals', async () => {render(<Harness assistant={ownershipRefusalMessage()} />)diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsxindex da67b759bdf..cd5f7f4530d 100644--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx@@ -308,6 +308,7 @@ const AssistantMessageBody: FC<AssistantMessageProps & { collapsedNotice?: null>{/* Todos render in the composer status stack now, not inline. */}{MESSAGE_PARTS}+ <StoppedNotice /><AssistantStatusSlot /><AssistantPreviewEmbeds /><MessagePrimitive.Error>@@ -362,6 +363,28 @@ const AssistantMessageBody: FC<AssistantMessageProps & { collapsedNotice?: null)}+const StoppedNotice: FC = () => {+ const { t } = useI18n()++ const stopped = useAuiState(+ s => s.message.status?.type !== 'running' && s.message.metadata?.custom?.interrupted === true+ )++ if (!stopped) {+ return null+ }++ return (+ <div+ className="flex items-center gap-1 px-(--message-text-indent) pt-1 text-[0.72rem] text-(--ui-text-tertiary)"+ data-slot="aui_assistant-message-stopped"+ >+ <Codicon className="size-3" name="debug-stop" />+ {t.assistant.thread.responseStopped}+ </div>+ )+}+/*** PERF leaf: the only subscriber to this message's streaming status inside the* message content. Previously `messageStatus` / `isPlaceholder` /diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.tsindex 696dd1211e5..51f68419094 100644--- a/apps/desktop/src/i18n/de.ts+++ b/apps/desktop/src/i18n/de.ts@@ -5464,6 +5464,7 @@ export const deOverrides = {branchNewChat: 'In neuem Chat abzweigen',react: 'Reagieren',dismissError: 'Fehler schließen',+ responseStopped: 'Antwort gestoppt',errorLayers: {auth: 'Authentifizierungsfehler',billing: 'Keine Credits mehr',diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex b2b2061fda4..d4406105761 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -5085,6 +5085,7 @@ export const en: Translations = {branchNewChat: 'Branch in new chat',react: 'React',dismissError: 'Dismiss error',+ responseStopped: 'Response stopped',errorLayers: {auth: 'Sign-in problem',billing: 'Out of credits',diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.tsindex d41423156a7..df113024ea4 100644--- a/apps/desktop/src/i18n/es.ts+++ b/apps/desktop/src/i18n/es.ts@@ -5460,6 +5460,7 @@ export const esOverrides = {branchNewChat: 'Ramificar en chat nuevo',react: 'Reaccionar',dismissError: 'Descartar error',+ responseStopped: 'Respuesta detenida',errorLayers: {auth: 'Problema de inicio de sesión',billing: 'Créditos agotados',diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.tsindex 78fbaed3fcb..e3434dcb88e 100644--- a/apps/desktop/src/i18n/fr.ts+++ b/apps/desktop/src/i18n/fr.ts@@ -5482,6 +5482,7 @@ export const frOverrides = {branchNewChat: 'Créer une branche dans une nouvelle conversation',react: 'Réagir',dismissError: "Ignorer l'erreur",+ responseStopped: 'Réponse interrompue',errorLayers: {auth: "Erreur d'authentification",billing: 'Crédits épuisés',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 3eddccd189d..f8ab51e9000 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -4319,6 +4319,7 @@ export interface Translations {branchNewChat: stringreact: stringdismissError: string+ responseStopped: string/** Layer titles for the structured error card (agent/error_surface.py).* `generic` is the fallback when the backend sent no descriptor. */errorLayers: {diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.tsindex 5d37f0d7c18..f43d42d86fe 100644--- a/apps/desktop/src/lib/chat-messages.test.ts+++ b/apps/desktop/src/lib/chat-messages.test.ts@@ -158,6 +158,17 @@ describe('toChatMessages', () => {expect(messages[0].parts.map(p => p.timestamp)).toEqual([1, 2, 3])})+ it('restores the stopped flag on a persisted interrupted reply', () => {+ const messages = toChatMessages([+ { role: 'user', content: 'tell a story', timestamp: 1 },+ { role: 'assistant', content: 'Once upon', timestamp: 2, display_metadata: '{"interrupted": true}' },+ { role: 'user', content: 'again', timestamp: 3 },+ { role: 'assistant', content: 'The end.', timestamp: 4 }+ ])++ expect(messages.map(message => message.interrupted)).toEqual([undefined, true, undefined, undefined])+ })+it('starts a hydrated bubble at an earlier leading tool call', () => {const messages = toChatMessages([{diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.tsindex f845e8b2520..a942fbff419 100644--- a/apps/desktop/src/lib/chat-messages/hydration.ts+++ b/apps/desktop/src/lib/chat-messages/hydration.ts@@ -202,6 +202,10 @@ function timelineDisplayText(metadata: SessionMessage['display_metadata']): strireturn typeof text === 'string' && text.trim() ? text : undefined}+function messageInterrupted(metadata: SessionMessage['display_metadata']): boolean {+ return parseDisplayMetadata(metadata)?.interrupted === true+}+function messageReactions(metadata: SessionMessage['display_metadata']): MessageReaction[] {const reactions = parseDisplayMetadata(metadata)?.reactions@@ -573,6 +577,7 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {...(rowId !== undefined ? { rowId } : {}),...(pendingAbsorbedRows > 0 ? { serverRowSpan: pendingAbsorbedRows + 1 } : {}),...(reactions.length ? { reactions } : {}),+ ...(message.role === 'assistant' && messageInterrupted(message.display_metadata) ? { interrupted: true } : {}),...(extractedAttachmentRefs ? { attachmentRefs: extractedAttachmentRefs } : {})})diff --git a/apps/desktop/src/lib/chat-messages/types.ts b/apps/desktop/src/lib/chat-messages/types.tsindex 337832cfa8a..141213298dd 100644--- a/apps/desktop/src/lib/chat-messages/types.ts+++ b/apps/desktop/src/lib/chat-messages/types.ts@@ -49,6 +49,8 @@ export type ChatMessage = {* action footer so only the turn's final reply carries copy/refresh, and* the live view matches rehydration (which merges the turn into one bubble). */interim?: boolean+ /** The user stopped this reply before it finished; its text is partial. */+ interrupted?: boolean/** Locally recovered output not yet represented by a durable completed reply. */recovered?: boolean/** Whether hydration reached a final assistant source row, rather than a tool round. */diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.tsindex 68aa19ae136..190148142ca 100644--- a/apps/desktop/src/lib/chat-runtime.ts+++ b/apps/desktop/src/lib/chat-runtime.ts@@ -490,6 +490,7 @@ export function toRuntimeMessage(message: ChatMessage): ThreadMessage {// Carries ChatMessage.interim to AssistantMessage's footer gate.custom: {...(message.interim ? { interim: true } : {}),+ ...(message.interrupted ? { interrupted: true } : {}),...timelineMeta,...(message.completedAt !== undefined ? { timelineCompletedAt: message.completedAt } : {}),...(message.durationS !== undefined ? { durationS: message.durationS } : {}),diff --git a/tests/agent/test_turn_api_call_interrupt.py b/tests/agent/test_turn_api_call_interrupt.pyindex 46d2b467a50..e1a9baeda2e 100644--- a/tests/agent/test_turn_api_call_interrupt.py+++ b/tests/agent/test_turn_api_call_interrupt.py@@ -72,4 +72,5 @@ def test_ordinary_partial_is_kept_as_the_interrupted_row():messages, verdict = _interrupt("Visible draft.")assert (messages[-1]["role"], messages[-1]["content"]) == ("assistant", "Visible draft.")+ assert messages[-1]["display_metadata"] == {"interrupted": True}assert verdict.final_response == "Visible draft."