Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(downloads): a cleared finished download stays cleared

purple930f87b79671
diff --git a/src/stores/__tests__/downloadStore-cleared-finished-row-stays-cleared.test.ts b/src/stores/__tests__/downloadStore-cleared-finished-row-stays-cleared.test.ts
new file mode 100644
index 00000000..99137f3a
--- /dev/null
+++ b/src/stores/__tests__/downloadStore-cleared-finished-row-stays-cleared.test.ts
@@ -0,0 +1,101 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * Bug hunt C9 (Oktober 2026): a chat download finished. Download badge,
+ * "Clear completed": the row went, and 1.5 s later it was back ("Complete
+ * (1 file)"), because the poll rebuilt the rows from the Rust map, which keeps
+ * finished entries. The X on the row held only until Models was opened again,
+ * whose mount refresh brought it back the same way.
+ *
+ * Run: npx vitest run src/stores/__tests__/downloadStore-cleared-finished-row-stays-cleared.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+
+const io = vi.hoisted(() => ({
+ rows: {} as Record<string, unknown>,
+ clear: vi.fn(async (_id: string) => {}),
+}))
+
+vi.mock('../../api/discover', async () => {
+ const actual = await vi.importActual<typeof import('../../api/discover')>('../../api/discover')
+ return {
+ ...actual,
+ getDownloadProgress: vi.fn(async () => io.rows),
+ cancelDownload: vi.fn(async () => {}),
+ clearDownloadEntry: (id: string) => io.clear(id),
+ }
+})
+
+import { useDownloadStore } from '../downloadStore'
+
+const FILE = 'Tiny-Model-Q4_K_M.gguf'
+const done = (filename: string) => ({ progress: 100, total: 100, speed: 0, filename, status: 'complete' })
+const running = (filename: string) => ({ progress: 10, total: 100, speed: 5, filename, status: 'downloading' })
+const rows = () => useDownloadStore.getState().downloads
+
+beforeEach(() => {
+ useDownloadStore.getState().stopPolling()
+ useDownloadStore.setState({ downloads: {}, ownRows: {}, cancelled: [], dismissed: [], orphans: {}, bundleMap: {} })
+ io.clear.mockClear()
+ io.rows = { [FILE]: done(FILE) }
+})
+
+describe('a finished download the user cleared', () => {
+ it('THE REPORT: stays gone through the next poll and the Models mount refresh', async () => {
+ await useDownloadStore.getState().refresh()
+ expect(rows()[FILE]?.status).toBe('complete')
+
+ useDownloadStore.getState().dismiss(FILE)
+ expect(rows()[FILE]).toBeUndefined()
+
+ await useDownloadStore.getState().refresh()
+ await useDownloadStore.getState().refresh()
+ expect(rows()[FILE]).toBeUndefined()
+ })
+
+ it('does not announce the finished file again on every poll', async () => {
+ await useDownloadStore.getState().refresh()
+ useDownloadStore.getState().dismiss(FILE)
+ const heard: string[] = []
+ const listen = (e: Event) => heard.push((e as CustomEvent<{ filename: string }>).detail.filename)
+ window.addEventListener('comfyui-model-downloaded', listen)
+ try {
+ await useDownloadStore.getState().refresh()
+ await useDownloadStore.getState().refresh()
+ } finally {
+ window.removeEventListener('comfyui-model-downloaded', listen)
+ }
+ expect(heard).toEqual([])
+ })
+
+ it('shows again when the same file is downloaded anew', async () => {
+ await useDownloadStore.getState().refresh()
+ useDownloadStore.getState().dismiss(FILE)
+
+ useDownloadStore.getState().setMeta(FILE, 'https://huggingface.co/x/y/resolve/main/' + FILE, 'gguf', '/models')
+ io.rows = { [FILE]: running(FILE) }
+ await useDownloadStore.getState().refresh()
+ expect(rows()[FILE]?.status).toBe('downloading')
+
+ io.rows = { [FILE]: done(FILE) }
+ await useDownloadStore.getState().refresh()
+ expect(rows()[FILE]?.status).toBe('complete')
+ })
+
+ it('a running download started elsewhere for that file shows even without a new start here', async () => {
+ await useDownloadStore.getState().refresh()
+ useDownloadStore.getState().dismiss(FILE)
+ io.rows = { [FILE]: running(FILE) }
+ await useDownloadStore.getState().refresh()
+ expect(rows()[FILE]?.status).toBe('downloading')
+ })
+
+ it('other finished rows are not hidden', async () => {
+ const OTHER = 'Other-Model-Q4_K_M.gguf'
+ io.rows = { [FILE]: done(FILE), [OTHER]: done(OTHER) }
+ await useDownloadStore.getState().refresh()
+ useDownloadStore.getState().dismiss(FILE)
+ await useDownloadStore.getState().refresh()
+ expect(Object.keys(rows())).toEqual([OTHER])
+ })
+})
diff --git a/src/stores/downloadStore.ts b/src/stores/downloadStore.ts
index 70ad9169..e9abe5dc 100644
--- a/src/stores/downloadStore.ts
+++ b/src/stores/downloadStore.ts
@@ -172,6 +172,11 @@ interface DownloadStoreState {
* with their bundle, so a bundle with cancelled files never reads as
* complete (lib/download-tray). This session only. */
cancelled: string[]
+ /** Finished files the user cleared from the badge. Rust keeps finished
+ * entries in its map, so without this list the next poll brought the row
+ * straight back. A new start of the same file takes it off the list. This
+ * session only. */
+ dismissed: string[]
polling: boolean
pollInterval: ReturnType<typeof setInterval> | null
pollCount: number
@@ -292,6 +297,7 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
bundleMap: {},
orphans: {},
cancelled: [],
+ dismissed: [],
polling: false,
pollInterval: null,
@@ -299,8 +305,12 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
refresh: async () => {
try {
- const prog = await getDownloadProgress()
+ const raw = await getDownloadProgress()
const prev = get().downloads
+ // A finished row the user cleared stays cleared. An entry that is no
+ // longer finished is a new run of that file and shows again.
+ const dismissed = get().dismissed.filter((id) => raw[id]?.status === 'complete')
+ const prog = Object.fromEntries(Object.entries(raw).filter(([id]) => !dismissed.includes(id)))
// Detect newly completed downloads and dispatch event. The filename
// rides along now so a listener can tell WHICH model arrived; every
@@ -326,6 +336,7 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
set({
downloads: { ...orphanRows(stillOrphaned, downloadMeta), ...ownRows, ...prog },
orphans: stillOrphaned,
+ dismissed,
pollCount: count,
})
@@ -374,7 +385,12 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
// Every start goes through here first, so a file that is started
// again stops counting as cancelled, and what this side said about
// it before (already there, not listed) is no longer the news.
- return { downloadMeta: next, cancelled: s.cancelled.filter((f) => f !== filename), ownRows: without(s.ownRows, filename) }
+ return {
+ downloadMeta: next,
+ cancelled: s.cancelled.filter((f) => f !== filename),
+ dismissed: s.dismissed.filter((f) => f !== filename),
+ ownRows: without(s.ownRows, filename),
+ }
})
},
@@ -582,11 +598,14 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
// The phone shell clears a finished row for good: its list polls again on
// every visit, and a row the backend still holds came back a second after
// it was cleared. The desktop badge keeps dismissing finished rows on this
- // side only, as before.
- if (status === 'complete' && isMobileHost()) {
+ // side only, as before, and remembers them so the next poll of the Rust
+ // map does not bring them back.
+ const remember = status === 'complete' && !isMobileHost()
+ if (status === 'complete' && !remember) {
clearDownloadEntry(id).catch(() => { /* app restart clears it anyway */ })
}
set(s => ({
+ dismissed: remember && !s.dismissed.includes(id) ? [...s.dismissed, id] : s.dismissed,
downloads: without(s.downloads, id),
ownRows: without(s.ownRows, id),
orphans: withoutFilename(s.orphans, id),