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(install): a node pack install frees a file the running ComfyUI holds open
purple30a429cd3073
diff --git a/src-tauri/src/commands/install/comfy_repair.rs b/src-tauri/src/commands/install/comfy_repair.rsindex 7c478a0c..54a91112 100644--- a/src-tauri/src/commands/install/comfy_repair.rs+++ b/src-tauri/src/commands/install/comfy_repair.rs@@ -531,7 +531,7 @@ pub fn repair_comfyui_env(state: State<'_, AppState>) -> Result<serde_json::Valu// like a hang with a Cancel button that does nothing.let mut broken_nodes: Vec<(String, String)> = Vec::new();if comfy_dir.join("custom_nodes").is_dir() {- let constraints = super::custom_nodes::write_core_package_constraints(&venv_py);+ let constraints = super::custom_nodes::write_package_constraints(&venv_py, &super::custom_nodes::CORE_PACKAGES);let outcome = super::custom_nodes::reinstall_all_node_requirements(&comfy_dir,&venv_py,@@ -761,9 +761,60 @@ fn wait_for_port_free(/// offers the Update button once `isLocal` is false, and this app manages no/// process there either way.fn ensure_comfyui_stopped_for_update(state: &State<'_, AppState>) -> Result<(), String> {+ let port = *state.comfy_port.lock().unwrap();+ match stop_own_idle_comfyui(state) {+ OwnComfyStop::NotRunning | OwnComfyStop::Stopped => Ok(()),+ OwnComfyStop::Foreign => {+ println!("[Update] Refusing: port {port} is served by a ComfyUI this app did not start");+ Err(foreign_comfyui_blocks_update(port))+ }+ OwnComfyStop::Busy => {+ println!("[Update] Refusing: ComfyUI on port {port} is generating something");+ Err(COMFYUI_BUSY_REFUSAL.to_string())+ }+ OwnComfyStop::QueueUnknown(e) => {+ println!("[Update] Refusing: could not check ComfyUI's queue on port {port}: {e}");+ Err(format!(+ "Could not check whether ComfyUI is generating something right now, so the \+ update was refused rather than risk interrupting a render ({e}). Nothing \+ was changed."+ ))+ }+ OwnComfyStop::StopFailed(e) => Err(e),+ OwnComfyStop::StillRunning => Err(format!(+ "ComfyUI on port {port} did not stop, so the update was not started. Try \+ Stop in Settings, then run Update ComfyUI again. Nothing was changed."+ )),+ }+}++/// What became of the ComfyUI on the configured port when a job asked for it+/// to be out of the way.+pub(crate) enum OwnComfyStop {+ /// Nothing was serving the port (or the host is another machine).+ NotRunning,+ /// It was this app's own, it was idle, and it is down now.+ Stopped,+ /// A ComfyUI this app never started. Left alone.+ Foreign,+ /// This app's own, but it is rendering. Left alone.+ Busy,+ /// This app's own, but its queue could not be read. Left alone.+ QueueUnknown(String),+ /// The stop itself failed, with the reason.+ StopFailed(String),+ /// The stop went through and the port still answers.+ StillRunning,+}++/// Stop this app's own ComfyUI when it is idle, and say what was found. Never+/// touches a ComfyUI this app did not start and never interrupts a render.+/// Shared by Update ComfyUI and by a node pack whose requirements replace a+/// file the running ComfyUI holds open (custom_nodes.rs).+pub(crate) fn stop_own_idle_comfyui(state: &AppState) -> OwnComfyStop {let host = state.comfy_host.lock().unwrap().clone();if !crate::commands::process::is_local_host(&host) {- return Ok(());+ return OwnComfyStop::NotRunning;}let port = *state.comfy_port.lock().unwrap();let port_occupied = crate::commands::process::is_comfyui_running_on_port(port);@@ -799,36 +850,26 @@ fn ensure_comfyui_stopped_for_update(state: &State<'_, AppState>) -> Result<(),// return that used to sit above this block, made the `NotRunning` arm// below dead code that only LOOKED like a check.match crate::commands::process::classify_comfyui_ownership(port_occupied, own_child_alive, orphan_pid) {- crate::commands::process::ComfyOwnership::NotRunning => Ok(()),- crate::commands::process::ComfyOwnership::Foreign => {- println!("[Update] Refusing: port {port} is served by a ComfyUI this app did not start");- Err(foreign_comfyui_blocks_update(port))- }+ crate::commands::process::ComfyOwnership::NotRunning => OwnComfyStop::NotRunning,+ crate::commands::process::ComfyOwnership::Foreign => OwnComfyStop::Foreign,crate::commands::process::ComfyOwnership::Own => {match comfyui_queue_busy(port) {- Ok(true) => {- println!("[Update] Refusing: ComfyUI on port {port} is generating something");- Err(COMFYUI_BUSY_REFUSAL.to_string())- }- Err(e) => {- println!("[Update] Refusing: could not check ComfyUI's queue on port {port}: {e}");- Err(format!(- "Could not check whether ComfyUI is generating something right now, so the \- update was refused rather than risk interrupting a render ({e}). Nothing \- was changed."- ))- }+ Ok(true) => OwnComfyStop::Busy,+ Err(e) => OwnComfyStop::QueueUnknown(e),Ok(false) => {- let result = crate::commands::process::stop_comfyui_blocking(state)?;+ let result = match crate::commands::process::stop_comfyui_blocking(state) {+ Ok(r) => r,+ Err(e) => return OwnComfyStop::StopFailed(e),+ };let status = result.get("status").and_then(|s| s.as_str()).unwrap_or("");if status == "not_ours" {// A race between the classify above and the stop: the// handle exited and something else grabbed the port- // in between. Rare, and refused exactly like a plain+ // in between. Rare, and treated exactly like a plain// foreign ComfyUI would be.- return Err(foreign_comfyui_blocks_update(port));+ return OwnComfyStop::Foreign;}- info!(port = port, status = status, "update_comfyui stopped its own ComfyUI before updating");+ info!(port = port, status = status, "stopped the app's own idle ComfyUI");// final review Runde 2, R2-1: a single check right here// used to fire before the kill had actually landed.// `stop_comfyui_blocking`'s own-child path reaps with@@ -848,12 +889,9 @@ fn ensure_comfyui_stopped_for_update(state: &State<'_, AppState>) -> Result<(),std::time::Duration::from_secs(10),|| crate::commands::process::is_comfyui_running_on_port(port),) {- return Err(format!(- "ComfyUI on port {port} did not stop, so the update was not started. Try \- Stop in Settings, then run Update ComfyUI again. Nothing was changed."- ));+ return OwnComfyStop::StillRunning;}- Ok(())+ OwnComfyStop::Stopped}}}@@ -2070,9 +2108,9 @@ mod tests {let src = include_str!("comfy_repair.rs");let needle = |head: &str, tail: &str| format!("{head}{tail}");- let guard_fn_start = src.find("fn ensure_comfyui_stopped_for_update(").expect("the running-instance guard is gone");+ let guard_fn_start = src.find("fn stop_own_idle_comfyui(").expect("the running-instance guard is gone");let queue_check = needle("comfyui_queue_bus", "y(port)");- let stop_call = needle("process::stop_comfyui_bloc", "king(state)?;");+ let stop_call = needle("process::stop_comfyui_bloc", "king(state)");let at_queue_check = src[guard_fn_start..].find(&queue_check).map(|i| i + guard_fn_start).expect("the guard no longer checks whether ComfyUI is busy");diff --git a/src-tauri/src/commands/install/custom_nodes.rs b/src-tauri/src/commands/install/custom_nodes.rsindex 94aed645..6f9d7d0e 100644--- a/src-tauri/src/commands/install/custom_nodes.rs+++ b/src-tauri/src/commands/install/custom_nodes.rs@@ -32,7 +32,7 @@ use std::process::Stdio;#[cfg(target_os = "windows")]use std::os::windows::process::CommandExt;-use tauri::State;+use tauri::{Manager, State};use tracing::{error, info};use crate::os_error;@@ -50,6 +50,7 @@ use super::CREATE_NO_WINDOW;#[tauri::command]pub async fn install_custom_node(state: State<'_, AppState>,+ app: tauri::AppHandle,repoUrl: String,nodeName: String,) -> Result<serde_json::Value, String> {@@ -74,7 +75,18 @@ pub async fn install_custom_node(// stays responsive and the staged status messages actually paint — the JS// caller still awaits this command's result exactly as before.tauri::async_runtime::spawn_blocking(move || {- install_custom_node_blocking(repoUrl, nodeName, comfy_path, &fallback_python)+ // Re-resolved here: a `State` borrow cannot cross into the blocking+ // pool, and the pause below stops and starts ComfyUI through it.+ let state = app.state::<AppState>();+ let pause = ComfyPause {+ stop: &|| super::comfy_repair::stop_own_idle_comfyui(&state),+ start: &|| {+ if let Err(e) = crate::commands::process::start_comfyui_blocking(&state) {+ error!(error = %e, "comfyui did not start again after a node pack install");+ }+ },+ };+ install_custom_node_blocking(repoUrl, nodeName, comfy_path, &fallback_python, &pause)}).await.map_err(|e| format!("Custom node install task failed to run: {e}"))?@@ -89,6 +101,7 @@ fn install_custom_node_blocking(nodeName: String,comfy_path: Option<String>,fallback_python: &str,+ pause: &ComfyPause<'_>,) -> Result<serde_json::Value, String> {let repo_url = repoUrl;let node_name = nodeName;@@ -225,11 +238,21 @@ fn install_custom_node_blocking(}}- // No constraints file here: this is a fresh clone (or update) of ONE- // node against whatever the venv already has, not the post-repair- // restore path where a downgrade of a just-verified core package is the- // specific risk (Runde 6, Folgeposten a).- install_node_requirements(&comfy_dir, &target_dir, &node_name, fallback_python, None)?;+ // A node pack never replaces torch: its requirements go in against a pin+ // of the torch family this ComfyUI runs on, so a pack that asks for+ // another torch fails by name instead of trading the CUDA build for a+ // CPU wheel. numpy stays free here (unlike the post-repair restore),+ // packs legitimately move it.+ let constraints = node_python(&comfy_dir, fallback_python)+ .and_then(|python| write_package_constraints(&python, &TORCH_PACKAGES));+ let installed = install_requirements_freeing_locked_files(+ &|| install_node_requirements(&comfy_dir, &target_dir, &node_name, fallback_python, constraints.as_deref()),+ pause,+ );+ if let Some(c) = &constraints {+ let _ = fs::remove_file(c);+ }+ installed?;Ok(serde_json::json!({"status": if fresh_clone { "installed" } else { "updated" },@@ -237,6 +260,76 @@ fn install_custom_node_blocking(}))}+/// How the installer takes this app's own ComfyUI out of the way and brings+/// it back. Closures, so the rule below is provable without a process.+pub(crate) struct ComfyPause<'a> {+ pub(crate) stop: &'a dyn Fn() -> super::comfy_repair::OwnComfyStop,+ pub(crate) start: &'a dyn Fn(),+}++/// Install a node pack's requirements, and when pip cannot write a file+/// because a running ComfyUI holds it open, stop that ComfyUI, install again+/// and start it again.+///+/// The box, 03.10.2026, ComfyUI-RMBG: its requirements bring+/// opencv-python-headless, which writes `cv2\cv2.pyd`. The running ComfyUI+/// had that file loaded (VideoHelperSuite imports cv2), Windows refused the+/// write with WinError 5, and four attempts ended on "close any open Python+/// REPLs" while the only Python on the machine was the ComfyUI this app had+/// started itself. The same command went through with ComfyUI stopped.+///+/// Only this app's own, idle ComfyUI is stopped. A render in progress and a+/// ComfyUI started outside the app are left alone, and the message then+/// names them instead of sending the customer after a Python that is not+/// there.+fn install_requirements_freeing_locked_files(+ install: &dyn Fn() -> Result<(), String>,+ pause: &ComfyPause<'_>,+) -> Result<(), String> {+ use super::comfy_repair::OwnComfyStop;+ let reason = match install() {+ Ok(()) => return Ok(()),+ Err(reason) => reason,+ };+ if !is_permission_denied_pip_error(&reason) {+ return Err(reason);+ }+ match (pause.stop)() {+ OwnComfyStop::Stopped => {+ println!("[Install] A running ComfyUI held a file the requirements replace. Stopped it, installing again.");+ let second = install();+ // Back up whether the second try worked or not: it was running+ // before this install touched it.+ (pause.start)();+ second+ }+ OwnComfyStop::Busy => Err(format!(+ "ComfyUI is generating something right now and has a file open that this node pack \+ replaces. Wait for the render to finish, then install again.\n\n{reason}"+ )),+ OwnComfyStop::Foreign => Err(format!(+ "A ComfyUI this app did not start is running and has a file open that this node pack \+ replaces. Close that ComfyUI, then install again.\n\n{reason}"+ )),+ OwnComfyStop::NotRunning+ | OwnComfyStop::QueueUnknown(_)+ | OwnComfyStop::StopFailed(_)+ | OwnComfyStop::StillRunning => Err(reason),+ }+}++/// The Python a node pack's requirements go into: ComfyUI's venv when it has+/// a usable one, the fallback otherwise. None for a broken venv, which+/// `install_node_requirements` reports in its own words.+fn node_python(comfy_dir: &std::path::Path, fallback_python: &str) -> Option<String> {+ match crate::python::comfy_venv_state(comfy_dir) {+ crate::python::ComfyVenv::Usable(p) => Some(p),+ crate::python::ComfyVenv::Broken { .. } => None,+ crate::python::ComfyVenv::Absent if fallback_python.is_empty() => None,+ crate::python::ComfyVenv::Absent => Some(fallback_python.to_string()),+ }+}+/// Move a non-repo custom-node leftover out of the way so a fresh clone can/// land. The ".disabled" suffix matches the ComfyUI(-Manager) convention, so/// ComfyUI never tries to load the moved-aside folder as a node pack.@@ -326,7 +419,14 @@ pub(crate) fn install_node_requirements(if !pip_out.status.success() {let stderr = String::from_utf8_lossy(&pip_out.stderr);let stdout = String::from_utf8_lossy(&pip_out.stdout);- let combined = format!("{}{}", stdout, stderr);+ // The words of the operating system are ours to answer for: a German+ // Windows hands pip "Zugriff verweigert", and the line is shown in an+ // English app. What pip wrote itself stays as it is.+ let combined: String = format!("{}{}", stdout, stderr)+ .lines()+ .map(|line| os_error::english_child_text(line).into_owned())+ .collect::<Vec<_>>()+ .join("\n");// python.org installs under Program Files have an admin-only// site-packages: the first node pack whose requirements pull a NEW// wheel dies with a permission error, while packs whose deps are@@ -369,9 +469,13 @@ pub(crate) fn install_node_requirements(/// snapshot a caller can hand to [`install_node_requirements`] as a/// constraints file so pip REFUSES to let a node's own requirements.txt/// quietly change any of them.-const CORE_PACKAGES: [&str; 4] = ["torch", "torchvision", "torchaudio", "numpy"];+pub(crate) const CORE_PACKAGES: [&str; 4] = ["torch", "torchvision", "torchaudio", "numpy"];++/// What a single node pack install must never replace (see+/// `install_custom_node_blocking`).+const TORCH_PACKAGES: [&str; 3] = ["torch", "torchvision", "torchaudio"];-/// Write [`CORE_PACKAGES`]'s current, exact versions (from `pip freeze`+/// Write the current, exact versions of `packages` (from `pip freeze`/// against `python_bin`) to a fresh temp file in pip's constraints format/// (one `name==version` per line) and return its path. `None` when `pip/// freeze` itself fails to run, or when none of the core packages turn out@@ -380,7 +484,7 @@ const CORE_PACKAGES: [&str; 4] = ["torch", "torchvision", "torchaudio", "numpy"]////// The caller owns the returned file and is responsible for deleting it once/// the node loop that uses it is done; this function only ever creates one.-pub(crate) fn write_core_package_constraints(python_bin: &str) -> Option<PathBuf> {+pub(crate) fn write_package_constraints(python_bin: &str, packages: &[&str]) -> Option<PathBuf> {let mut cmd = python_command(python_bin);cmd.args(["-m", "pip", "freeze"]).stdout(Stdio::piped()).stderr(Stdio::piped());let out = cmd.output().ok()?;@@ -388,7 +492,7 @@ pub(crate) fn write_core_package_constraints(python_bin: &str) -> Option<PathBufreturn None;}let freeze = String::from_utf8_lossy(&out.stdout);- let core_lines = core_constraint_lines(&freeze);+ let core_lines = constraint_lines(&freeze, packages);if core_lines.is_empty() {return None;}@@ -405,7 +509,7 @@ pub(crate) fn write_core_package_constraints(python_bin: &str) -> Option<PathBuf}/// Pure: the subset of a `pip freeze` listing that names one of-/// [`CORE_PACKAGES`], for exactly the reason every other network- or+/// `packages`, for exactly the reason every other network- or/// process-touching function in this codebase splits its parsing out:/// testable against a canned string, no pip and no venv required.///@@ -420,11 +524,11 @@ pub(crate) fn write_core_package_constraints(python_bin: &str) -> Option<PathBuf/// `-c <file>` argument, so EVERY custom node's own install would start/// failing, not just the one node that happens to touch a core package. A/// venv built the normal way, from the index, never produces this shape (see-/// `write_core_package_constraints`'s own doc: it only ever reads THIS+/// `write_package_constraints`'s own doc: it only ever reads THIS/// venv's `pip freeze` after this repair's own build), so this is a defensive/// skip for a shape that should not occur today, not a shape this file/// exercises against a real freeze.-fn core_constraint_lines(freeze: &str) -> Vec<&str> {+fn constraint_lines<'a>(freeze: &'a str, packages: &[&str]) -> Vec<&'a str> {freeze.lines().filter(|line| {@@ -433,7 +537,7 @@ fn core_constraint_lines(freeze: &str) -> Vec<&str> {.next().unwrap_or("").to_lowercase();- CORE_PACKAGES.contains(&name.as_str()) && !line.contains('@')+ packages.contains(&name.as_str()) && !line.contains('@')}).collect()}@@ -485,7 +589,7 @@ impl NodeReinstallOutcome {/// claiming success.////// Runde 6, Folgeposten (a) and (b) (review Runde 5, F2/F3): `constraints`-/// (from [`write_core_package_constraints`]) is passed straight through to+/// (from [`write_package_constraints`]) is passed straight through to/// every node's own install so none of them can quietly downgrade torch or/// numpy; `cancel` is read BETWEEN nodes so a customer with twenty of them/// can actually stop the run instead of the Cancel button doing nothing@@ -544,6 +648,126 @@ pub(crate) fn reinstall_all_node_requirements(mod tests {use super::*;+ // ── A file the running ComfyUI holds open (the box, 03.10.2026) ─────++ use super::super::comfy_repair::OwnComfyStop;+ use std::cell::{Cell, RefCell};++ /// What the app said on the box, with pip's real last line in it.+ const LOCKED: &str = "Custom node ComfyUI-RMBG is cloned, but its requirements install failed.\n\n\+ Permission denied. Make sure no other process is using Python, then retry.\n\n--- pip output ---\n\+ ERROR: Could not install packages due to an OSError: [WinError 5] access is denied: \+ 'C:\\\\Users\\\\ddrob\\\\ComfyUI\\\\venv\\\\Lib\\\\site-packages\\\\cv2\\\\cv2.pyd'\nCheck the permissions.";++ /// Runs the rule with a pip that fails `failures` times on the locked+ /// file, and records the order of everything that happened.+ fn run_locked(failures: usize, found: fn() -> OwnComfyStop) -> (Result<(), String>, Vec<&'static str>) {+ let events = RefCell::new(Vec::new());+ let left = Cell::new(failures);+ let install = || {+ events.borrow_mut().push("pip");+ if left.get() > 0 {+ left.set(left.get() - 1);+ Err(LOCKED.to_string())+ } else {+ Ok(())+ }+ };+ let stop = || {+ events.borrow_mut().push("stop");+ found()+ };+ let start = || events.borrow_mut().push("start");+ let result = install_requirements_freeing_locked_files(&install, &ComfyPause { stop: &stop, start: &start });+ (result, events.into_inner())+ }++ #[test]+ fn a_file_held_by_the_apps_own_comfyui_is_freed_and_the_install_goes_through() {+ let (result, events) = run_locked(1, || OwnComfyStop::Stopped);+ assert_eq!(result, Ok(()));+ assert_eq!(events, ["pip", "stop", "pip", "start"]);+ }++ #[test]+ fn comfyui_comes_back_up_even_when_the_second_try_fails_too() {+ let (result, events) = run_locked(2, || OwnComfyStop::Stopped);+ assert_eq!(result, Err(LOCKED.to_string()));+ assert_eq!(events, ["pip", "stop", "pip", "start"], "a ComfyUI this install stopped must be started again");+ }++ #[test]+ fn an_install_that_works_never_touches_comfyui() {+ let (result, events) = run_locked(0, || OwnComfyStop::Stopped);+ assert_eq!(result, Ok(()));+ assert_eq!(events, ["pip"]);+ }++ #[test]+ fn a_failure_that_is_no_locked_file_never_stops_comfyui() {+ let events = RefCell::new(Vec::new());+ let install = || -> Result<(), String> {+ events.borrow_mut().push("pip");+ Err("ERROR: No matching distribution found for decord".to_string())+ };+ let stop = || {+ events.borrow_mut().push("stop");+ OwnComfyStop::Stopped+ };+ let start = || events.borrow_mut().push("start");+ let result = install_requirements_freeing_locked_files(&install, &ComfyPause { stop: &stop, start: &start });+ assert_eq!(result, Err("ERROR: No matching distribution found for decord".to_string()));+ assert_eq!(events.into_inner(), ["pip"]);+ }++ #[test]+ fn a_render_in_progress_is_not_interrupted_and_the_message_says_so() {+ let (result, events) = run_locked(1, || OwnComfyStop::Busy);+ let msg = result.unwrap_err();+ assert!(msg.starts_with("ComfyUI is generating something right now"), "got: {msg}");+ assert!(msg.contains("cv2.pyd"), "pip's own line with the file is gone: {msg}");+ assert_eq!(events, ["pip", "stop"], "no second pip and no start for a ComfyUI nobody stopped");+ }++ #[test]+ fn a_comfyui_started_outside_the_app_is_named_instead_of_a_python_repl() {+ let (result, events) = run_locked(1, || OwnComfyStop::Foreign);+ let msg = result.unwrap_err();+ assert!(msg.starts_with("A ComfyUI this app did not start is running"), "got: {msg}");+ assert!(msg.contains("Close that ComfyUI, then install again."), "got: {msg}");+ assert_eq!(events, ["pip", "stop"]);+ }++ #[test]+ fn with_no_comfyui_on_the_port_the_plain_reason_stands() {+ let (result, events) = run_locked(1, || OwnComfyStop::NotRunning);+ assert_eq!(result, Err(LOCKED.to_string()));+ assert_eq!(events, ["pip", "stop"]);+ }++ /// The pin a single node pack install runs against is the torch family+ /// only: a pack may move numpy, it never replaces torch.+ #[test]+ fn a_node_pack_is_held_to_the_installed_torch_and_free_on_numpy() {+ let freeze = "numpy==2.4.6\ntorch==2.14.0+cu130\ntorchaudio==2.14.0+cu130\ntorchvision==0.29.0+cu130\nopencv-python==5.0.0.93\n";+ assert_eq!(+ constraint_lines(freeze, &TORCH_PACKAGES),+ ["torch==2.14.0+cu130", "torchaudio==2.14.0+cu130", "torchvision==0.29.0+cu130"]+ );+ }++ /// Source guard: the rule above is worth nothing if the command does not+ /// run its pip through it, with the pin.+ #[test]+ fn install_custom_node_runs_its_requirements_through_the_rule_with_the_torch_pin() {+ let src = include_str!("custom_nodes.rs");+ let start = src.find("fn install_custom_node_blocking(").expect("install_custom_node_blocking is gone");+ let body = &src[start..];+ let body = &body[..body.find("\n}\n").expect("install_custom_node_blocking has no end")];+ assert!(body.contains("install_requirements_freeing_locked_files("), "the install no longer frees a locked file");+ assert!(body.contains("&TORCH_PACKAGES"), "the install no longer pins torch");+ }+// ── install_custom_node helpers (#72 bob: VHS install loop) ─────────#[test]@@ -608,14 +832,14 @@ mod tests {// F2) ─────────────────────────────────────────────────────────────────#[test]- fn core_constraint_lines_keeps_only_the_core_packages() {+ fn constraint_lines_keeps_only_the_core_packages() {let freeze = "torch==2.7.0\n\torchvision==0.22.0\n\numpy==1.26.4\n\Pillow==11.0.0\n\comfyui-frontend-package==1.2.3\n\torchaudio==2.7.0\n";- let lines = core_constraint_lines(freeze);+ let lines = constraint_lines(freeze, &CORE_PACKAGES);assert_eq!(lines, vec!["torch==2.7.0", "torchvision==0.22.0", "numpy==1.26.4", "torchaudio==2.7.0"]);// Negative control: neither Pillow nor comfyui-frontend-package,// both real ComfyUI-venv packages, may leak into the constraints.@@ -624,21 +848,21 @@ mod tests {}#[test]- fn core_constraint_lines_is_empty_for_a_freeze_with_no_core_packages() {+ fn constraint_lines_is_empty_for_a_freeze_with_no_core_packages() {// Negativkontrolle: a venv that somehow has no torch at all must not// invent a pin; an empty result is what tells the caller not to// write a constraints file.- assert!(core_constraint_lines("Pillow==11.0.0\nrequests==2.32.0\n").is_empty());- assert!(core_constraint_lines("").is_empty());+ assert!(constraint_lines("Pillow==11.0.0\nrequests==2.32.0\n", &CORE_PACKAGES).is_empty());+ assert!(constraint_lines("", &CORE_PACKAGES).is_empty());}#[test]- fn core_constraint_lines_is_not_fooled_by_a_name_prefix() {+ fn constraint_lines_is_not_fooled_by_a_name_prefix() {// "torch" must not match "torchsde" or "torchdiffeq", real// dependencies in a ComfyUI venv that are not the core packages this// constraints file exists to protect.let freeze = "torchsde==0.2.6\ntorchdiffeq==0.2.4\ntorch==2.7.0\n";- let lines = core_constraint_lines(freeze);+ let lines = constraint_lines(freeze, &CORE_PACKAGES);assert_eq!(lines, vec!["torch==2.7.0"]);}@@ -653,7 +877,7 @@ mod tests {fn a_direct_url_reference_line_is_skipped_even_though_its_name_matches() {let freeze = "torch @ file:///tmp/torch-2.7.0-cp312-cp312-linux_x86_64.whl\n\numpy==1.26.4\n";- let lines = core_constraint_lines(freeze);+ let lines = constraint_lines(freeze, &CORE_PACKAGES);assert_eq!(lines, vec!["numpy==1.26.4"], "the @ line must not appear in the constraints at all: {lines:?}");}diff --git a/src-tauri/src/commands/install/pip.rs b/src-tauri/src/commands/install/pip.rsindex b8562805..b7d84c7f 100644--- a/src-tauri/src/commands/install/pip.rs+++ b/src-tauri/src/commands/install/pip.rs@@ -123,8 +123,39 @@ pub(super) fn diagnose_pip_error_for(stderr: &str, python_bin: Option<&str>) ->}}+/// How much of pip's own error text a message carries at most.+const PIP_EXCERPT_MAX: usize = 1200;+/// How much of an output without an `ERROR:` line is kept, from its end.+const PIP_TAIL_MAX: usize = 400;++/// The part of a pip output a person needs: pip's own `ERROR:` lines and what+/// it says after them, whole.+///+/// The box, 03.10.2026: this used to be the first 400 characters. For a node+/// pack that is the head of the log, "Requirement already satisfied ...",+/// cut in the middle of a URL, while the one line that named the file pip+/// could not write stood two hundred lines further down and was never shown.+/// Without an `ERROR:` line (a traceback, a crash) the end of the output is+/// kept, because that is where a traceback names its exception. pip's+/// `[notice]` lines about a newer pip are no part of any failure.+pub(super) fn pip_error_excerpt(output: &str) -> String {+ let lines: Vec<&str> = output+ .lines()+ .map(str::trim_end)+ .filter(|l| !l.trim().is_empty() && !l.trim_start().starts_with("[notice]"))+ .collect();+ match lines.iter().position(|l| l.trim_start().starts_with("ERROR:")) {+ Some(first) => lines[first..].join("\n").chars().take(PIP_EXCERPT_MAX).collect(),+ None => {+ let all = lines.join("\n");+ let count = all.chars().count();+ all.chars().skip(count.saturating_sub(PIP_TAIL_MAX)).collect()+ }+ }+}+fn diagnose_pip_error_inner(stderr: &str, python_bin: Option<&str>) -> String {- let snippet: String = stderr.chars().take(400).collect();+ let snippet = pip_error_excerpt(stderr);let kind = pip_failure_kind(stderr);// K14: this is the one PipFailureKind whose hint text changes depending// on something OTHER than the pip output already in hand, see@@ -1513,6 +1544,41 @@ mod tests {assert!(msg.contains(raw));}+ /// The box, 03.10.2026, ComfyUI-RMBG on a running ComfyUI: four attempts,+ /// and each time the message ended in the middle of the second log line.+ /// The output below is pip's own, from the box, shortened in the middle.+ #[test]+ fn the_excerpt_is_pips_own_error_line_whole_not_the_head_of_the_log() {+ let filler = "Requirement already satisfied: idna in c:\\users\\ddrob\\comfyui\\venv\\lib\\site-packages (3.19)\n".repeat(40);+ let raw = format!(+ "Requirement already satisfied: huggingface-hub>=0.19.0 in c:\\users\\ddrob\\comfyui\\venv\\lib\\site-packages (1.31.0)\n\+ Collecting transparent-background>=1.1.2\n{filler}\+ Installing collected packages: opencv-python-headless\n\+ ERROR: Could not install packages due to an OSError: [WinError 5] access is denied: 'C:\\\\Users\\\\ddrob\\\\ComfyUI\\\\venv\\\\Lib\\\\site-packages\\\\cv2\\\\cv2.pyd'\n\+ Check the permissions.\n\n\n\+ [notice] A new release of pip is available: 23.2.1 -> 26.2.1\n\+ [notice] To update, run: python.exe -m pip install --upgrade pip\n"+ );+ assert!(raw.len() > 2000, "the fixture must be longer than the old 400 character cut");+ let excerpt = pip_error_excerpt(&raw);+ assert_eq!(+ excerpt,+ "ERROR: Could not install packages due to an OSError: [WinError 5] access is denied: 'C:\\\\Users\\\\ddrob\\\\ComfyUI\\\\venv\\\\Lib\\\\site-packages\\\\cv2\\\\cv2.pyd'\nCheck the permissions."+ );+ let msg = diagnose_pip_error(&raw);+ assert!(msg.contains("cv2.pyd"), "the file pip could not write is not named: {msg}");+ assert!(!msg.contains("Requirement already satisfied"), "the head of the log is back: {msg}");+ assert!(!msg.contains("[notice]"), "pip's own update notice is no part of the failure: {msg}");+ }++ #[test]+ fn an_output_without_an_error_line_keeps_its_end() {+ let raw = format!("{}\nRuntimeError: the wheel is corrupt", "Traceback line\n".repeat(100));+ let excerpt = pip_error_excerpt(&raw);+ assert!(excerpt.ends_with("RuntimeError: the wheel is corrupt"), "got: {excerpt}");+ assert!(excerpt.chars().count() <= 400);+ }+#[test]fn diagnose_truncates_giant_stderr_to_400_chars_snippet_block() {let huge: String = "x".repeat(2000);diff --git a/src/components/create/experimental/Stage.tsx b/src/components/create/experimental/Stage.tsxindex 94ca49c1..9b60aac5 100644--- a/src/components/create/experimental/Stage.tsx+++ b/src/components/create/experimental/Stage.tsx@@ -549,31 +549,24 @@ const BUSY_DESCRIPTION = {function CapabilityCard({ cap }: { cap: 'rmbg' | 'inpaint-nodes' | 'dwpose' }) {const { installCapability } = useCreateExp()- const [installing, setInstalling] = useState(false)- const [status, setStatus] = useState('')- const [err, setErr] = useState<string | null>(null)- const abortRef = useRef<AbortController | null>(null)+ // The run lives outside the card, like a bundle install: a failure must+ // still be readable after a trip to another mode (the box, 03.10.2026: the+ // reason for a failed node pack install was gone on the first mode switch).+ // It stays until the user closes it or tries again.+ const runKey = `capability:${cap}`+ const { status, err, running: installing } = useSyncExternalStore(subscribeInstallRuns, () => getInstallRun(runKey))const copy = CAP_COPY[cap]- const run = async () => {- const ac = new AbortController()- abortRef.current = ac- setInstalling(true); setErr(null); setStatus('Starting…')- try {- // On success the capability flips true and Stage swaps this card for the input slot.- await installCapability(cap, setStatus, ac.signal)- } catch (e) {+ // On success the capability flips true and Stage swaps this card for the input slot.+ const run = () => startInstallRun(runKey, (onStatus, signal) =>+ installCapability(cap, onStatus, signal).catch((e: unknown) => {// A cancel is a decision, not a failure: say so plainly and add the one// thing that is not obvious, that the node install itself finishes in the// background because there is nothing to roll back.- setErr(e instanceof InstallCancelled- ? 'Cancelled. Any node install already running finishes on its own in the background.'- : e instanceof Error ? e.message : String(e))- } finally {- setInstalling(false)- abortRef.current = null- }- }+ throw e instanceof InstallCancelled+ ? new Error('Cancelled. Any node install already running finishes on its own in the background.')+ : e+ }))return (<EmptyState@@ -584,8 +577,8 @@ function CapabilityCard({ cap }: { cap: 'rmbg' | 'inpaint-nodes' | 'dwpose' }) {><InstallCardBodyrun={run} installing={installing} status={status} err={err}- onDismiss={() => setErr(null)}- onCancel={() => abortRef.current?.abort()}+ onDismiss={() => clearInstallRun(runKey)}+ onCancel={() => cancelInstallRun(runKey)}/></EmptyState>)diff --git a/src/components/create/experimental/__tests__/capability-install-error-stays.test.tsx b/src/components/create/experimental/__tests__/capability-install-error-stays.test.tsxnew file mode 100644index 00000000..11d0077b--- /dev/null+++ b/src/components/create/experimental/__tests__/capability-install-error-stays.test.tsx@@ -0,0 +1,75 @@+// @vitest-environment jsdom+/**+ * The box, 03.10.2026: "Download & install" for the cutout node pack failed,+ * and the reason was gone as soon as the mode changed. The card kept it in its+ * own state, so leaving Cutout threw it away. It now lives with the run+ * (lib/model-install-runs.ts) and stays until the user closes it or tries+ * again.+ */+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'+import { render, cleanup, screen, fireEvent, act } from '@testing-library/react'++const installCapability = vi.hoisted(() => vi.fn())++vi.mock('../CreateContext', () => ({+ useCreateExp: () => ({+ generate: vi.fn(), cancel: vi.fn(), makeVoice: vi.fn(), connected: true, modelsLoaded: true,+ cloudAvailable: false, uploadImage: vi.fn(), installCapability,+ }),+}))++import { Stage } from '../Stage'+import { useCreateStore } from '../../../../stores/createStore'+import { resetInstallRuns } from '../../../../lib/model-install-runs'++const REASON = "Failed to install ComfyUI-RMBG: ERROR: Could not install packages due to an OSError: [WinError 5] access is denied: 'cv2.pyd'"++function stage() {+ return render(<Stage displayed={undefined} onOpenMaskEditor={vi.fn()} onEditResult={vi.fn()} onAnimateResult={vi.fn()} onFullscreen={vi.fn()} />)+}++beforeEach(() => {+ resetInstallRuns()+ installCapability.mockReset()+ useCreateStore.setState({+ backend: 'local', isGenerating: false, gallery: [], source: null, mask: null,+ caps: { rmbg: false, 'inpaint-nodes': true, dwpose: true },+ imageModelList: [{ name: 'sd_turbo.safetensors', type: 'sd15' }],+ } as never)+ useCreateStore.getState().setIntent('removebg')+})+afterEach(() => cleanup())++describe('a failed node pack install on the Cutout card', () => {+ it('keeps its reason through a mode switch and back', async () => {+ installCapability.mockRejectedValue(new Error(REASON))+ const first = stage()+ await act(async () => { fireEvent.click(screen.getByText('Download & install')) })+ expect(screen.getByText(REASON)).toBeTruthy()++ // Off to Image and back to Cutout: the card is unmounted in between.+ first.unmount()+ act(() => { useCreateStore.getState().setIntent('image') })+ act(() => { useCreateStore.getState().setIntent('removebg') })+ stage()+ expect(screen.getByText(REASON)).toBeTruthy()+ })++ it('goes away when the user closes it', async () => {+ installCapability.mockRejectedValue(new Error(REASON))+ stage()+ await act(async () => { fireEvent.click(screen.getByText('Download & install')) })+ fireEvent.click(screen.getByLabelText('Dismiss'))+ expect(screen.queryByText(REASON)).toBeNull()+ })++ it('goes away on the next try', async () => {+ installCapability.mockRejectedValueOnce(new Error(REASON)).mockReturnValue(new Promise(() => undefined))+ stage()+ await act(async () => { fireEvent.click(screen.getByText('Download & install')) })+ expect(screen.getByText(REASON)).toBeTruthy()+ await act(async () => { fireEvent.click(screen.getByText('Download & install')) })+ expect(screen.queryByText(REASON)).toBeNull()+ expect(screen.getByText('Setting this up for you')).toBeTruthy()+ })+})