fix: preserve Desktop async report bodies during hydration

Keep compact completion labels while rendering only result and job output bodies, including legacy and batch deliveries. Credit Gyarados4157's #101083 investigation; avoid rendering its full model instruction envelope.
This commit is contained in:
Teknium
2026-09-07 01:50:40 -07:00
parent a51912c25b
commit 8c10ffba55
7 changed files with 101 additions and 1 deletions
@@ -150,6 +150,7 @@ const _chatMessageFieldsExhaustive: {
} = {}
const COMPARED_FIELDS = [
'asyncResult',
'id',
'role',
'pending',
@@ -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,
+48
View File
@@ -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()
})
})
@@ -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 } : {}),
@@ -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
+1 -1
View File
@@ -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
}
+2
View File
@@ -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: