Skip to content

The agent that grows with you

fix(desktop): align skill success and guard result consumers

yoniebans945eca9aaa52
diff --git a/apps/desktop/src/components/assistant-ui/tool/skill-activity.ts b/apps/desktop/src/components/assistant-ui/tool/skill-activity.ts
index e1eb5edc0da..88d6502753b 100644
--- a/apps/desktop/src/components/assistant-ui/tool/skill-activity.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/skill-activity.ts
@@ -22,7 +22,7 @@ export function skillActivityTitle(part: SkillCall, live = true): string | undef
const args = parseMaybeObject(part.args)
const result = parseMaybeObject(part.result)
- const failed = Boolean(
+ const failed = result.success !== true && result.ok !== true && Boolean(
part.isError || extractToolErrorMessage(part.result) || result.success === false || result.ok === false
)
diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.ts
index 5d67d315174..f5866561804 100644
--- a/apps/desktop/src/lib/chat-messages.test.ts
+++ b/apps/desktop/src/lib/chat-messages.test.ts
@@ -1417,7 +1417,8 @@ describe('sealOpenToolParts', () => {
const next = sealOpenToolParts(messages)
- expect(next[0].parts[0]).toHaveProperty('result')
+ expect(next[0].parts[0]).not.toHaveProperty('result')
+ expect(next[0].parts[0].completedAt).toBeDefined()
})
it('leaves already-completed tool parts untouched', () => {
@@ -1444,7 +1445,8 @@ describe('sealOpenToolParts', () => {
const next = sealOpenToolParts(messages)
expect(next[0].parts[0]).toBe(text)
- expect(next[0].parts[1]).toHaveProperty('result')
+ expect(next[0].parts[1]).not.toHaveProperty('result')
+ expect(next[0].parts[1].completedAt).toBeDefined()
})
it('returns the same array reference when nothing needs sealing', () => {
diff --git a/apps/desktop/src/lib/chat-messages/competing-contracts.test.ts b/apps/desktop/src/lib/chat-messages/competing-contracts.test.ts
new file mode 100644
index 00000000000..b5184d3dcfb
--- /dev/null
+++ b/apps/desktop/src/lib/chat-messages/competing-contracts.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest'
+import { upsertToolPart } from '@/lib/chat-messages'
+import { summarizeToolRun } from '@/components/assistant-ui/tool/run-summary'
+
+describe('D1 competing implementation contracts', () => {
+ it('retains JSON object text as the canonical received value', () => {
+ const result = '{"value":1}'
+ const part = upsertToolPart([], { name: 'terminal', tool_id: 'a', result }, 'complete', 1)[0]
+ expect(part.type === 'tool-call' && part.result).toBe(result)
+ })
+ it('keeps identified parallel running calls separate even with identical args', () => {
+ let parts = upsertToolPart([], { name: 'terminal', tool_id: 'a', args: { command: 'pwd' } }, 'running', 1)
+ parts = upsertToolPart(parts, { name: 'terminal', tool_id: 'b', args: { command: 'pwd' } }, 'running', 2)
+ expect(parts).toHaveLength(2)
+ })
+ it('honors explicit successful skill results over stale envelope errors', () => {
+ const part = { type: 'tool-call' as const, toolName: 'skill_view', args: { name: 'loaded-skill' }, result: { success: true }, isError: true }
+ expect(summarizeToolRun([part], false)).toContain('Loaded skill')
+ })
+ it('does not report a failed skill as loaded in the settled summary', () => {
+ const summary = summarizeToolRun([{ toolName: 'skill_view', args: { name: 'missing-skill' }, result: { error: 'missing' }, isError: true }], false)
+ expect(summary.toLowerCase()).toContain('failed')
+ expect(summary).not.toContain('Loaded')
+ })
+})
diff --git a/apps/desktop/src/lib/chat-messages/d1-consumers.test.ts b/apps/desktop/src/lib/chat-messages/d1-consumers.test.ts
new file mode 100644
index 00000000000..c1aa292e11e
--- /dev/null
+++ b/apps/desktop/src/lib/chat-messages/d1-consumers.test.ts
@@ -0,0 +1,32 @@
+import { fromThreadMessageLike, getAutoStatus } from '@assistant-ui/core/internal'
+import { describe, expect, it } from 'vitest'
+import { buildToolView } from '@/components/assistant-ui/tool/fallback-model'
+import { deriveChangedFiles } from '@/components/assistant-ui/thread/changed-files'
+import { toRuntimeMessage } from '@/lib/chat-runtime'
+import { sealOpenToolParts, upsertToolPart } from '@/lib/chat-messages'
+import { todosFromMessageContent } from '@/lib/todos'
+
+const normalize = (parts: ReturnType<typeof upsertToolPart>) => fromThreadMessageLike(toRuntimeMessage({ id: 'd1', role: 'assistant', parts }), 'd1', getAutoStatus(false, false, false, false, undefined)).content
+
+describe('D1 settlement and presentation consumers', () => {
+ it('seals unknown outcomes without fabricating success and remains idempotent', () => {
+ const messages = [{ id: 'd1', role: 'assistant' as const, parts: upsertToolPart([], { name: 'terminal', tool_id: 'missing' }, 'running', 1) }]
+ const sealed = sealOpenToolParts(messages)
+ const part = sealed[0].parts[0]
+ expect('result' in part ? part.result : undefined).toBeUndefined()
+ expect(part.completedAt).toBeDefined()
+ expect(buildToolView(part as never, '').status).toBe('warning')
+ expect(sealOpenToolParts(sealed)).toBe(sealed)
+ })
+ it('keeps side-channel diffs in the changed-files consumer after normalization', () => {
+ const parts = upsertToolPart([], { name: 'patch', tool_id: 'patch', args: { path: '/tmp/a.ts' }, result: 'ok', inline_diff: '--- a/a.ts\n+++ b/a.ts\n@@ -1 +1 @@\n-old\n+new' }, 'complete', 2)
+ expect(deriveChangedFiles(normalize(parts))).toEqual([{ path: '/tmp/a.ts', name: 'a.ts', added: 1, removed: 1 }])
+ })
+ it('keeps envelope-only todo completion and explicit clearing after normalization', () => {
+ const todos = [{ id: 'a', content: 'Do it', status: 'completed' }]
+ const parts = upsertToolPart([], { name: 'todo_list', tool_id: 'todos', result: 'ok', todos }, 'complete', 2)
+ expect(todosFromMessageContent(normalize(parts))).toEqual(todos)
+ const cleared = upsertToolPart(parts, { name: 'todo_list', tool_id: 'todos', todos: [] }, 'complete', 3)
+ expect(todosFromMessageContent(normalize(cleared))).toEqual([])
+ })
+})