The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep blob previews alive across composer clear handoff
stantheman01285de3c046b09e
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.tsindex 2d04ce8720b..e8f749c1c4c 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts@@ -193,7 +193,9 @@ export function useComposerQueue({}clearDraft()- scope.attachments.clear()+ // Queue entry retains blob: previews; revoke when the entry is discarded+ // or drained into a submit that takes ownership (see composer-queue).+ scope.attachments.clear({ retainPreviewUrls: true })triggerHaptic('selection')return true@@ -234,7 +236,8 @@ export function useComposerQueue({}drainFailuresRef.current.delete(entry.id)- removeQueuedPrompt(drainQueueSessionKey, entry.id)+ // Submit now owns the blob: previews (optimistic bubble); do not revoke.+ removeQueuedPrompt(drainQueueSessionKey, entry.id, { retainPreviewUrls: true })resetBrowseState(drainRuntimeSessionId)// A successful drain means the queue is flowing again — lift any park// so the remaining entries follow. Manual drains (Enter on an emptydiff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.tsindex cfd7c5521c7..fd720b1f4bc 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts@@ -286,7 +286,9 @@ export function useComposerSubmit({triggerHaptic('submit')resetBrowseState(sessionId)clearDraft()- scope.attachments.clear()+ // Keep blob: previews alive for the optimistic bubble; revoke when that+ // consumer is discarded/replaced (not here — clear would race the clone).+ scope.attachments.clear({ retainPreviewUrls: true })dispatchSubmit(text, submittedAttachments)}diff --git a/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts b/apps/desktop/src/app/session/hooks/use-background-queue-drain.tsindex 46929653ad1..b67722eb677 100644--- a/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts+++ b/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts@@ -133,7 +133,8 @@ export function useBackgroundQueueDrain({}drainFailuresRef.current.delete(liveEntry.id)- removeQueuedPrompt(sessionKey, liveEntry.id)+ // Submit owns blob: previews after a successful drain handoff.+ removeQueuedPrompt(sessionKey, liveEntry.id, { retainPreviewUrls: true })resetBrowseState(runtimeSessionId)return truediff --git a/apps/desktop/src/store/composer-queue.test.ts b/apps/desktop/src/store/composer-queue.test.tsindex 4fadda8f7db..b7b36a0f1cd 100644--- a/apps/desktop/src/store/composer-queue.test.ts+++ b/apps/desktop/src/store/composer-queue.test.ts@@ -1,6 +1,11 @@-import { beforeEach, describe, expect, it } from 'vitest'+import { beforeEach, describe, expect, it, vi } from 'vitest'-import type { ComposerAttachment } from './composer'+import {+ $composerAttachments,+ addComposerAttachment,+ type ComposerAttachment,+ mainComposerScope+} from './composer'import {$parkedQueueSessions,$queuedPromptsBySession,@@ -31,10 +36,80 @@ function attachment(id: string, kind: ComposerAttachment['kind'] = 'file'): Comp}}+function stubRevokeObjectURL() {+ const revokeObjectURL = vi.fn()+ vi.stubGlobal('URL', { ...URL, revokeObjectURL })++ return revokeObjectURL+}+describe('composer queue store', () => {beforeEach(() => {window.localStorage.removeItem(QUEUE_STORAGE_KEY)$queuedPromptsBySession.set({})+ $composerAttachments.set([])+ vi.unstubAllGlobals()+ vi.restoreAllMocks()+ })++ it('queued-prompt handoff keeps blob previews across composer clear, then revokes when the entry is discarded', () => {+ // Mirrors use-composer-queue: enqueue → clear({ retainPreviewUrls }).+ const revokeObjectURL = stubRevokeObjectURL()+ const blobUrl = 'blob:hermes-queued-1'+ const image = {+ id: 'image:drop',+ kind: 'image' as const,+ label: 'Lattice.png',+ previewUrl: blobUrl+ }+ addComposerAttachment(image)++ const queued = enqueueQueuedPrompt(SESSION_KEY, {+ text: 'look at this',+ attachments: $composerAttachments.get()+ })+ mainComposerScope.clear({ retainPreviewUrls: true })++ expect(queued).not.toBeNull()+ expect($composerAttachments.get()).toEqual([])+ expect(revokeObjectURL).not.toHaveBeenCalled()+ expect(getQueuedPrompts(SESSION_KEY)[0]?.attachments[0]?.previewUrl).toBe(blobUrl)++ expect(removeQueuedPrompt(SESSION_KEY, queued!.id)).toBe(true)+ expect(revokeObjectURL).toHaveBeenCalledWith(blobUrl)+ })++ it('drain handoff retains blob previews when the queued entry is removed after submit owns them', () => {+ const revokeObjectURL = stubRevokeObjectURL()+ const blobUrl = 'blob:hermes-drain-1'+ const queued = enqueueQueuedPrompt(SESSION_KEY, {+ text: 'drain me',+ attachments: [{ id: 'image:drop', kind: 'image', label: 'shot.png', previewUrl: blobUrl }]+ })++ expect(queued).not.toBeNull()+ expect(removeQueuedPrompt(SESSION_KEY, queued!.id, { retainPreviewUrls: true })).toBe(true)+ expect(revokeObjectURL).not.toHaveBeenCalled()+ })++ it('revokes replaced blob previews when a queued entry attachment snapshot changes', () => {+ const revokeObjectURL = stubRevokeObjectURL()+ const oldUrl = 'blob:hermes-old'+ const newUrl = 'blob:hermes-new'+ const queued = enqueueQueuedPrompt(SESSION_KEY, {+ text: 'edit me',+ attachments: [{ id: 'image:old', kind: 'image', label: 'old.png', previewUrl: oldUrl }]+ })++ expect(queued).not.toBeNull()+ expect(+ updateQueuedPrompt(SESSION_KEY, queued!.id, {+ text: 'edit me',+ attachments: [{ id: 'image:new', kind: 'image', label: 'new.png', previewUrl: newUrl }]+ })+ ).toBe(true)+ expect(revokeObjectURL).toHaveBeenCalledWith(oldUrl)+ expect(revokeObjectURL).not.toHaveBeenCalledWith(newUrl)})it('queues prompts in FIFO order', () => {diff --git a/apps/desktop/src/store/composer-queue.ts b/apps/desktop/src/store/composer-queue.tsindex 0afa76a5cfa..a376bfac869 100644--- a/apps/desktop/src/store/composer-queue.ts+++ b/apps/desktop/src/store/composer-queue.ts@@ -1,7 +1,19 @@import { SLASH_COMMAND_RE } from '@hermes/shared'import { atom } from 'nanostores'-import type { ComposerAttachment } from './composer'+import {+ type ComposerAttachment,+ revokeAttachmentPreviewUrls,+ revokeDiscardedAttachmentPreviews+} from './composer'++export interface RemoveQueuedPromptOptions {+ /**+ * When true, leave blob: preview URLs alive because submit/optimistic now+ * owns the snapshot (drain handoff). Default false = entry discarded.+ */+ retainPreviewUrls?: boolean+}export interface QueuedPromptEntry {id: string@@ -188,12 +200,17 @@ export const dequeueQueuedPrompt = (key: string | null | undefined): null | Queureturn null}+ // Caller takes ownership of head.attachments (including any blob: previews).writeSession(sid, rest)return head}-export const removeQueuedPrompt = (key: string | null | undefined, id: string): boolean => {+export const removeQueuedPrompt = (+ key: string | null | undefined,+ id: string,+ options?: RemoveQueuedPromptOptions+): boolean => {const sid = sidOf(key)if (!sid) {@@ -201,14 +218,19 @@ export const removeQueuedPrompt = (key: string | null | undefined, id: string):}const queue = queueFor(sid)+ const removed = queue.find(e => e.id === id)const next = queue.filter(e => e.id !== id)- if (next.length === queue.length) {+ if (!removed || next.length === queue.length) {return false}writeSession(sid, next)+ if (!options?.retainPreviewUrls) {+ revokeAttachmentPreviewUrls(removed.attachments)+ }+return true}@@ -257,6 +279,10 @@ export const updateQueuedPrompt = (return entry}+ if (update.attachments) {+ revokeDiscardedAttachmentPreviews(entry.attachments, attachments)+ }+changed = true// The user rewrote the text, so any display projection it carried (a@@ -286,6 +312,10 @@ export const clearQueuedPrompts = (key: string | null | undefined) => {return}+ for (const entry of queueFor(sid)) {+ revokeAttachmentPreviewUrls(entry.attachments)+ }+writeSession(sid, [])}diff --git a/apps/desktop/src/store/composer.test.ts b/apps/desktop/src/store/composer.test.tsindex a0f13584d6f..94e44bc639c 100644--- a/apps/desktop/src/store/composer.test.ts+++ b/apps/desktop/src/store/composer.test.ts@@ -11,9 +11,11 @@ import {type ComposerAttachment,createComposerAttachmentOccurrenceId,createComposerAttachmentScope,+ mainComposerScope,migrateSessionDraft,removeComposerAttachment,requestVoiceConversationStart,+ revokeAttachmentPreviewUrls,SESSION_DRAFTS_STORAGE_KEY,stashSessionDraft,takeSessionDraft,@@ -39,6 +41,53 @@ function attachment(overrides: Partial<ComposerAttachment> & Pick<ComposerAttachreturn { kind: 'file', label: 'doc.pdf', ...overrides }}+function stubRevokeObjectURL() {+ const revokeObjectURL = vi.fn()+ vi.stubGlobal('URL', { ...URL, revokeObjectURL })++ return revokeObjectURL+}++describe('blob preview URL ownership handoff', () => {+ afterEach(() => {+ $composerAttachments.set([])+ vi.unstubAllGlobals()+ vi.restoreAllMocks()+ })++ it('direct-submit handoff keeps blob previews across clear, then revokes when the optimistic consumer is discarded', () => {+ // Mirrors use-composer-submit: clone → clear({ retainPreviewUrls }) → dispatch clone.+ const revokeObjectURL = stubRevokeObjectURL()+ const blobUrl = 'blob:hermes-direct-submit-1'+ addComposerAttachment(+ attachment({ id: 'image:drop', kind: 'image', label: 'Lattice.png', previewUrl: blobUrl })+ )++ const submittedAttachments = $composerAttachments.get().map(item => ({ ...item }))+ mainComposerScope.clear({ retainPreviewUrls: true })++ expect($composerAttachments.get()).toEqual([])+ expect(revokeObjectURL).not.toHaveBeenCalled()+ expect(submittedAttachments[0]?.previewUrl).toBe(blobUrl)++ // Optimistic bubble discarded / replaced without restoring into the composer.+ revokeAttachmentPreviewUrls(submittedAttachments)+ expect(revokeObjectURL).toHaveBeenCalledWith(blobUrl)+ })++ it('still revokes blob previews on a normal clear (no handoff)', () => {+ const revokeObjectURL = stubRevokeObjectURL()+ const blobUrl = 'blob:hermes-clear-1'+ const scope = createComposerAttachmentScope()+ scope.add(attachment({ id: 'image:x', kind: 'image', previewUrl: blobUrl }))++ scope.clear()++ expect(scope.$attachments.get()).toEqual([])+ expect(revokeObjectURL).toHaveBeenCalledWith(blobUrl)+ })+})+describe('updateComposerAttachment', () => {afterEach(() => {$composerAttachments.set([])diff --git a/apps/desktop/src/store/composer.ts b/apps/desktop/src/store/composer.tsindex be82b9b8d27..17459519ffd 100644--- a/apps/desktop/src/store/composer.ts+++ b/apps/desktop/src/store/composer.ts@@ -4,7 +4,7 @@ import { deriveDraftTitle } from '@/lib/draft-title'import { triggerHaptic } from '@/lib/haptics'/** Release blob: chip previews created for OS image drops (see #63682). */-function revokeAttachmentPreviewUrl(url?: string | null) {+export function revokeAttachmentPreviewUrl(url?: string | null) {if (url?.startsWith('blob:')) {try {URL.revokeObjectURL(url)@@ -14,6 +14,43 @@ function revokeAttachmentPreviewUrl(url?: string | null) {}}+/** Revoke blob: previews for attachments whose consumer was discarded. */+export function revokeAttachmentPreviewUrls(attachments: readonly ComposerAttachment[]) {+ for (const attachment of attachments) {+ revokeAttachmentPreviewUrl(attachment.previewUrl)+ }+}++/**+ * Revoke blob: previews from `previous` that are not retained by `next`.+ * Used when a queued/optimistic snapshot is replaced or dropped.+ */+export function revokeDiscardedAttachmentPreviews(+ previous: readonly ComposerAttachment[],+ next: readonly ComposerAttachment[] = []+) {+ const retained = new Set(+ next.map(attachment => attachment.previewUrl).filter((url): url is string => !!url?.startsWith('blob:'))+ )++ for (const attachment of previous) {+ const url = attachment.previewUrl++ if (url?.startsWith('blob:') && !retained.has(url)) {+ revokeAttachmentPreviewUrl(url)+ }+ }+}++export interface ClearAttachmentsOptions {+ /**+ * When true, leave blob: preview URLs alive for a submitted/queued snapshot+ * that still references them. Caller must revoke when that consumer is+ * discarded or replaced (see #63682 / PR review on #66546).+ */+ retainPreviewUrls?: boolean+}+export interface ComposerAttachment {id: string/** Renderer-lifetime identity for one attachment occurrence. Unlike `id`,@@ -75,7 +112,7 @@ export const takeVoiceConversationStart = (current: number): boolean => {export interface ComposerAttachmentScope {$attachments: ReturnType<typeof atom<ComposerAttachment[]>>add(attachment: ComposerAttachment): void- clear(): void+ clear(options?: ClearAttachmentsOptions): voidremove(id: string): ComposerAttachment | nullremoveOccurrences(attachments: readonly ComposerAttachment[]): voidsetUploadState(id: string, uploadState?: ComposerAttachment['uploadState']): void@@ -103,9 +140,9 @@ export function createComposerAttachmentScope($attachments = atom<ComposerAttachtriggerHaptic('selection')}},- clear() {- for (const attachment of $attachments.get()) {- revokeAttachmentPreviewUrl(attachment.previewUrl)+ clear(options) {+ if (!options?.retainPreviewUrls) {+ revokeAttachmentPreviewUrls($attachments.get())}$attachments.set([])