Skip to content

The agent that grows with you

fix: preserve Desktop async report bodies during hydration

Teknium8c10ffba55d8
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.ts
index 875b059ed23..c3a38d46384 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
@@ -150,6 +150,7 @@ const _chatMessageFieldsExhaustive: {
} = {}
const COMPARED_FIELDS = [
+ 'asyncResult',
'id',
'role',
'pending',
diff --git a/apps/desktop/src/components/assistant-ui/thread/system-message.tsx b/apps/desktop/src/components/assistant-ui/thread/system-message.tsx
index 112611ffe06..08a919e9de2 100644
--- a/apps/desktop/src/components/assistant-ui/thread/system-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/system-message.tsx
@@ -1,6 +1,7 @@
import { MessagePrimitive, useAuiState } from '@assistant-ui/react'
import { type FC } from 'react'
+import { MarkdownTextContent } from '@/components/assistant-ui/markdown-text'
import { messageContentText } from '@/components/assistant-ui/thread/content'
import { MessageTimelineTimestamp } from '@/components/assistant-ui/thread/timeline-timestamp'
import { SCAFFOLD_LABEL_CLASS } from '@/components/chat/scaffold-row'
@@ -15,11 +16,27 @@ const REVIEW_NOTE_RE = /^review:(?<label>[^:\n]+):?\s*(?<detail>[\s\S]*)$/
export const SystemMessage: FC = () => {
const text = useAuiState(s => messageContentText(s.message.content))
+ const asyncResult = useAuiState(s => s.message.metadata.custom?.asyncResult)
if (!text) {
return null
}
+ if (typeof asyncResult === 'string' && asyncResult) {
+ return (
+ <MessagePrimitive.Root
+ className="flex w-full min-w-0 flex-col gap-2 self-start py-1"
+ data-role="system"
+ data-slot="aui_system-message-root"
+ >
+ <div className="text-[0.6875rem] leading-5 text-muted-foreground/55">
+ {text} <MessageTimelineTimestamp />
+ </div>
+ <MarkdownTextContent isRunning={false} text={asyncResult} />
+ </MessagePrimitive.Root>
+ )
+ }
+
// The self-improvement review saved something to memory/skills — the same
// kind of event as a landed `memory` write, so it wears the same chrome:
// brain glyph with the gold→purple glow, gradient label, purple detail,
diff --git a/apps/desktop/src/lib/async-report.test.ts b/apps/desktop/src/lib/async-report.test.ts
new file mode 100644
index 00000000000..3075201a32a
--- /dev/null
+++ b/apps/desktop/src/lib/async-report.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from 'vitest'
+
+import { toChatMessages } from '@/lib/chat-messages/hydration'
+import { toRuntimeMessage } from '@/lib/chat-runtime'
+
+const report = '# Report\n\n**Conclusion:** ready\n\n| Task | Status |\n|---|---|\n| probe | ok |'
+
+const envelope = (body: string) =>
+ `[ASYNC DELEGATION COMPLETE — probe]\nPrivate instructions\nOriginal goal: private goal\nRole: leaf\n--- RESULT ---\n${body}`
+
+function hydrate(content: string) {
+ return toRuntimeMessage(
+ toChatMessages([
+ {
+ role: 'user',
+ content,
+ display_kind: 'async_delegation_complete',
+ display_metadata: { delegation_id: 'probe', task_count: 1 }
+ }
+ ])[0]
+ )
+}
+
+describe('async report hydration', () => {
+ it('keeps only result bodies beside compact system metadata across current and legacy deliveries', () => {
+ for (const input of [
+ envelope(report),
+ envelope(
+ `Cron job 'probe' (id) finished its manual run.\nResult: ok\nDelivery target: local\n--- JOB OUTPUT ---\n${report}`
+ ),
+ report
+ ]) {
+ const message = hydrate(input)
+ expect(message.role).toBe('system')
+ expect(message.content).toEqual([{ type: 'text', text: '1 background agent finished' }])
+ expect(message.metadata.custom.asyncResult).toBe(report)
+ }
+ })
+
+ it('separates batch result blocks without leaking preambles or transcript plumbing', () => {
+ const content = `[ASYNC DELEGATION BATCH COMPLETE — batch]\nPrivate instructions\nRole: leaf\n\n--- ✓ TASK 1/2: private goal (status=completed) ---\n${report}\nFull live transcript (complete tool/assistant trace): /private/path\n\n--- ✓ TASK 2/2 (status=completed) ---\nPlain result`
+ expect(hydrate(content).metadata.custom.asyncResult).toBe(`${report}\n\nPlain result`)
+ expect(
+ hydrate('[ASYNC DELEGATION COMPLETE — malformed]\nPrivate instructions').metadata.custom.asyncResult
+ ).toBeUndefined()
+ expect(hydrate('').metadata.custom.asyncResult).toBeUndefined()
+ })
+})
diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.ts
index 0d179c0f541..53fc0cebe94 100644
--- a/apps/desktop/src/lib/chat-messages/hydration.ts
+++ b/apps/desktop/src/lib/chat-messages/hydration.ts
@@ -159,6 +159,33 @@ function messageReactions(metadata: SessionMessage['display_metadata']): Message
)
}
+// Only parse producer-owned boundaries, never render the model's task preamble.
+// Older backends can persist an unwrapped result rather than an envelope.
+function asyncResultBody(content: string): string | undefined {
+ let bodies = [content]
+
+ if (content.startsWith('[ASYNC DELEGATION')) {
+ if (content.startsWith('[ASYNC DELEGATION BATCH COMPLETE')) {
+ bodies = content.split(/^--- [✓✗⚠] TASK [^\n]+ ---\r?\n/gm).slice(1)
+ } else {
+ const result = content.match(/^--- (?:RESULT|ERROR) ---\r?\n/m)
+ bodies = result ? [content.slice(result.index! + result[0].length)] : []
+ }
+ }
+
+ return (
+ bodies
+ .map(body => {
+ const output = body.startsWith('Cron job ') ? body.match(/^--- JOB OUTPUT ---\r?\n/m) : null
+ const result = output ? body.slice(output.index! + output[0].length) : body
+
+ return result.replace(/\nFull live transcript \(complete tool\/assistant trace\): [^\n]*\n*$/, '').trim()
+ })
+ .filter(Boolean)
+ .join('\n\n') || undefined
+ )
+}
+
function timelineDisplayContent(message: SessionMessage, content: string): string {
if (message.display_kind === 'model_switch') {
return 'model changed'
@@ -381,6 +408,9 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {
id: `${message.timestamp || Date.now()}-${index}-${displayRole}`,
role: displayRole,
parts,
+ ...(message.display_kind === 'async_delegation_complete'
+ ? { asyncResult: asyncResultBody(displayContentForMessage(message.role, message.content || content)) }
+ : {}),
timestamp: earliestTimestamp(message.timestamp, ...parts.map(part => part.timestamp)),
...(rowId !== undefined ? { rowId } : {}),
...(reactions.length ? { reactions } : {}),
diff --git a/apps/desktop/src/lib/chat-messages/types.ts b/apps/desktop/src/lib/chat-messages/types.ts
index f7f04727366..ef2a21f5146 100644
--- a/apps/desktop/src/lib/chat-messages/types.ts
+++ b/apps/desktop/src/lib/chat-messages/types.ts
@@ -18,6 +18,8 @@ export type ChatMessage = {
id: string
role: SessionMessage['role']
parts: ChatMessagePart[]
+ /** Result body only; the system text remains the compact completion label. */
+ asyncResult?: string
timestamp?: number
completedAt?: number
pending?: boolean
diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.ts
index 98f4ff8b7f5..78fafc2faf2 100644
--- a/apps/desktop/src/lib/chat-runtime.ts
+++ b/apps/desktop/src/lib/chat-runtime.ts
@@ -459,7 +459,7 @@ export function toRuntimeMessage(message: ChatMessage): ThreadMessage {
role,
content: [textPart(text)],
createdAt,
- metadata: { custom: timelineMeta }
+ metadata: { custom: { ...timelineMeta, ...(message.asyncResult ? { asyncResult: message.asyncResult } : {}) } }
} as ThreadMessage
}
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index ce9e3bab203..5494b197cb1 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -51,6 +51,8 @@ The center of the app. You get:
- **A conversation timeline rail** — long chats get a slim rail of markers along the edge of the transcript, one per prompt. Hover it to pop open the list of prompts, click one to jump straight to that point in the conversation. (It appears once the chat has a handful of turns.)
- **Find in page** — press **Cmd/Ctrl+F** to open a find bar that searches the rendered chat transcript. Enter / Shift+Enter (or Cmd/Ctrl+G / Cmd/Ctrl+Shift+G while the bar is open) step through matches; Esc closes it.
+Async cron and delegation completions keep a compact timeline label and render the result body (including job output) as Markdown. Task instructions and delivery envelopes are not shown as report content.
+
#### Status bar
The bar along the bottom of the chat shows live session state and exposes quick controls without opening Settings: