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: partial download detection + 4 edge case fixes

PurpleDoubleD4ac2ab8a23c6
diff --git a/src-tauri/src/commands/download.rs b/src-tauri/src/commands/download.rs
index f5d03762..fb05d00e 100644
--- a/src-tauri/src/commands/download.rs
+++ b/src-tauri/src/commands/download.rs
@@ -27,6 +27,7 @@ pub async fn download_model(
url: String,
subfolder: String,
filename: String,
+ expected_bytes: Option<u64>,
state: State<'_, AppState>,
) -> Result<serde_json::Value, String> {
let comfy_path = {
@@ -44,7 +45,26 @@ pub async fn download_model(
let dest_file = dest_dir.join(&filename);
if dest_file.exists() {
- return Ok(serde_json::json!({"status": "exists", "path": dest_file.to_string_lossy()}));
+ // If expected_bytes is provided, verify the file is at least 90% of expected size
+ // to catch partially downloaded files
+ let file_complete = match expected_bytes {
+ Some(expected) if expected > 0 => {
+ let actual = dest_file.metadata().map(|m| m.len()).unwrap_or(0);
+ let threshold = (expected as f64 * 0.9) as u64;
+ let is_complete = actual >= threshold;
+ if !is_complete {
+ println!("[Download] File {} exists but is incomplete: {} bytes vs {} expected ({}%)",
+ filename, actual, expected, (actual as f64 / expected as f64 * 100.0) as u32);
+ }
+ is_complete
+ }
+ _ => true, // No expected size — trust existence (backward compat)
+ };
+
+ if file_complete {
+ return Ok(serde_json::json!({"status": "exists", "path": dest_file.to_string_lossy()}));
+ }
+ // File is incomplete — fall through to re-download (resume from partial)
}
// Use filename as ID (matches frontend lookup)
@@ -472,6 +492,7 @@ pub async fn download_model_to_path(
url: String,
dest_dir: String,
filename: String,
+ expected_bytes: Option<u64>,
state: State<'_, AppState>,
) -> Result<serde_json::Value, String> {
let dir = PathBuf::from(&dest_dir);
@@ -479,7 +500,17 @@ pub async fn download_model_to_path(
let dest_file = dir.join(&filename);
if dest_file.exists() {
- return Ok(serde_json::json!({"status": "exists", "path": dest_file.to_string_lossy()}));
+ let file_complete = match expected_bytes {
+ Some(expected) if expected > 0 => {
+ let actual = dest_file.metadata().map(|m| m.len()).unwrap_or(0);
+ let threshold = (expected as f64 * 0.9) as u64;
+ actual >= threshold
+ }
+ _ => true,
+ };
+ if file_complete {
+ return Ok(serde_json::json!({"status": "exists", "path": dest_file.to_string_lossy()}));
+ }
}
let id = filename.clone();
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rs
index 5533b1e6..016066fa 100644
--- a/src-tauri/src/commands/install.rs
+++ b/src-tauri/src/commands/install.rs
@@ -2,16 +2,10 @@ use std::fs;
use std::path::PathBuf;
use std::process::{Command, Stdio};
-#[cfg(target_os = "windows")]
-use std::os::windows::process::CommandExt;
-
use tauri::State;
use crate::state::AppState;
-#[cfg(target_os = "windows")]
-const CREATE_NO_WINDOW: u32 = 0x08000000;
-
#[tauri::command]
pub fn install_comfyui(
install_path: Option<String>,
diff --git a/src/api/discover.ts b/src/api/discover.ts
index e2a2868a..e17ef03c 100644
--- a/src/api/discover.ts
+++ b/src/api/discover.ts
@@ -34,8 +34,8 @@ export interface DownloadProgress {
// ─── Download API ───
-export async function startModelDownload(url: string, subfolder: string, filename: string): Promise<{ status: string; id: string; error?: string }> {
- return backendCall("download_model", { url, subfolder, filename })
+export async function startModelDownload(url: string, subfolder: string, filename: string, expectedBytes?: number): Promise<{ status: string; id: string; error?: string }> {
+ return backendCall("download_model", { url, subfolder, filename, expectedBytes: expectedBytes ?? null })
}
export async function getDownloadProgress(): Promise<Record<string, DownloadProgress>> {
@@ -100,7 +100,8 @@ export async function installBundleComplete(bundle: ModelBundle): Promise<void>
for (const file of bundle.files) {
if (!file.downloadUrl || !file.filename || !file.subfolder) continue
try {
- const result = await startModelDownload(file.downloadUrl, file.subfolder, file.filename)
+ const expectedBytes = file.sizeGB ? Math.round(file.sizeGB * 1_073_741_824) : undefined
+ const result = await startModelDownload(file.downloadUrl, file.subfolder, file.filename, expectedBytes)
if (result.status === 'exists') {
// File already on disk — emit synthetic 'complete' so UI reflects it
window.dispatchEvent(new CustomEvent('comfyui-download-exists', { detail: { filename: file.filename } }))
@@ -511,8 +512,8 @@ export async function detectProviderModelPath(providerName: string): Promise<str
}
/** Download a GGUF model to a specific directory (for non-Ollama providers) */
-export async function startModelDownloadToPath(url: string, destDir: string, filename: string): Promise<{ status: string; id: string; error?: string }> {
- return backendCall('download_model_to_path', { url, destDir, filename })
+export async function startModelDownloadToPath(url: string, destDir: string, filename: string, expectedBytes?: number): Promise<{ status: string; id: string; error?: string }> {
+ return backendCall('download_model_to_path', { url, destDir, filename, expectedBytes: expectedBytes ?? null })
}
// ─── Image Model Bundles ───
diff --git a/src/components/models/DiscoverModels.tsx b/src/components/models/DiscoverModels.tsx
index 1b1660fc..03b43db0 100644
--- a/src/components/models/DiscoverModels.tsx
+++ b/src/components/models/DiscoverModels.tsx
@@ -337,6 +337,7 @@ export function DiscoverModels({ category }: Props) {
const [installError, setInstallError] = useState<string | null>(null)
const handleBundleInstall = async (bundle: ModelBundle) => {
+ if (installingBundle === bundle.name) return // Prevent duplicate installs
setInstallingBundle(bundle.name)
const filenames: string[] = []
for (const file of bundle.files) {
@@ -452,8 +453,7 @@ export function DiscoverModels({ category }: Props) {
// HF curated lists are static — just re-detect model path and clear search results
setHfSearchResults([])
const providerName = providers.openai?.name || 'LM Studio'
- detectProviderModelPath(providerName).then(path => setHfModelPath(path))
- setLoading(false)
+ detectProviderModelPath(providerName).then(path => { setHfModelPath(path); setLoading(false) })
}
}
@@ -467,7 +467,8 @@ export function DiscoverModels({ category }: Props) {
setHfModelPath(destDir)
try {
dlStore.getState().setMeta(model.filename, model.downloadUrl, 'gguf')
- await startModelDownloadToPath(model.downloadUrl, destDir, model.filename)
+ const expectedBytes = model.sizeGB ? Math.round(model.sizeGB * 1_073_741_824) : undefined
+ await startModelDownloadToPath(model.downloadUrl, destDir, model.filename, expectedBytes)
dlStore.getState().startPolling()
} catch (e) {
console.error('HF download failed:', e)
diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.ts
index 367dcb07..d687a031 100644
--- a/src/hooks/useModels.ts
+++ b/src/hooks/useModels.ts
@@ -108,7 +108,7 @@ export function useModels() {
updatePullProgress(name, chunk)
}
completePull(name)
- await fetchModels()
+ try { await fetchModels() } catch { /* non-critical */ }
setTimeout(() => dismissPull(name), 5000)
} catch (err) {
if ((err as Error).name !== 'AbortError') {
diff --git a/vite.config.ts b/vite.config.ts
index c4b70877..bfd85299 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -2,7 +2,7 @@ import { defineConfig, type Plugin } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { spawn, execSync, type ChildProcess } from 'child_process'
-import { existsSync, readdirSync, createWriteStream, mkdirSync } from 'fs'
+import { existsSync, readdirSync, createWriteStream, mkdirSync, statSync } from 'fs'
import { resolve, join, basename } from 'path'
import https from 'https'
import http from 'http'
@@ -384,7 +384,7 @@ function comfyLauncher(): Plugin {
req.on('data', (c: any) => { body += c })
req.on('end', () => {
try {
- const { url, subfolder, filename } = JSON.parse(body)
+ const { url, subfolder, filename, expectedBytes } = JSON.parse(body)
if (!url || !subfolder || !filename) {
res.writeHead(400, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ error: 'Missing url, subfolder, or filename' }))
@@ -402,9 +402,24 @@ function comfyLauncher(): Plugin {
const destPath = join(destDir, filename)
if (existsSync(destPath)) {
- res.writeHead(200, { 'Content-Type': 'application/json' })
- res.end(JSON.stringify({ status: 'exists', id: filename }))
- return
+ // Validate file size if expectedBytes provided (catch partial downloads)
+ let fileComplete = true
+ if (expectedBytes && expectedBytes > 0) {
+ try {
+ const actual = statSync(destPath).size
+ const threshold = expectedBytes * 0.9
+ fileComplete = actual >= threshold
+ if (!fileComplete) {
+ console.log(`[Download] File ${filename} is incomplete: ${actual} bytes vs ${expectedBytes} expected (${Math.round(actual / expectedBytes * 100)}%)`)
+ }
+ } catch { fileComplete = true }
+ }
+ if (fileComplete) {
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ status: 'exists', id: filename }))
+ return
+ }
+ // Fall through to re-download incomplete file
}
const id = filename
@@ -485,14 +500,25 @@ function comfyLauncher(): Plugin {
res.end(JSON.stringify({ error: 'Missing url, destDir, or filename' }))
return
}
- const { existsSync, mkdirSync } = require('fs')
+ const { existsSync, mkdirSync, statSync: statSyncFs } = require('fs')
const { join } = require('path')
+ const expectedBytes = parsed.expectedBytes
if (!existsSync(destDir)) mkdirSync(destDir, { recursive: true })
const destPath = join(destDir, filename)
if (existsSync(destPath)) {
- res.writeHead(200, { 'Content-Type': 'application/json' })
- res.end(JSON.stringify({ status: 'exists', id: filename }))
- return
+ let fileComplete = true
+ if (expectedBytes && expectedBytes > 0) {
+ try {
+ const actual = statSyncFs(destPath).size
+ fileComplete = actual >= expectedBytes * 0.9
+ if (!fileComplete) console.log(`[Download] ${filename} incomplete: ${actual} vs ${expectedBytes} expected`)
+ } catch { fileComplete = true }
+ }
+ if (fileComplete) {
+ res.writeHead(200, { 'Content-Type': 'application/json' })
+ res.end(JSON.stringify({ status: 'exists', id: filename }))
+ return
+ }
}
const id = filename
console.log(`[Download] Starting to path: ${filename} → ${destDir}`)