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 cancel leaves its summary, a bundle checks the drive, a loaded node pack is left alone

purplea898a3858980
diff --git a/src-tauri/src/commands/download.rs b/src-tauri/src/commands/download.rs
index 8d2c43f5..f8d43d19 100644
--- a/src-tauri/src/commands/download.rs
+++ b/src-tauri/src/commands/download.rs
@@ -1181,14 +1181,42 @@ const SPACE_RESERVE: u64 = 1024 * 1024 * 1024;
/// download big enough to fill a disk, so the check belongs here, where every
/// download passes through, not in the caller that happens to know the sizes.
fn space_shortfall(total: u64, already_on_disk: u64, available: Option<u64>) -> Option<(u64, u64)> {
+ space_shortfall_keeping(total, already_on_disk, available, SPACE_RESERVE)
+}
+
+/// `space_shortfall` with the headroom named by the caller.
+fn space_shortfall_keeping(total: u64, already_on_disk: u64, available: Option<u64>, reserve: u64) -> Option<(u64, u64)> {
let available = available?;
if total == 0 {
return None;
}
- let needed = total.saturating_sub(already_on_disk).saturating_add(SPACE_RESERVE);
+ let needed = total.saturating_sub(already_on_disk).saturating_add(reserve);
if available >= needed { None } else { Some((needed, available)) }
}
+/// Headroom a whole bundle leaves free. Twice the single file's: a bundle is
+/// tens of gigabytes in several transfers, and its plan is made from catalog
+/// sizes before any server has stated a length (the box, 03.10.2026: 27.1 GB
+/// started onto 29.6 GB free without a word).
+const BUNDLE_SPACE_RESERVE: u64 = 2 * 1024 * 1024 * 1024;
+
+/// What the user is told when a bundle does not fit: how much is missing
+/// first, then the three numbers it comes from.
+fn bundle_space_message(required: u64, reserved: u64, needed: u64, free: u64) -> String {
+ format!(
+ "Not enough free space: {} short. The download is {}, LU keeps {} of the drive free, and the drive has {} free.{} Free up some space and start it again.",
+ gib(needed.saturating_sub(free)),
+ gib(required),
+ gib(BUNDLE_SPACE_RESERVE),
+ gib(free),
+ if reserved > 0 {
+ format!(" Another {} is already promised to downloads that are still running.", gib(reserved))
+ } else {
+ String::new()
+ },
+ )
+}
+
/// Free bytes on the drive that holds `dest`. The longest matching mount point
/// wins, so a model folder on a mounted volume is measured against that volume
/// and not against the root it hangs under.
@@ -1874,7 +1902,7 @@ pub async fn check_download_space(
.map(|dl| reserved_bytes(&dl))
.unwrap_or(0);
let available = available_space_for(&dir);
- let shortfall = space_shortfall(requiredBytes.saturating_add(reserved), 0, available);
+ let shortfall = space_shortfall_keeping(requiredBytes.saturating_add(reserved), 0, available, BUNDLE_SPACE_RESERVE);
Ok(match shortfall {
None => serde_json::json!({
@@ -1888,16 +1916,7 @@ pub async fn check_download_space(
"requiredBytes": requiredBytes,
"reservedBytes": reserved,
"availableBytes": available,
- "message": format!(
- "Not enough free space. This needs {} and the drive has {} free.{} Free up some space and start it again.",
- gib(needed),
- gib(free),
- if reserved > 0 {
- format!(" {} of that is already promised to downloads that are still running.", gib(reserved))
- } else {
- String::new()
- },
- ),
+ "message": bundle_space_message(requiredBytes, reserved, needed, free),
}),
})
}
@@ -2786,6 +2805,30 @@ mod tests {
assert!(space_shortfall(modell, 0, Some(modell)).is_some());
}
+ #[test]
+ fn a_bundle_keeps_two_gigabytes_free_and_says_how_much_is_missing() {
+ const GIB: u64 = 1024 * 1024 * 1024;
+ // The box, 03.10.2026: 27.1 GB to fetch, 29.6 GB free. That fits, and
+ // it still does with the larger reserve.
+ let ltx: u64 = 29_066_057_328;
+ assert!(space_shortfall_keeping(ltx, 0, Some(31_782_000_000), BUNDLE_SPACE_RESERVE).is_none());
+ // One gigabyte less free and the single file's reserve would still let
+ // it start; the bundle's does not.
+ let free = ltx + GIB + GIB / 2;
+ assert!(space_shortfall(ltx, 0, Some(free)).is_none());
+ let (needed, got) = space_shortfall_keeping(ltx, 0, Some(free), BUNDLE_SPACE_RESERVE).expect("too tight for a bundle");
+ assert_eq!(needed, ltx + 2 * GIB);
+ let message = bundle_space_message(ltx, 0, needed, got);
+ assert!(message.starts_with("Not enough free space: 0.5 GB short."), "{message}");
+ assert!(message.contains("The download is 27.1 GB"), "{message}");
+ assert!(message.contains("keeps 2.0 GB of the drive free"), "{message}");
+ assert!(!message.contains("promised"), "{message}");
+ // Transfers still running are named, because their bytes are why.
+ let busy = bundle_space_message(ltx, 4 * GIB, needed + 4 * GIB, got);
+ assert!(busy.contains("Another 4.0 GB is already promised"), "{busy}");
+ assert!(busy.starts_with("Not enough free space: 4.5 GB short."), "{busy}");
+ }
+
#[test]
fn what_already_lies_on_disk_does_not_have_to_fit_twice() {
// Fortsetzung: 12 GB von 16,3 GB liegen schon, es fehlen 4,3 GB.
diff --git a/src/api/__tests__/a-loaded-node-pack-is-not-installed-again.test.ts b/src/api/__tests__/a-loaded-node-pack-is-not-installed-again.test.ts
new file mode 100644
index 00000000..fdeb84bc
--- /dev/null
+++ b/src/api/__tests__/a-loaded-node-pack-is-not-installed-again.test.ts
@@ -0,0 +1,137 @@
+/**
+ * The box, 03.10.2026: a click on Get for "LTX 2.5 · Small (GGUF Q4)" pulled
+ * ComfyUI-GGUF again and restarted ComfyUI, with the pack loaded all along
+ * (the restart showed in the process start time, nowhere on the surface). A
+ * pack whose nodes the running ComfyUI lists is neither installed nor does it
+ * cost a restart. One that is not loaded still is.
+ *
+ * Run: npx vitest run src/api/__tests__/a-loaded-node-pack-is-not-installed-again.test.ts
+ */
+import { describe, it, expect, vi, beforeEach, beforeAll } from 'vitest'
+import type { ModelBundle } from '../discover'
+
+const backendCall = vi.fn<(cmd: string, args?: unknown) => Promise<unknown>>()
+const localFetch = vi.fn<(url: string, opts?: unknown) => Promise<Response>>()
+
+vi.mock('../backend', () => ({
+ backendCall: (...a: unknown[]) => backendCall(...(a as [string, unknown])),
+ localFetch: (...a: unknown[]) => localFetch(...(a as [string, unknown])),
+ comfyuiUrl: (p: string) => `http://localhost:8188${p}`,
+ fetchExternal: vi.fn(),
+ fetchLocalhostBytes: vi.fn(),
+ isTauri: () => true,
+}))
+
+import { installBundleComplete, nodePacksNotLoaded, assertBundleFits } from '../discover'
+import { clearNodeCache } from '../comfyui-nodes'
+
+let nodes: Record<string, unknown> = {}
+let objectInfoAnswers = true
+
+beforeAll(() => {
+ ;(globalThis as unknown as { window: EventTarget }).window = new EventTarget()
+})
+
+beforeEach(() => {
+ clearNodeCache()
+ objectInfoAnswers = true
+ nodes = { UnetLoaderGGUF: { input: { required: {} }, output: [] } }
+ backendCall.mockReset().mockImplementation(async (cmd: string) => {
+ if (cmd === 'check_model_sizes') return []
+ if (cmd === 'check_download_space') return { fits: true }
+ if (cmd === 'download_model') return { status: 'started', id: '1' }
+ return { status: 'installed' }
+ })
+ localFetch.mockReset().mockImplementation(async (url: string) => {
+ if (url.endsWith('/object_info')) {
+ return objectInfoAnswers
+ ? new Response(JSON.stringify(nodes), { status: 200 })
+ : new Response('down', { status: 503 })
+ }
+ if (url.endsWith('/system_stats')) return new Response('{}', { status: 503 })
+ return new Response('{}', { status: 200 })
+ })
+})
+
+const bundle = (): ModelBundle => ({
+ name: 'LTX 2.5 · Small (GGUF Q4)',
+ description: '', tags: [], totalSizeGB: 1, vramRequired: '16 GB',
+ customNodes: ['gguf'],
+ files: [{
+ name: '', description: '', pulls: '', tags: [], updated: '',
+ downloadUrl: 'https://example.test/m.gguf', filename: 'm.gguf', subfolder: 'diffusion_models', sizeGB: 1,
+ }],
+} as unknown as ModelBundle)
+
+const commands = () => backendCall.mock.calls.map((c) => c[0])
+/** The node install runs beside the download on purpose; give it its turn. */
+const settle = () => new Promise((r) => setTimeout(r, 50))
+
+describe('nodePacksNotLoaded', () => {
+ it('leaves out a pack whose nodes ComfyUI lists', async () => {
+ expect(await nodePacksNotLoaded(['gguf'])).toEqual([])
+ })
+
+ it('keeps a pack that is missing one of its nodes', async () => {
+ expect(await nodePacksNotLoaded(['gguf', 'videohelpersuite'])).toEqual(['videohelpersuite'])
+ })
+
+ it('counts every pack as missing when ComfyUI does not answer', async () => {
+ objectInfoAnswers = false
+ expect(await nodePacksNotLoaded(['gguf'])).toEqual(['gguf'])
+ })
+})
+
+describe('a bundle download', () => {
+ it('with its node pack loaded: no install, and ComfyUI is not restarted', async () => {
+ await installBundleComplete(bundle())
+ await settle()
+ expect(commands()).toContain('download_model')
+ expect(commands()).not.toContain('install_custom_node')
+ expect(commands()).not.toContain('stop_comfyui')
+ expect(commands()).not.toContain('start_comfyui')
+ })
+
+ it('with its node pack not loaded: installs it and restarts, as before', async () => {
+ nodes = {}
+ await installBundleComplete(bundle())
+ await vi.waitFor(() => expect(commands()).toContain('start_comfyui'))
+ expect(commands()).toContain('install_custom_node')
+ }, 30_000)
+})
+
+// Same click, the other thing it has to settle first: the drive. The check
+// asks for the files that are still missing, and a refusal carries Rust's
+// sentence with the numbers and stops the install before anything starts.
+describe('the space check before a bundle download', () => {
+ const two = (): ModelBundle => ({
+ ...bundle(),
+ files: [
+ ...bundle().files,
+ { name: '', description: '', pulls: '', tags: [], updated: '', downloadUrl: 'https://example.test/v.safetensors', filename: 'v.safetensors', subfolder: 'vae', sizeGB: 0.5, sizeBytes: 500_000_000 },
+ ],
+ } as unknown as ModelBundle)
+ const spaceCalls = () => backendCall.mock.calls.filter((c) => c[0] === 'check_download_space').map((c) => c[1])
+
+ it('asks for the missing files only, in their exact bytes', async () => {
+ await assertBundleFits(two(), new Set(['m.gguf']))
+ expect(spaceCalls()).toEqual([{ subfolder: 'vae', destDir: null, requiredBytes: 500_000_000 }])
+ })
+
+ it('asks nothing when everything is there', async () => {
+ await assertBundleFits(two(), new Set(['m.gguf', 'v.safetensors']))
+ expect(spaceCalls()).toEqual([])
+ })
+
+ it('a bundle that does not fit starts no download and says how much is short', async () => {
+ const SHORT = 'Not enough free space: 0.5 GB short. The download is 27.1 GB, LU keeps 2.0 GB of the drive free, and the drive has 28.6 GB free. Free up some space and start it again.'
+ backendCall.mockImplementation(async (cmd: string) => {
+ if (cmd === 'check_model_sizes') return []
+ if (cmd === 'check_download_space') return { fits: false, message: SHORT }
+ return { status: 'installed' }
+ })
+ await expect(installBundleComplete(two())).rejects.toThrow(SHORT)
+ expect(commands()).not.toContain('download_model')
+ expect(commands()).not.toContain('install_custom_node')
+ })
+})
diff --git a/src/api/discover.ts b/src/api/discover.ts
index 4ebd40b4..40181e97 100644
--- a/src/api/discover.ts
+++ b/src/api/discover.ts
@@ -688,6 +688,49 @@ async function runVisibilityConfirmation(filename: string): Promise<void> {
}
}
+/**
+ * ONE space check for the whole bundle, before the first byte moves.
+ *
+ * Every file starts its own transfer and every transfer checked the free
+ * space on its own, so a four file bundle passed the same free bytes four
+ * times over and then filled the drive between them. The sum is the only
+ * honest question, and it has to be asked before anything starts: refusing
+ * file three after files one and two have written 20 GB helps nobody. Throws
+ * with the numbers (how much is short, the download, the free space) when the
+ * missing files plus the reserve do not fit.
+ */
+export async function assertBundleFits(bundle: ModelBundle, installed: ReadonlySet<string>): Promise<void> {
+ const pending = bundleBytesToFetch(bundle, installed)
+ if (pending.bytes <= 0 || !pending.subfolder) return
+ const verdict = await checkDownloadSpace({ subfolder: pending.subfolder }, pending.bytes)
+ if (verdict && !verdict.fits) {
+ throw new Error(verdict.message || `${bundle.name} does not fit on this drive.`)
+ }
+}
+
+/**
+ * The node packs of `keys` the running ComfyUI has not loaded.
+ *
+ * The box, 03.10.2026: a click on Get for a GGUF bundle pulled ComfyUI-GGUF
+ * again and restarted ComfyUI, with the pack loaded all along and nothing on
+ * the surface saying so. A pack whose nodes are registered needs neither. One
+ * that is on disk and failed to import is not loaded, so it still gets the
+ * install that heals it. With ComfyUI not answering nobody can tell, and
+ * every pack counts as missing, as before.
+ */
+export async function nodePacksNotLoaded(keys: string[]): Promise<string[]> {
+ let registered: Set<string>
+ try {
+ registered = new Set(Object.keys(await getAllNodeInfo()))
+ } catch {
+ return keys
+ }
+ return keys.filter((key) => {
+ const entry = CUSTOM_NODE_REGISTRY[key]
+ return !entry || !entry.requiredNodes.every((node) => registered.has(node))
+ })
+}
+
export async function installBundleComplete(bundle: ModelBundle): Promise<{ remote?: RemoteBundleReport }> {
const errors: string[] = []
// GH #143: a ComfyUI on another machine. The files land here for the user
@@ -759,20 +802,7 @@ export async function installBundleComplete(bundle: ModelBundle): Promise<{ remo
// it ran "lazily", which was not true, the request always goes out).
const judgeable = judgeableFolders()
- // ONE space check for the whole bundle, before the first byte moves.
- //
- // Every file starts its own transfer and every transfer checked the free
- // space on its own, so a four file bundle passed the same free bytes four
- // times over and then filled the drive between them. The sum is the only
- // honest question, and it has to be asked before anything starts: refusing
- // file three after files one and two have written 20 GB helps nobody.
- const pendingBytes = bundleBytesToFetch(bundle, installedFiles)
- if (pendingBytes.bytes > 0 && pendingBytes.subfolder) {
- const verdict = await checkDownloadSpace({ subfolder: pendingBytes.subfolder }, pendingBytes.bytes)
- if (verdict && !verdict.fits) {
- throw new Error(verdict.message || `${bundle.name} does not fit on this drive.`)
- }
- }
+ await assertBundleFits(bundle, installedFiles)
// Step 1: Start downloads only for files NOT already installed
for (const file of bundle.files) {
@@ -814,7 +844,10 @@ export async function installBundleComplete(bundle: ModelBundle): Promise<{ remo
// (T-67), and its restart was a hand-rolled sleep that could not tell a
// ComfyUI LU owns from one it does not.
if (bundle.customNodes && bundle.customNodes.length > 0 && !target.remote) {
- void installCustomNodes([...bundle.customNodes], { keepGoing: true, restart: true })
+ // Only the packs ComfyUI has not loaded: installing one that is there
+ // restarts ComfyUI for nothing (nodePacksNotLoaded).
+ void nodePacksNotLoaded([...bundle.customNodes])
+ .then((missing) => (missing.length > 0 ? installCustomNodes(missing, { keepGoing: true, restart: true }) : undefined))
.catch((err) => log.warn('[discover] Custom node install/restart failed', { err }))
}
diff --git a/src/components/create/experimental/CreateContext.tsx b/src/components/create/experimental/CreateContext.tsx
index 3f2f6815..3ffb4012 100644
--- a/src/components/create/experimental/CreateContext.tsx
+++ b/src/components/create/experimental/CreateContext.tsx
@@ -5,7 +5,7 @@ import { useCloudSession } from '../../../hooks/useCloudSession'
import { useCreateStore, type GalleryItem } from '../../../stores/createStore'
import { listedLoras, getVAEModels, checkComfyConnection, refreshComfyModels, bundleForVideoIntent } from '../../../api/comfyui'
import { getAllNodeInfo, clearNodeCache } from '../../../api/comfyui-nodes'
-import { installCustomNodes, getImageBundles, getVideoBundles, getAudioBundles, getLipsyncBundles, getMotionBundles, startModelDownload, getDownloadProgress, modelsNotVisibleInComfy, judgeableFolders } from '../../../api/discover'
+import { installCustomNodes, nodePacksNotLoaded, assertBundleFits, checkBundlesOnDisk, getImageBundles, getVideoBundles, getAudioBundles, getLipsyncBundles, getMotionBundles, startModelDownload, getDownloadProgress, modelsNotVisibleInComfy, judgeableFolders } from '../../../api/discover'
import { CUSTOM_NODE_REGISTRY } from '../../../api/model-bundles'
import { backendCall, isMacOS, isLinux } from '../../../api/backend'
import { asComfyGpuMode, comfyCpuBannerText, type ComfyCpuBannerFacts } from '../../../lib/comfy-cpu-banner'
@@ -448,9 +448,15 @@ export function CreateExpProvider({ children }: { children: ReactNode }) {
: getMotionBundles()
)[0]
if (!bundle) throw new Error('No starter bundle available for this intent.')
- if (bundle.customNodes?.length) {
+ // Before anything is installed or restarted: does what is still missing
+ // fit on the drive at all.
+ await assertBundleFits(bundle, (await checkBundlesOnDisk([bundle])).files)
+ // Only the packs ComfyUI has not loaded. With all of them there this used
+ // to pull them again and restart ComfyUI for nothing.
+ const packs = await nodePacksNotLoaded(bundle.customNodes ?? [])
+ if (packs.length > 0) {
onProgress?.('Installing the required node packs. This can take a minute…')
- await installCustomNodes(bundle.customNodes)
+ await installCustomNodes(packs)
onProgress?.('Restarting ComfyUI to register the new nodes…')
await restartComfyForNewNodes()
for (let i = 0; i < 20; i++) {
diff --git a/src/components/layout/DownloadBadge.tsx b/src/components/layout/DownloadBadge.tsx
index 82513cb4..ed13865e 100644
--- a/src/components/layout/DownloadBadge.tsx
+++ b/src/components/layout/DownloadBadge.tsx
@@ -62,7 +62,12 @@ export function DownloadBadge() {
}, [])
const totalActive = textActiveCount + comfyActiveCount + mlxActiveCount
- const hasAny = textEntries.length > 0 || comfyEntries.length > 0 || mlxEntries.length > 0
+ // A cancelled file has no row and still has something to say: its bundle is
+ // listed until the user closes it, so the tray does not shut itself (and
+ // then read "No active downloads") the moment the last transfer is stopped.
+ const cancelledShown = comfyBundles.reduce((n, b) => n + b.cancelled.length, 0)
+ const listed = textEntries.length + comfyEntries.length + mlxEntries.length + cancelledShown
+ const hasAny = listed > 0
// Click outside to close
useEffect(() => {
@@ -143,7 +148,7 @@ export function DownloadBadge() {
{/* Header */}
<div className="flex items-center justify-between px-3 pt-2.5 pb-1">
<span className="text-[0.65rem] font-semibold uppercase tracking-widest text-gray-500">
- Downloads {hasAny && `(${textEntries.length + comfyEntries.length + mlxEntries.length})`}
+ Downloads {hasAny && `(${listed})`}
</span>
{(textEntries.some(([, s]) => s.complete) || comfyEntries.some(([, d]) => d.status === 'complete') || mlxEntries.some(e => e.status === 'complete')) && (
<button
@@ -279,7 +284,7 @@ export function DownloadBadge() {
// missing, and its card offers the download again.
<>
<p className={`t-micro ${HINWEIS_TEXT.ruhig}`}>{verdict.line}</p>
- <div className="mt-1.5 space-y-0.5">
+ {isBundle && <div className="mt-1.5 space-y-0.5">
{files.map(({ id, d }) => (
<div key={id} className="flex items-center justify-between t-micro text-gray-500">
<span className="truncate flex-1 font-mono">{d.filename || id}</span>
@@ -292,7 +297,7 @@ export function DownloadBadge() {
<span className="shrink-0 ml-2">Cancelled</span>
</div>
))}
- </div>
+ </div>}
</>
) : (
<>
diff --git a/src/components/layout/__tests__/DownloadBadge-autoclose.test.ts b/src/components/layout/__tests__/DownloadBadge-autoclose.test.ts
index 66135042..5d1e0ba1 100644
--- a/src/components/layout/__tests__/DownloadBadge-autoclose.test.ts
+++ b/src/components/layout/__tests__/DownloadBadge-autoclose.test.ts
@@ -48,6 +48,15 @@ describe('DownloadBadge tray auto-close', () => {
expect(src).not.toMatch(/autoOpened/)
})
+ it('counts a cancelled bundle as something to show, so a cancel does not shut the tray', () => {
+ // The box, 03.10.2026: "Cancel all" removed the last row, `any` went
+ // false, and the tray that had opened itself closed on the spot. The
+ // cancelled files are listed (lib/download-tray) and count here.
+ expect(src).toMatch(/const cancelledShown = comfyBundles\.reduce\(\(n, b\) => n \+ b\.cancelled\.length, 0\)/)
+ expect(src).toMatch(/const listed = textEntries\.length \+ comfyEntries\.length \+ mlxEntries\.length \+ cancelledShown/)
+ expect(src).toMatch(/const hasAny = listed > 0/)
+ })
+
it('leaves a hand-opened tray alone', () => {
// Clicking the trigger drops the flag, so the close branch skips it.
expect(src).toMatch(/onClick=\{\(\) => setTray\(\{ open: !open, auto: false \}\)\}/)
diff --git a/src/lib/__tests__/download-tray-cancelled-bundle.test.ts b/src/lib/__tests__/download-tray-cancelled-bundle.test.ts
index b022b3e9..79d44c8a 100644
--- a/src/lib/__tests__/download-tray-cancelled-bundle.test.ts
+++ b/src/lib/__tests__/download-tray-cancelled-bundle.test.ts
@@ -50,8 +50,25 @@ describe('a bundle with cancelled files', () => {
expect(bundleVerdict(group).state).toBe('running')
})
- it('a bundle with nothing left but cancelled files has no row at all', () => {
- expect(trayBundles({}, bundleMap, FILES)).toEqual([])
+ // The box, 03.10.2026, second finding: with every running file cancelled
+ // the bundle had no row, so the tray shut itself and read "No active
+ // downloads" when opened again. The summary stays until it is cleared.
+ it('a bundle with nothing left but cancelled files is still listed, and says so', () => {
+ const [group] = trayBundles({}, bundleMap, FILES.slice(0, 3))
+ expect(group.name).toBe(LTX)
+ expect(group.files).toEqual([])
+ expect(group.cancelled).toEqual(FILES.slice(0, 3))
+ expect(bundleVerdict(group)).toEqual({ state: 'partial', line: 'Cancelled, 3 files not downloaded' })
+ })
+
+ it('a single cancelled file outside any bundle is listed under its own name', () => {
+ const [group] = trayBundles({}, {}, ['lora.safetensors'])
+ expect(group.name).toBe('lora.safetensors')
+ expect(bundleVerdict(group)).toEqual({ state: 'partial', line: 'Cancelled, 1 file not downloaded' })
+ })
+
+ it('nothing cancelled and no rows: nothing listed', () => {
+ expect(trayBundles({}, bundleMap, [])).toEqual([])
})
it('a single file outside any bundle keeps its own row', () => {
diff --git a/src/lib/download-tray.ts b/src/lib/download-tray.ts
index 56b76e05..9de645f5 100644
--- a/src/lib/download-tray.ts
+++ b/src/lib/download-tray.ts
@@ -89,9 +89,13 @@ export interface TrayBundle<R extends TrayRow> {
* three running files, the two finished rows were all that was left of it, and
* "every row is complete" turned the group into "Complete (2 files)" with a
* green check. A cancelled file has no row, so the group has to be told about
- * it. A file that has a row again (started once more) is not cancelled, and a
- * bundle with nothing but cancelled files is not listed: there is nothing to
- * show, and its card offers the download again.
+ * it. A file that has a row again (started once more) is not cancelled.
+ *
+ * A bundle with nothing but cancelled files is listed too. It used not to be
+ * ("there is nothing to show"), and that was the next thing the box found:
+ * after "Cancel all" the last row was gone, the tray shut itself the same
+ * moment and read "No active downloads" when opened again, without a word
+ * about the cancel. The summary stays until the user closes it.
*/
export function trayBundles<R extends TrayRow>(
rows: Record<string, R>,
@@ -106,7 +110,9 @@ export function trayBundles<R extends TrayRow>(
}
for (const id of cancelled) {
if (rows[id]) continue
- groups.get(bundleMap[id] || id)?.cancelled.push(id)
+ const name = bundleMap[id] || id
+ if (!groups.has(name)) groups.set(name, { name, files: [], cancelled: [] })
+ groups.get(name)!.cancelled.push(id)
}
return [...groups.values()]
}
@@ -117,6 +123,7 @@ export function bundleVerdict(bundle: TrayBundle<TrayRow>): { state: 'complete'
const done = bundle.files.filter((f) => f.d.status === 'complete').length
if (done < bundle.files.length) return { state: 'running', line: '' }
if (bundle.cancelled.length === 0) return { state: 'complete', line: `Complete (${countLabel(done, 'file')})` }
+ if (done === 0) return { state: 'partial', line: `Cancelled, ${countLabel(bundle.cancelled.length, 'file')} not downloaded` }
const total = done + bundle.cancelled.length
return { state: 'partial', line: `${done} of ${countLabel(total, 'file')} downloaded, ${bundle.cancelled.length} cancelled` }
}
diff --git a/src/stores/__tests__/downloadStore-own-rows-survive-the-poll.test.ts b/src/stores/__tests__/downloadStore-own-rows-survive-the-poll.test.ts
new file mode 100644
index 00000000..699a0d41
--- /dev/null
+++ b/src/stores/__tests__/downloadStore-own-rows-survive-the-poll.test.ts
@@ -0,0 +1,81 @@
+/**
+ * The box, 03.10.2026: a bundle of five files, two of them on disk already.
+ * The install marks those two as there, and one second later the poll took
+ * Rust's list (three running transfers) as the whole picture and wiped them.
+ * The tray showed three files, and after "Cancel all" nothing at all. Rows
+ * this side wrote itself survive the poll, under whatever Rust reports.
+ *
+ * Run: npx vitest run src/stores/__tests__/downloadStore-own-rows-survive-the-poll.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+
+const progress = vi.hoisted(() => ({ rows: {} as Record<string, unknown> }))
+
+vi.mock('../../api/discover', async () => {
+ const actual = await vi.importActual<typeof import('../../api/discover')>('../../api/discover')
+ return {
+ ...actual,
+ getDownloadProgress: vi.fn(async () => progress.rows),
+ cancelDownload: vi.fn(async () => {}),
+ clearDownloadEntry: vi.fn(async () => {}),
+ }
+})
+
+import { useDownloadStore } from '../downloadStore'
+import { trayBundles, bundleVerdict } from '../../lib/download-tray'
+
+const LTX = 'LTX 2.5 · Small (GGUF Q4)'
+const THERE = ['audio-vae.safetensors', 'upscaler.safetensors']
+const RUNNING = ['transformer.gguf', 'text-encoder.safetensors', 'video-vae.safetensors']
+const running = (filename: string) => ({ progress: 10, total: 1000, speed: 5, filename, status: 'downloading' })
+
+beforeEach(() => {
+ useDownloadStore.getState().stopPolling()
+ useDownloadStore.setState({ downloads: {}, ownRows: {}, cancelled: [], orphans: {}, bundleMap: {} })
+ useDownloadStore.getState().setBundleGroup(LTX, [...THERE, ...RUNNING])
+ progress.rows = Object.fromEntries(RUNNING.map((f) => [f, running(f)]))
+})
+
+const tray = () => {
+ const s = useDownloadStore.getState()
+ return trayBundles(s.downloads, s.bundleMap, s.cancelled)
+}
+
+describe('a file that was already there', () => {
+ it('keeps its row through the poll, next to the running transfers', async () => {
+ for (const f of THERE) useDownloadStore.getState().markComplete(f)
+ await useDownloadStore.getState().refresh()
+ const rows = useDownloadStore.getState().downloads
+ expect(Object.keys(rows).sort()).toEqual([...THERE, ...RUNNING].sort())
+ expect(THERE.map((f) => rows[f].status)).toEqual(['complete', 'complete'])
+ })
+
+ it('after "Cancel all" the bundle reads 2 of 5 files downloaded, 3 cancelled', async () => {
+ for (const f of THERE) useDownloadStore.getState().markComplete(f)
+ await useDownloadStore.getState().refresh()
+ for (const f of [...THERE, ...RUNNING]) await useDownloadStore.getState().cancel(f)
+ progress.rows = {}
+ await useDownloadStore.getState().refresh()
+ const [group] = tray()
+ expect(group.name).toBe(LTX)
+ expect(bundleVerdict(group)).toEqual({ state: 'partial', line: '2 of 5 files downloaded, 3 cancelled' })
+ })
+
+ it('goes when the user clears it, and the poll does not bring it back', async () => {
+ useDownloadStore.getState().markComplete(THERE[0])
+ useDownloadStore.getState().dismiss(THERE[0])
+ await useDownloadStore.getState().refresh()
+ expect(useDownloadStore.getState().downloads[THERE[0]]).toBeUndefined()
+ })
+
+ it('gives way to what Rust reports once the file is started again', async () => {
+ useDownloadStore.getState().markInvisible(RUNNING[0])
+ expect(useDownloadStore.getState().downloads[RUNNING[0]].status).toBe('error')
+ useDownloadStore.getState().setMeta(RUNNING[0], 'https://example.com/t.gguf', 'diffusion_models')
+ await useDownloadStore.getState().refresh()
+ expect(useDownloadStore.getState().downloads[RUNNING[0]].status).toBe('downloading')
+ progress.rows = {}
+ await useDownloadStore.getState().refresh()
+ expect(useDownloadStore.getState().downloads[RUNNING[0]]).toBeUndefined()
+ })
+})
diff --git a/src/stores/downloadStore.ts b/src/stores/downloadStore.ts
index 9c445abd..ce25687d 100644
--- a/src/stores/downloadStore.ts
+++ b/src/stores/downloadStore.ts
@@ -117,6 +117,12 @@ export interface OrphanEntry extends OrphanDownload {
interface DownloadStoreState {
downloads: Record<string, DownloadProgress>
+ /** Rows this side wrote itself: a bundle file that was on disk already, a
+ * file ComfyUI does not list. Rust has no entry for them, so a poll that
+ * takes Rust's list as the whole picture wiped them a second later, and a
+ * bundle of five showed three files (the box, 03.10.2026). They are merged
+ * under Rust's rows and go when the user clears, cancels or restarts them. */
+ ownRows: Record<string, DownloadProgress>
downloadMeta: Record<string, DownloadMeta>
bundleMap: BundleMap // filename → bundle name
/** Partials found on disk with no transfer behind them, keyed by stem. */
@@ -232,6 +238,7 @@ const META_LIMIT = 400
export const useDownloadStore = create<DownloadStoreState>()(persist((set, get) => ({
downloads: {},
+ ownRows: {},
downloadMeta: {},
bundleMap: {},
orphans: {},
@@ -263,12 +270,12 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
// Rust owns the live rows; an adopted orphan only fills a gap Rust has
// nothing for. The moment a resume starts, the real entry takes over and
// the orphan stops being one.
- const { orphans, downloadMeta } = get()
+ const { orphans, downloadMeta, ownRows } = get()
const stillOrphaned = Object.fromEntries(
Object.entries(orphans).filter(([, o]) => !o.filename || !prog[o.filename]),
)
set({
- downloads: { ...orphanRows(stillOrphaned, downloadMeta), ...prog },
+ downloads: { ...orphanRows(stillOrphaned, downloadMeta), ...ownRows, ...prog },
orphans: stillOrphaned,
pollCount: count,
})
@@ -316,8 +323,9 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
for (const k of keys.slice(0, keys.length - META_LIMIT)) delete next[k]
}
// Every start goes through here first, so a file that is started
- // again stops counting as cancelled.
- return { downloadMeta: next, cancelled: s.cancelled.filter((f) => f !== filename) }
+ // 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) }
})
},
@@ -330,23 +338,21 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
},
markComplete: (filename: string) => {
+ const row: DownloadProgress = { progress: 1, total: 1, speed: 0, filename, status: 'complete' }
set(s => ({
- downloads: {
- ...s.downloads,
- [filename]: { progress: 1, total: 1, speed: 0, filename, status: 'complete' },
- },
+ downloads: { ...s.downloads, [filename]: row },
+ ownRows: { ...s.ownRows, [filename]: row },
}))
},
markInvisible: (filename: string) => {
+ const row: DownloadProgress = {
+ progress: 0, total: 0, speed: 0, filename, status: 'error',
+ error: invisibleFileMessage(filename),
+ }
set(s => ({
- downloads: {
- ...s.downloads,
- [filename]: {
- progress: 0, total: 0, speed: 0, filename, status: 'error',
- error: invisibleFileMessage(filename),
- },
- },
+ downloads: { ...s.downloads, [filename]: row },
+ ownRows: { ...s.ownRows, [filename]: row },
}))
},
@@ -369,6 +375,7 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
// the row the user just cancelled.
return {
downloads: updated,
+ ownRows: without(s.ownRows, id),
orphans: withoutFilename(s.orphans, id),
cancelled: s.cancelled.includes(id) ? s.cancelled : [...s.cancelled, id],
}
@@ -416,11 +423,11 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
if (current?.status === 'error') {
await clearDownloadEntry(id).catch(() => { /* best effort — a restart clears it */ })
}
- set(s => {
- const updated = { ...s.downloads }
- delete updated[id]
- return { downloads: updated, orphans: withoutFilename(s.orphans, id) }
- })
+ set(s => ({
+ downloads: without(s.downloads, id),
+ ownRows: without(s.ownRows, id),
+ orphans: withoutFilename(s.orphans, id),
+ }))
// Re-start the download — use path-based for GGUF text models, subfolder-based for ComfyUI
if (meta.destDir) {
await startModelDownloadToPath(meta.url, meta.destDir, id, meta.expectedBytes, meta.sha256)
@@ -444,11 +451,11 @@ export const useDownloadStore = create<DownloadStoreState>()(persist((set, get)
if (get().downloads[id]?.status === 'error') {
clearDownloadEntry(id).catch(() => { /* app restart clears it anyway */ })
}
- set(s => {
- const updated = { ...s.downloads }
- delete updated[id]
- return { downloads: updated, orphans: withoutFilename(s.orphans, id) }
- })
+ set(s => ({
+ downloads: without(s.downloads, id),
+ ownRows: without(s.ownRows, id),
+ orphans: withoutFilename(s.orphans, id),
+ }))
},
forgetCancelled: (ids: string[]) => {
@@ -590,6 +597,14 @@ function ensureMeta(get: () => DownloadStoreState, id: string): DownloadMeta | n
return meta
}
+/** `rows` without `id`; the same object when `id` is not in it. */
+function without<T>(rows: Record<string, T>, id: string): Record<string, T> {
+ if (!(id in rows)) return rows
+ const next = { ...rows }
+ delete next[id]
+ return next
+}
+
/** Drop the orphan that resolved to `filename`, whatever its stem was. */
function withoutFilename(
orphans: Record<string, OrphanEntry>,