Skip to content

The agent that grows with you

fix: restore prepared desktop image drafts after restart

Teknium5034ee3a4a20
diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx
index 26ce9493d63..3ab56e47f13 100644
--- a/apps/desktop/src/app/chat/composer/index.tsx
+++ b/apps/desktop/src/app/chat/composer/index.tsx
@@ -45,6 +45,7 @@ import { ContextMenu } from './context-menu'
import { COMPOSER_AREAS, runComposerMiddleware } from './contrib'
import { ComposerControls } from './controls'
import { ComposerDirectiveActions } from './directive-actions'
+import { discardLostPrompt } from './discard-lost-prompt'
import { COMPOSER_DROP_ACTIVE_CLASS, COMPOSER_DROP_FADE_CLASS } from './drop-affordance'
import { markActiveComposer, onComposerAttachImagesRequest } from './focus'
import { HelpHint } from './help-hint'
@@ -68,6 +69,7 @@ import { useSlashCompletions } from './hooks/use-slash-completions'
import { useSessionStatusPresence } from './hooks/use-status-presence'
import { ActionBadges } from './micro-actions'
import { chipTypedPathOnSpace, pathifyRefs } from './path-refs'
+import { PreparedImageRecovery } from './prepared-image-recovery'
import { QueuePanel } from './queue-panel'
import {
beginComposerComposition,
@@ -1207,6 +1209,12 @@ export function ChatBar({
<div className={cn(composerFloatingStrip, 'px-[5px] pb-1.5 empty:hidden')}>
<ActionBadges sessionId={statusSessionId} />
<SuggestionPills sessionId={statusSessionId} />
+ <PreparedImageRecovery
+ occupied={hasText || attachments.length > 0 || busy || disabled}
+ onRestore={loadIntoComposer}
+ request={requestBusyConfig}
+ sessionKey={activeQueueSessionKey}
+ />
</div>
{/* Session-scoped status stack (todos, subagents, background tasks,
queue). An in-flow dock child: the dock is bottom-anchored, so it
@@ -1230,7 +1238,7 @@ export function ChatBar({
// from the queue once the acknowledgement commits. Canonical
// local sessions key the queue by their own session id, so the
// stored key stands in when the runtime id is not bound yet.
- gateway.request('prompt.resolve_unknown', { session_id: sessionId ?? activeQueueSessionKey, admission_id: id })
+ discardLostPrompt(sessionId, activeQueueSessionKey, id, gateway.request.bind(gateway))
.catch((error: unknown) => notifyError(error, t.composer.queueLostDiscard))
} : undefined}
onEdit={beginQueuedEdit}
diff --git a/apps/desktop/src/app/chat/composer/prepared-image-recovery.test.tsx b/apps/desktop/src/app/chat/composer/prepared-image-recovery.test.tsx
new file mode 100644
index 00000000000..b21b7f2c458
--- /dev/null
+++ b/apps/desktop/src/app/chat/composer/prepared-image-recovery.test.tsx
@@ -0,0 +1,45 @@
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { afterEach, expect, test, vi } from 'vitest'
+
+import { preparedSubmissionKey, writePreparedSubmission } from '@/app/session/hooks/use-prompt-actions/prepared-submissions'
+import { captureSubmissionDestination } from '@/app/session/hooks/use-prompt-actions/submission-destination'
+
+import { PreparedImageRecovery } from './prepared-image-recovery'
+
+afterEach(() => { localStorage.clear() })
+
+test('reopened composer offers exact image occurrence only for its original destination', async () => {
+ const request = vi.fn()
+ const destination = captureSubmissionDestination('original', request)
+ const attachments = [{ id: 'image', occurrenceId: 'occurrence', kind: 'image' as const, label: 'image.png', path: '/cache/images/exact.png', mime: 'image/png' }]
+ const key = preparedSubmissionKey('original', destination, ' retained image ', attachments)
+ await writePreparedSubmission(key, { id: 'submission', owner: destination.owner, text: 'expanded wire', attachments, params: { session_id: 'original' } })
+ const restore = vi.fn()
+ const view = render(<PreparedImageRecovery occupied={false} onRestore={restore} request={request} sessionKey="elsewhere" />)
+ await waitFor(() => expect(request).not.toHaveBeenCalled())
+ expect(screen.queryByRole('button')).toBeNull()
+ view.rerender(<PreparedImageRecovery occupied={false} onRestore={restore} request={request} sessionKey="original" />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Restore image draft' }))
+ expect(restore).toHaveBeenCalledWith(' retained image ', attachments)
+ expect(request).not.toHaveBeenCalled()
+})
+
+test('recovery never overwrites a newer draft or offers an ambiguous legacy send', async () => {
+ const request = vi.fn()
+ const destination = captureSubmissionDestination('original', request)
+ const attachments = [{ id: 'image', kind: 'image' as const, label: 'image.png' }]
+
+ for (const legacyAttempted of [false, true]) {
+ await writePreparedSubmission(preparedSubmissionKey('original', destination, String(legacyAttempted), attachments), {
+ id: String(legacyAttempted), owner: destination.owner, text: String(legacyAttempted), attachments, params: {}, legacyAttempted
+ })
+ }
+
+ const restore = vi.fn()
+ render(<PreparedImageRecovery occupied onRestore={restore} request={request} sessionKey="original" />)
+ const button = await screen.findByRole('button', { name: 'Restore image draft' })
+ expect(screen.getAllByRole('button')).toHaveLength(1)
+ expect((button as HTMLButtonElement).disabled).toBe(true)
+ fireEvent.click(button)
+ expect(restore).not.toHaveBeenCalled()
+})
diff --git a/apps/desktop/src/app/chat/composer/prepared-image-recovery.tsx b/apps/desktop/src/app/chat/composer/prepared-image-recovery.tsx
new file mode 100644
index 00000000000..37a14eb6d8b
--- /dev/null
+++ b/apps/desktop/src/app/chat/composer/prepared-image-recovery.tsx
@@ -0,0 +1,47 @@
+import { useEffect, useState } from 'react'
+
+import { listPreparedImageDrafts } from '@/app/session/hooks/use-prompt-actions/prepared-submissions'
+import { captureSubmissionDestination } from '@/app/session/hooks/use-prompt-actions/submission-destination'
+import type { GatewayRequest } from '@/app/session/hooks/use-prompt-actions/utils'
+import { Button } from '@/components/ui/button'
+import { useI18n } from '@/i18n'
+import type { ComposerAttachment } from '@/store/composer'
+import { notifyError } from '@/store/notifications'
+
+interface Props {
+ sessionKey: string | null
+ request: GatewayRequest
+ occupied: boolean
+ onRestore: (text: string, attachments: ComposerAttachment[]) => void
+}
+
+export function PreparedImageRecovery({ sessionKey, request, occupied, onRestore }: Props) {
+ const { t } = useI18n()
+ const [drafts, setDrafts] = useState<Awaited<ReturnType<typeof listPreparedImageDrafts>>>([])
+ const scopeKey = captureSubmissionDestination(sessionKey, request).scopeKey
+
+ useEffect(() => {
+ let cancelled = false
+ setDrafts([])
+
+ if (sessionKey) {
+ void listPreparedImageDrafts(sessionKey, scopeKey).then(entries => {
+ if (!cancelled) { setDrafts(entries) }
+ }).catch(error => {
+ if (!cancelled) { notifyError(error, t.composer.restoreImageDraft) }
+ })
+ }
+
+ return () => { cancelled = true }
+ }, [sessionKey, scopeKey, t.composer.restoreImageDraft])
+
+ return drafts.map(draft => (
+ <div className="flex items-center gap-2 rounded-md border bg-background px-3 py-2 text-xs" key={draft.key}>
+ <span className="min-w-0 flex-1 truncate">{draft.text || draft.attachments.map(attachment => attachment.label).join(', ')}</span>
+ <Button disabled={occupied} onClick={() => {
+ onRestore(draft.text, draft.attachments)
+ setDrafts(current => current.filter(entry => entry.key !== draft.key))
+ }} size="sm" type="button" variant="outline">{t.composer.restoreImageDraft}</Button>
+ </div>
+ ))
+}
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
index c58ac013f32..7896ff9e789 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prepared-submissions.ts
@@ -52,6 +52,19 @@ export function preparedSubmissionKey(
])
}
+export async function listPreparedImageDrafts(target: string, scopeKey: string) {
+ return Object.entries(await readJournal()).flatMap(([key, entry]) => {
+ const [scope, session, text, , displayKind, fromQueue, submissionId] = JSON.parse(key)
+
+ // Restoring an ordinary draft must recreate its exact retry key. Queue and
+ // slash submissions have additional intent fields and own their recovery.
+ return scope === scopeKey && session === target && !displayKind && !fromQueue && !submissionId &&
+ !entry.legacyAttempted && entry.attachments.some(attachment => attachment.kind === 'image')
+ ? [{ key, text: String(text), attachments: entry.attachments }]
+ : []
+ })
+}
+
export async function readPreparedSubmission(key: string): Promise<PreparedSubmission | undefined> {
return (await readJournal())[key]
}
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 546a327ed12..bb231b1af60 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -1996,6 +1996,7 @@ export const ar = defineLocale({
queueSend: 'إرسالها الآن',
queueDelete: 'حذف من الطابور',
queueLostNote: 'فُقد الدور أثناء إعادة التشغيل',
+ restoreImageDraft: 'استعادة مسودة الصورة',
queueLostDiscard: 'تجاهل',
queueLostDiscardTip: 'أعادت البوابة التشغيل أثناء هذا الدور ولا يمكن إكماله. تجاهله لتستمر الأدوار المنتظرة خلفه.',
queueStuckTitle: 'لم تُرسل الرسالة في قائمة الانتظار',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 055a2e2cfed..e27f4c521ec 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2702,6 +2702,7 @@ export const en: Translations = {
queueSend: 'Send',
queueDelete: 'Delete',
queueLostNote: 'Turn lost during restart',
+ restoreImageDraft: 'Restore image draft',
queueLostDiscard: 'Discard',
queueLostDiscardTip: 'The gateway restarted mid-turn and cannot finish this one. Discard it so the queued turns behind it run.',
queueResume: 'Resume',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index eb38293e773..ef7d7cdfe91 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2340,6 +2340,7 @@ export const ja = defineLocale({
queueSend: '送信',
queueDelete: '削除',
queueLostNote: '再起動中にターンが失われました',
+ restoreImageDraft: '画像の下書きを復元',
queueLostDiscard: '破棄',
queueLostDiscardTip: 'ターン中にゲートウェイが再起動したため完了できません。破棄すると後続のキュー済みターンが実行されます。',
queueResume: '再開',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index fa35d26f21a..3a61c01bad6 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -2692,6 +2692,7 @@ export const ru = defineLocale({
queueSend: 'Отправить',
queueDelete: 'Удалить',
queueLostNote: 'Ход потерян при перезапуске',
+ restoreImageDraft: 'Восстановить черновик с изображением',
queueLostDiscard: 'Отбросить',
queueLostDiscardTip: 'Шлюз перезапустился посреди хода и не может его завершить. Отбросьте его, чтобы очередь продолжилась.',
queueResume: 'Продолжить',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 63ff6b5e4c4..562939877f7 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2304,6 +2304,7 @@ export interface Translations {
queueSteer: string
queueDelete: string
queueLostNote: string
+ restoreImageDraft: string
queueLostDiscard: string
queueLostDiscardTip: string
queueResume: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index f3ab48e3bc2..80db20f7163 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2258,6 +2258,7 @@ export const zhHant = defineLocale({
queueSend: '傳送',
queueDelete: '刪除',
queueLostNote: '重新啟動期間該回合已遺失',
+ restoreImageDraft: '還原圖片草稿',
queueLostDiscard: '捨棄',
queueLostDiscardTip: '閘道在該回合進行中重新啟動,無法完成。捨棄後其後的排隊回合將繼續執行。',
queueResume: '繼續',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 43ed70e621a..cefb7e881df 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -2860,6 +2860,7 @@ export const zh: Translations = {
queueSend: '发送',
queueDelete: '删除',
queueLostNote: '重启期间该轮次已丢失',
+ restoreImageDraft: '恢复图片草稿',
queueLostDiscard: '丢弃',
queueLostDiscardTip: '网关在该轮次进行中重启,无法完成。丢弃后其后的排队轮次将继续执行。',
queueResume: '继续',
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 29aee8c4265..8d534d0b6bf 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -103,6 +103,8 @@ Explore and preview the working directory without leaving the app — useful for
When connected to a remote gateway, opening a file artifact downloads it through that gateway, using the artifact’s originating profile and session. Relative paths resolve against the session’s saved working directory; home-relative paths use the gateway’s home, never the Desktop machine’s home. Windows-style relative paths are recognized alongside forward-slash paths, and file URIs retain drive and network-share information for the gateway to interpret. Missing sessions or working directories produce an error rather than selecting a different local file.
+If Desktop closes before an image message is acknowledged, reopen its original chat. The **Restore image draft** button above the composer restores the saved text and image attachment together; press Send to retry the original submission. It never sends automatically or replaces a newer draft.
+
The **Artifacts** view collects what your sessions generate — **images, files, and links** — into one searchable, browsable gallery. Open it from the sidebar, the command palette (**Artifacts — Browse generated outputs**), or a `nav.artifacts` shortcut you bind yourself. It indexes recent session outputs automatically; every artifact shows which session produced it with a jump back to that chat, and images and files open in a preview with download / open-in-browser / copy actions.
### Windows, tabs & panes