Skip to content

The agent that grows with you

fix(desktop): show tool calls the user interrupted as Interrupted

rodricksz4h5ee9203889aec
diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.ts
index 28aabb0ad7d..3582ea13878 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.ts
@@ -51,7 +51,7 @@ import {
applyReloadOptimistic,
applyRewindOptimistic,
durableRowIdsForRebind,
- finalizeInterruptedMessages,
+ finalizeUserInterruptedMessages,
planEdit,
planReload,
planRestore,
@@ -344,7 +344,7 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored
update(state => ({
...state,
- messages: finalizeInterruptedMessages(state.messages, state.streamId),
+ messages: finalizeUserInterruptedMessages(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.ts
index 253b1a28ecb..5a61075310d 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
@@ -59,7 +59,7 @@ import {
applyReloadOptimistic,
applyRewindOptimistic,
durableRowIdsForRebind,
- finalizeInterruptedMessages,
+ finalizeUserInterruptedMessages,
planEdit,
planReload,
planRestore,
@@ -682,7 +682,7 @@ export function usePromptActions({
if (!sessionId) {
releaseBusy()
- setMessages(finalizeInterruptedMessages($messages.get()))
+ setMessages(finalizeUserInterruptedMessages($messages.get()))
return
}
@@ -693,7 +693,7 @@ export function usePromptActions({
updateSessionState(sessionId, state => {
const streamId = state.streamId
- const messages = finalizeInterruptedMessages(state.messages, streamId)
+ const messages = finalizeUserInterruptedMessages(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.ts
index 3a42802f61b..69ca064b569 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
@@ -8,6 +8,7 @@ import {
applyReloadOptimistic,
applyRewindOptimistic,
finalizeInterruptedMessages,
+ finalizeUserInterruptedMessages,
planEdit,
planReload,
planRestore,
@@ -309,6 +310,65 @@ describe('finalizeInterruptedMessages', () => {
})
})
+describe('finalizeUserInterruptedMessages', () => {
+ const toolTurn = (): ChatMessage => ({
+ id: 'assistant-tool',
+ role: 'assistant',
+ parts: [
+ {
+ args: {} as never,
+ argsText: '{}',
+ completedAt: 10.5,
+ result: 'listed',
+ timestamp: 10,
+ toolCallId: 'call-done',
+ toolName: 'terminal',
+ type: 'tool-call'
+ },
+ {
+ args: {} as never,
+ argsText: '{}',
+ timestamp: 10.5,
+ toolCallId: 'call-open',
+ toolName: 'terminal',
+ type: 'tool-call'
+ }
+ ],
+ pending: true,
+ timestamp: 10
+ })
+
+ it('marks only the tool calls still waiting on a result as interrupted', () => {
+ const [message] = finalizeUserInterruptedMessages([toolTurn()], 'assistant-tool', 11.25)
+ const [done, open] = message.parts
+
+ expect(done.interrupted).toBeUndefined()
+ expect(open.interrupted).toBe(true)
+ expect(open.completedAt).toBe(11.25)
+ expect(message.pending).toBe(false)
+ })
+
+ it('leaves settled turns alone', () => {
+ const settled = { ...toolTurn(), pending: false }
+ const [message] = finalizeUserInterruptedMessages([settled], null, 11.25)
+
+ expect(message.parts[1].interrupted).toBeUndefined()
+ })
+
+ it('does not mark calls sealed by the non-user settle path', () => {
+ const [message] = finalizeInterruptedMessages([toolTurn()], 'assistant-tool', 11.25)
+
+ expect(message.parts[1].interrupted).toBeUndefined()
+ })
+
+ it('marks open tool calls when a mid-turn message seals the live stream', () => {
+ const state: MidTurnState = { interimBoundaryPending: false, messages: [toolTurn()], streamId: 'assistant-tool' }
+ const next = appendMidTurnUserMessage(state, row('user-2', 'user', 'start mode 2'))
+
+ expect(next.messages[0].parts[1].interrupted).toBe(true)
+ })
+})
+
describe('failed-turn-aware ordinal space', () => {
const user = (id: string, rowId?: number): ChatMessage => ({
id,
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.ts
index 72b25801d3c..dc817e51656 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
@@ -16,6 +16,7 @@ import { PROMPT_SUBMIT_REQUEST_TIMEOUT_MS } from '@/hermes'
import {
branchGroupForUser,
type ChatMessage,
+ type ChatMessagePart,
chatMessageText,
completeOpenTimelineParts,
textPart
@@ -418,6 +419,31 @@ export function finalizeInterruptedMessages(
)
}
+const markInterruptedToolCall = (part: ChatMessagePart): ChatMessagePart =>
+ part.type === 'tool-call' && part.completedAt === undefined && part.result === undefined
+ ? { ...part, interrupted: true }
+ : part
+
+/**
+ * Stop/redirect finalize: like `finalizeInterruptedMessages`, but tool calls
+ * still waiting on a result are marked interrupted, so they read as cut short
+ * by the user rather than as a lost result (#116195). A result that still
+ * arrives later takes precedence over the marker.
+ */
+export function finalizeUserInterruptedMessages(
+ messages: ChatMessage[],
+ streamId?: null | string,
+ occurredAt = Date.now() / 1000
+): ChatMessage[] {
+ const marked = messages.map(message =>
+ message.pending || message.id === streamId
+ ? { ...message, parts: message.parts.map(markInterruptedToolCall) }
+ : message
+ )
+
+ return finalizeInterruptedMessages(marked, streamId, occurredAt)
+}
+
/**
* Arrival-ordered mid-turn user insert (#73793, #83151).
*
@@ -435,7 +461,7 @@ export function appendMidTurnUserMessage<
State extends { interimBoundaryPending: boolean; messages: ChatMessage[]; streamId: null | string }
>(state: State, message: ChatMessage): State {
const liveId = state.streamId
- const sealed = finalizeInterruptedMessages(state.messages, liveId)
+ const sealed = finalizeUserInterruptedMessages(state.messages, liveId)
const sealedLiveKept = liveId !== null && sealed.some(row => row.id === liveId)
const messages = [
diff --git a/apps/desktop/src/components/assistant-ui/thread/sealed-tool-parts.test.tsx b/apps/desktop/src/components/assistant-ui/thread/sealed-tool-parts.test.tsx
index 82206dd9400..98b8242c47c 100644
--- a/apps/desktop/src/components/assistant-ui/thread/sealed-tool-parts.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/sealed-tool-parts.test.tsx
@@ -16,7 +16,7 @@ stubThreadViewportSize()
const createdAt = new Date('2026-09-11T12:00:00Z')
const sealedAt = createdAt.getTime() / 1000 + 5
-function sealedMessage(toolName: string, args: Record<string, unknown>): ThreadMessage {
+function sealedMessage(toolName: string, args: Record<string, unknown>, extra: Record<string, unknown> = {}): ThreadMessage {
return {
id: `assistant-sealed-${toolName}`,
role: 'assistant',
@@ -27,7 +27,8 @@ function sealedMessage(toolName: string, args: Record<string, unknown>): ThreadM
toolName,
args,
argsText: JSON.stringify(args),
- completedAt: sealedAt
+ completedAt: sealedAt,
+ ...extra
}
],
status: { type: 'complete', reason: 'stop' },
@@ -78,4 +79,11 @@ describe('tool parts sealed without a result', () => {
expect(await screen.findByText('Result unavailable')).toBeTruthy()
expect(container.querySelector('[data-slot="aui_agent-delivery-notice"]')).toBeNull()
})
+
+ it('renders a call the user interrupted as Interrupted, not as a lost result', async () => {
+ render(<Harness message={sealedMessage('terminal', { command: 'ls' }, { interrupted: true })} />)
+
+ expect(await screen.findByText('Interrupted')).toBeTruthy()
+ expect(screen.queryByText('Result unavailable')).toBeNull()
+ })
})
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
index 1505450a68f..5c5d24648ef 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
@@ -146,6 +146,32 @@ describe('buildToolView envelope errors', () => {
})
})
+describe('buildToolView calls sealed without a result', () => {
+ it('warns that a lost result is unavailable', () => {
+ const view = buildToolView(part({ completedAt: 5, result: undefined, toolName: 'terminal' }), '')
+
+ expect(view.status).toBe('warning')
+ expect(view.title).toBe('Result unavailable')
+ })
+
+ it('shows a call the user interrupted as a neutral notice', () => {
+ const view = buildToolView(
+ part({ completedAt: 5, interrupted: true, result: undefined, toolName: 'terminal' }),
+ ''
+ )
+
+ expect(view.status).toBe('notice')
+ expect(view.title).toBe('Interrupted')
+ })
+
+ it('shows the real result when one arrived after the interruption', () => {
+ const view = buildToolView(part({ completedAt: 5, interrupted: true, result: 'ok', toolName: 'terminal' }), '')
+
+ expect(view.status).toBe('success')
+ expect(view.title).not.toBe('Interrupted')
+ })
+})
+
describe('buildToolView browser_exec step label', () => {
const bexec = (code: string) =>
buildToolView(part({ args: { code }, result: undefined, toolName: 'browser_exec' }), '')
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
index 1dd0e161a0c..2ad6cb3150b 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
@@ -706,8 +706,9 @@ function toolStatus(part: ToolPart, resultRecord: Record<string, unknown>): Tool
return 'running'
}
+ // A call the user stopped is expected to have no result; don't warn about it.
if (part.result === undefined && !part.isError) {
- return 'warning'
+ return part.interrupted ? 'notice' : 'warning'
}
// Explicit success wins over isError / nested-error heuristics. Memory writes
@@ -1477,7 +1478,11 @@ export function buildToolView(part: ToolPart, inlineDiff: string): ToolView {
)
const unavailable = part.result === undefined && part.completedAt !== undefined
- const title = unavailable ? translateNow('assistant.tool.resultUnavailable') : titleParts.title
+
+ const title = unavailable
+ ? translateNow(part.interrupted ? 'assistant.tool.resultInterrupted' : 'assistant.tool.resultUnavailable')
+ : titleParts.title
+
const titleEnriched = title !== baseTitle
const baseSubtitle = error || toolSubtitle(part, argsRecord, resultRecord)
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model/types.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model/types.ts
index 3fde8136d50..856dfa5fb68 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model/types.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model/types.ts
@@ -7,6 +7,7 @@ export interface ToolPart {
toolResultMetadata?: ToolResultMetadata
args?: unknown
completedAt?: number
+ interrupted?: boolean
isError?: boolean
result?: unknown
timestamp?: number
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback.tsx b/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
index 875e6b0b3b0..1cde4a24d4c 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
@@ -360,12 +360,13 @@ function ToolEntry({ part }: ToolEntryProps) {
// below and re-running buildToolView (full JSON.stringify of result) on every
// stream delta — the freeze on big `/learn` runs. Re-derive a stable part from
// the referentially-stable args/result so the memos hold across deltas.
- const { args, completedAt, isError, result, toolResultMetadata, timestamp, toolCallId, toolName } = part
+ const { args, completedAt, interrupted, isError, result, toolResultMetadata, timestamp, toolCallId, toolName } = part
const stablePart = useMemo<ToolPart>(
() => ({
args,
completedAt,
+ interrupted,
isError,
result,
toolResultMetadata,
@@ -374,7 +375,7 @@ function ToolEntry({ part }: ToolEntryProps) {
toolName,
type: 'tool-call'
}),
- [args, completedAt, isError, result, toolResultMetadata, timestamp, toolCallId, toolName]
+ [args, completedAt, interrupted, isError, result, toolResultMetadata, timestamp, toolCallId, toolName]
)
const disclosureId = toolEntryDisclosureId(messageId, stablePart)
@@ -1083,13 +1084,14 @@ export const ToolGroupSlot: FC<PropsWithChildren<{ endIndex: number; startIndex:
* group-shape changes.
*/
type TimelineToolCallProps = ToolCallMessagePartProps &
- Pick<ToolPart, 'completedAt' | 'timestamp' | 'toolResultMetadata'>
+ Pick<ToolPart, 'completedAt' | 'interrupted' | 'timestamp' | 'toolResultMetadata'>
export const ToolFallback = ({
toolCallId,
toolName,
args,
completedAt,
+ interrupted,
isError,
result,
toolResultMetadata,
@@ -1098,6 +1100,7 @@ export const ToolFallback = ({
const part: ToolPart = {
args,
completedAt,
+ interrupted,
isError,
result,
toolResultMetadata,
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 823fa39d9df..c13963bdc6a 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -3027,6 +3027,7 @@ export const ar = defineLocale({
statusRecovered: 'تم الاسترداد',
statusDone: 'تم',
resultUnavailable: 'النتيجة غير متاحة',
+ resultInterrupted: 'تمت المقاطعة',
memoryWriteNoted: 'تم تسجيل كتابة الذاكرة',
actions: {
read: 'قراءة',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 7c4ddec4df4..32de648c571 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -4352,6 +4352,7 @@ export const en: Translations = {
statusRecovered: 'Recovered',
statusDone: 'Done',
resultUnavailable: 'Result unavailable',
+ resultInterrupted: 'Interrupted',
memoryWriteNoted: 'Memory write noted',
actions: {
read: 'Read',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 16b5e7f9faf..df4eadb6732 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -3506,6 +3506,7 @@ export const ja = defineLocale({
statusRecovered: '回復しました',
statusDone: '完了',
resultUnavailable: '結果を取得できません',
+ resultInterrupted: '中断されました',
memoryWriteNoted: 'メモリへの書き込みを記録',
actions: {
read: '読み取り完了',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 05ed73aff88..40fd1de3074 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -3805,6 +3805,7 @@ export const ru = defineLocale({
statusRecovered: 'Восстановлено',
statusDone: 'Готово',
resultUnavailable: 'Результат недоступен',
+ resultInterrupted: 'Прервано',
memoryWriteNoted: 'Запись в память отмечена',
actions: {
read: 'Чтение',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index d761f086991..535d0c5d5a9 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -3695,6 +3695,7 @@ export interface Translations {
statusDone: string
/** Over-budget / rejected memory write title — not "Saved to memory". */
resultUnavailable: string
+ resultInterrupted: string
memoryWriteNoted: string
actions: {
read: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 9ae0f403d5f..31e3269f183 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -3461,6 +3461,7 @@ export const zhHant = defineLocale({
statusRecovered: '已復原',
statusDone: '完成',
resultUnavailable: '結果無法使用',
+ resultInterrupted: '已中斷',
memoryWriteNoted: '已記下記憶寫入',
actions: {
read: '已讀取',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 2482729c976..46a8415a3bf 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -4268,6 +4268,7 @@ export const zh = defineLocale({
statusRecovered: '已恢复',
statusDone: '完成',
resultUnavailable: '结果不可用',
+ resultInterrupted: '已中断',
memoryWriteNoted: '已记下记忆写入',
actions: {
read: '已读取',
diff --git a/apps/desktop/src/lib/chat-messages/types.ts b/apps/desktop/src/lib/chat-messages/types.ts
index 57127ff758e..54e4c18629f 100644
--- a/apps/desktop/src/lib/chat-messages/types.ts
+++ b/apps/desktop/src/lib/chat-messages/types.ts
@@ -12,6 +12,8 @@ export interface TimelinePartMetadata {
timestamp?: number
/** Unix seconds when this segment stopped or handed off to the next one. */
completedAt?: number
+ /** A tool call the user stopped or redirected before its result arrived. */
+ interrupted?: boolean
/** Raw streamed text behind a `text` part whose MEDIA tags are already rendered,
* so the next delta re-renders from the source instead of the render. */
mediaSource?: string