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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(comfyui): a start that fails says so instead of going quiet
Davidcbff32bb11b0
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rsindex 139cbbe2..bb4b8468 100644--- a/src-tauri/src/commands/process.rs+++ b/src-tauri/src/commands/process.rs@@ -140,6 +140,84 @@ impl ComfyGpuMode {}}+/// How long after a spawn a still-living child counts as proof of a start.+/// ComfyUI imports for 20 to 60 seconds before it binds the port, so we cannot+/// wait for the port here. We can wait for the crash: a bad dependency kills+/// main.py on the first import, well inside this window.+const COMFY_STARTUP_WATCH: std::time::Duration = std::time::Duration::from_millis(2_000);+const COMFY_STARTUP_STEP: std::time::Duration = std::time::Duration::from_millis(200);++/// After this long without the port opening, "starting" is a lie.+/// The slowest honest start measured on the 3060 box is about a minute; a+/// custom-node-heavy install can take longer, so this is deliberately generous.+const COMFY_STARTING_GRACE_SECS: u64 = 300;++/// What the panel should say about a child that is alive but has not bound the+/// port: `(starting, stalled)`.+///+/// Measured on the Windows box on 2026-08-14: `starting` was+/// `process_alive && !running` and nothing else, so a handle that never+/// resolved left the panel claiming a start that had been over for six+/// minutes. `starting` now expires, and the caller reports `stalled` so the UI+/// can offer the output instead of a spinner.+pub fn comfy_starting_state(+ process_alive: bool,+ running: bool,+ since_start: Option<std::time::Duration>,+) -> (bool, bool) {+ if running || !process_alive {+ return (false, false);+ }+ match since_start {+ // A handle we cannot date (kept from an earlier call, or a start we did+ // not make) gets the old reading rather than a stall we cannot prove.+ None => (true, false),+ Some(waited) if waited.as_secs() > COMFY_STARTING_GRACE_SECS => (false, true),+ Some(_) => (true, false),+ }+}++/// The message a start that is already over has to carry.+///+/// The traceback was never the missing part: `capture` has been putting every+/// line into `comfy_output` since GH #98. The missing part was anyone reading+/// it at the moment the start failed, which is why the box showed `Stopped`+/// with no reason while `main.py`'s ImportError sat in the ring buffer.+pub fn comfy_startup_failure(+ python: &str,+ code: Option<i32>,+ tail: &[String],+ has_own_python_env: bool,+) -> String {+ let mut msg = format!("ComfyUI exited right after starting (python={python}");+ if let Some(c) = code {+ msg.push_str(&format!(", exit code {c}"));+ }+ msg.push_str(").");+ if !has_own_python_env {+ msg.push_str(+ " This install has no python_embeded and no venv, so it ran on the system Python, \+ which usually does not have ComfyUI's dependencies. Settings, ComfyUI, Install \+ builds one.",+ );+ }+ let lines: Vec<&str> = tail+ .iter()+ .map(|l| l.trim_end())+ .filter(|l| !l.is_empty())+ .rev()+ .take(8)+ .collect::<Vec<_>>()+ .into_iter()+ .rev()+ .collect();+ if !lines.is_empty() {+ msg.push_str("\n\nLast output:\n");+ msg.push_str(&lines.join("\n"));+ }+ msg+}+/// Pure decision (all probes done by the caller): pass `--cpu` to ComfyUI?////// - `baseline_needs_cpu`: `needs_cpu_fallback()` — false when NVIDIA present or macOS.@@ -1331,11 +1409,52 @@ fn start_comfyui_blocking(state: &AppState) -> Result<serde_json::Value, String>});}+ // A spawn is not a start (E16, measured on the Windows box 2026-08-14).+ // That install had ComfyUI's source but neither python_embeded nor a venv,+ // so this fell back to the system Python, which has none of the+ // dependencies: main.py died on its first import inside a second. We+ // reported {"status":"started"} anyway, the panel showed `Stopped` with no+ // reason, and the traceback sat unread in our own ring buffer.+ //+ // The port cannot be the test here, ComfyUI imports for 20 to 60 seconds+ // before it binds. The crash can: it happens far inside this window. So+ // watch briefly, and if the child is already gone, fail with what it said.+ let mut watched = std::time::Duration::ZERO;+ let early_exit = loop {+ match child.try_wait() {+ Ok(Some(status)) => break Some(status.code()),+ Ok(None) => {}+ Err(_) => break None,+ }+ if watched >= COMFY_STARTUP_WATCH {+ break None;+ }+ std::thread::sleep(COMFY_STARTUP_STEP);+ watched += COMFY_STARTUP_STEP;+ };+ if let Some(code) = early_exit {+ let tail: Vec<String> = state+ .comfy_output+ .lock()+ .map(|b| b.iter().cloned().collect())+ .unwrap_or_default();+ let msg = comfy_startup_failure(+ &python,+ code,+ &tail,+ bundled_python.is_some() || venv_python.is_some(),+ );+ error!(python = %python, "comfyui exited during startup");+ *state.comfy_start_at.lock().unwrap() = None;+ return Err(msg);+ }+// Store process{let mut proc = state.comfy_process.lock().unwrap();*proc = Some(child);}+ *state.comfy_start_at.lock().unwrap() = Some(std::time::Instant::now());println!("[ComfyUI] Started");info!("comfyui started");@@ -1373,6 +1492,7 @@ fn stop_comfyui_blocking(state: &AppState) -> Result<serde_json::Value, String>// the dying process and silently leave the OLD node list being served.let _ = child.wait();*proc = None;+ *state.comfy_start_at.lock().unwrap() = None;println!("[ComfyUI] Stopped");info!(pid = pid, "comfyui stopped");Ok(serde_json::json!({"status": "stopped"}))@@ -1478,9 +1598,13 @@ pub async fn comfyui_status(state: State<'_, AppState>) -> Result<serde_json::Vatrue};+ let since_start = state.comfy_start_at.lock().unwrap().map(|t| t.elapsed());+ let (starting, stalled) = comfy_starting_state(process_alive, running, since_start);+Ok(serde_json::json!({"running": running,- "starting": process_alive && !running,+ "starting": starting,+ "stalled": stalled,"found": found,"complete": complete,"path": path,@@ -1978,6 +2102,76 @@ pub fn auto_start_comfyui(state: &AppState) {mod tests {use super::*;+ // ── E16: a start that fails has to say so ────────────────────────────+ //+ // Measured on the Windows box on 2026-08-14. The install had ComfyUI's+ // source but neither python_embeded nor a venv, so the launch fell back to+ // the system Python, which has none of the dependencies. main.py died on+ // its first import inside a second. What the user got: `start_comfyui`+ // answered {"status":"started"}, `comfyui_status` answered+ // processAlive true / running false / starting true, the panel showed+ // `Stopped`, and six minutes later it still showed `Stopped` with no+ // reason anywhere, while the ImportError sat in our own ring buffer.++ #[test]+ fn a_start_that_is_already_over_stops_claiming_to_be_starting() {+ // Inside the grace period a slow import is a normal start.+ assert_eq!(+ comfy_starting_state(true, false, Some(std::time::Duration::from_secs(30))),+ (true, false),+ );+ // Past it, the handle is not proof of anything. `starting` has to end,+ // and the caller needs to know it ended badly rather than quietly.+ assert_eq!(+ comfy_starting_state(true, false, Some(std::time::Duration::from_secs(COMFY_STARTING_GRACE_SECS + 1))),+ (false, true),+ );+ // A port that answers is the end of the question, however long it took.+ assert_eq!(+ comfy_starting_state(true, true, Some(std::time::Duration::from_secs(9_999))),+ (false, false),+ );+ // No child, nothing to wait for.+ assert_eq!(comfy_starting_state(false, false, None), (false, false));+ // Unknown start time (handle from an earlier session): fall back to the+ // old reading rather than declaring a stall we cannot date.+ assert_eq!(comfy_starting_state(true, false, None), (true, false));+ }++ #[test]+ fn the_failure_message_carries_the_traceback_and_the_likely_cause() {+ let tail = vec![+ "[start] C:\\Python313\\python.exe main.py --port 8188".to_string(),+ "Traceback (most recent call last):".to_string(),+ " File \"main.py\", line 25, in <module>".to_string(),+ " from app.assets.seeder import asset_seeder".to_string(),+ "ModuleNotFoundError: No module named 'app'".to_string(),+ ];+ let msg = comfy_startup_failure("C:\\Python313\\python.exe", Some(1), &tail, false);++ // The reason the user can act on, verbatim from the child.+ assert!(msg.contains("ModuleNotFoundError: No module named 'app'"), "{msg}");+ assert!(msg.contains("exit code 1"), "{msg}");+ // And the one sentence that explains why it happened on THIS install.+ assert!(msg.contains("no python_embeded and no venv"), "{msg}");++ // With a proper environment the guess would be wrong, so it is not made.+ let msg2 = comfy_startup_failure("C:\\ComfyUI\\venv\\Scripts\\python.exe", None, &tail, true);+ assert!(!msg2.contains("no python_embeded"), "{msg2}");+ assert!(msg2.contains("ModuleNotFoundError"), "{msg2}");+ }++ #[test]+ fn the_failure_message_keeps_the_last_lines_not_the_first() {+ // A crash prints its reason at the END. Keeping the head of a 400 line+ // ring buffer would show the banner and hide the error.+ let mut tail: Vec<String> = (0..50).map(|i| format!("line {i}")).collect();+ tail.push("RuntimeError: the actual reason".to_string());+ let msg = comfy_startup_failure("python", Some(1), &tail, true);+ assert!(msg.contains("RuntimeError: the actual reason"), "{msg}");+ assert!(!msg.contains("line 0"), "{msg}");+ }+#[test]fn a_host_typed_with_its_port_keeps_both() {assert_eq!(split_host_port("192.168.1.50:8188"), ("192.168.1.50".into(), Some(8188)));diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rsindex 521d5340..679804a8 100644--- a/src-tauri/src/state.rs+++ b/src-tauri/src/state.rs@@ -289,6 +289,11 @@ pub struct AppState {/// The drain threads push here; `comfyui_last_output` reads it back./// Arc because the drain threads outlive the command's State borrow.pub comfy_output: Arc<Mutex<std::collections::VecDeque<String>>>,+ /// When the tracked ComfyUI child was spawned. Without it "starting" was+ /// just `process_alive && !running`, so a handle that never resolved left+ /// the panel claiming a start that had been over for minutes (E16,+ /// measured 2026-08-14). `comfy_starting_state` dates the wait against it.+ pub comfy_start_at: Mutex<Option<std::time::Instant>>,// ── In-process MLX media engine (macOS Apple-Silicon local image/video) ──// Ported from uselu/apps/bridge's `commands::mlx` / `commands::video`. The// app spawns its OWN Python MLX sidecar (server.py on 127.0.0.1:47712) —@@ -383,6 +388,7 @@ impl AppState {comfy_gpu_mode: Mutex::new("auto".to_string()),comfy_started_cpu: Mutex::new(None),comfy_output: Arc::new(Mutex::new(std::collections::VecDeque::new())),+ comfy_start_at: Mutex::new(None),install_mlx_diffusion: crate::install_state::InstallSlot::default(),install_mlx_image_model: crate::install_state::InstallSlot::default(),install_mlx_video: crate::install_state::InstallSlot::default(),diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex 43ee4109..074ec361 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -301,7 +301,13 @@ function HfDownloadPathSetting() {// ── ComfyUI Settings ────────────────────────────────────────────function ComfyUISettings() {- const [status, setStatus] = useState<{ running: boolean; found: boolean; complete?: boolean; path?: string; port?: number; host?: string; isLocal?: boolean; starting?: boolean } | null>(null)+ const [status, setStatus] = useState<{ running: boolean; found: boolean; complete?: boolean; path?: string; port?: number; host?: string; isLocal?: boolean; starting?: boolean; stalled?: boolean } | null>(null)+ // Why the last start attempt did not stick. The button used to swallow this+ // whole (E16): on a box with no ComfyUI python environment, Start answered+ // "started", the panel went back to `Stopped`, and six minutes later there+ // was still no reason anywhere on screen while the traceback sat in our own+ // ring buffer. An error is not allowed to be silence.+ const [startError, setStartError] = useState('')const [loading, setLoading] = useState(true)const [customPath, setCustomPath] = useState('')const [pathError, setPathError] = useState('')@@ -338,11 +344,14 @@ function ComfyUISettings() {}, [])const handleStart = async () => {+ setStartError('')try {const { backendCall } = await import('../../api/backend')await backendCall('start_comfyui')setStatus(prev => prev ? { ...prev, starting: true } : null)- } catch {}+ } catch (err) {+ setStartError(err instanceof Error ? err.message : String(err))+ }}const handleStop = async () => {@@ -380,11 +389,25 @@ function ComfyUISettings() {<div className="flex items-center gap-1.5"><div className={`w-1.5 h-1.5 rounded-full ${status?.running ? 'bg-green-500' : status?.found ? 'bg-orange-500' : 'bg-gray-500'}`} /><span className="text-[0.65rem] text-gray-500">- {status?.running ? 'Running' : status?.found ? 'Stopped' : 'Not Installed'}+ {status?.running ? 'Running'+ : status?.stalled ? 'Not responding'+ : status?.starting ? 'Starting'+ : status?.found ? 'Stopped' : 'Not Installed'}</span></div></div>+ {startError && (+ <pre className="whitespace-pre-wrap break-words text-[0.55rem] leading-relaxed text-red-400 bg-red-500/[0.06] border border-red-500/20 rounded p-2 max-h-40 overflow-y-auto">+ {startError}+ </pre>+ )}+ {status?.stalled && !startError && (+ <p className="text-[0.55rem] text-amber-400">+ ComfyUI has been starting for a while without answering on its port. Use Show output below to see what it printed.+ </p>+ )}+{/* Host - editable (supports remote ComfyUI: Docker, LAN, homelab) */}<div className="space-y-1"><span className="text-[0.7rem] text-gray-700 dark:text-gray-400">Host</span>