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(diagnostics): a hung nvidia-smi froze the panel that exists to diagnose it
purplea43b01c534d6
diff --git a/src-tauri/src/commands/gpu.rs b/src-tauri/src/commands/gpu.rsindex dc907686..f015912c 100644--- a/src-tauri/src/commands/gpu.rs+++ b/src-tauri/src/commands/gpu.rs@@ -48,10 +48,10 @@ fn run_cmd(program: &str, args: &[&str]) -> Option<String> {cmd.args(args);#[cfg(target_os = "windows")]cmd.creation_flags(CREATE_NO_WINDOW);- match cmd.output() {- Ok(out) if out.status.success() => Some(String::from_utf8_lossy(&out.stdout).to_string()),- _ => None,- }+ // Bounded — nvidia-smi on a wedged driver, wmic on a busy WMI service and+ // lspci on a slow bus scan all block indefinitely, and Command::output()+ // would wait for all of it while the hardware picker shows a spinner.+ crate::commands::shell::output_bounded(cmd, std::time::Duration::from_secs(5))}fn detect_nvidia() -> Vec<DetectedGpu> {diff --git a/src-tauri/src/commands/health.rs b/src-tauri/src/commands/health.rsindex 9e0c476b..15ef8b40 100644--- a/src-tauri/src/commands/health.rs+++ b/src-tauri/src/commands/health.rs@@ -13,7 +13,7 @@use crate::state::AppState;use serde::Serialize;-use std::process::{Command, Stdio};+use std::process::Command;use std::time::Duration;use sysinfo::{Disks, System};use tauri::State;@@ -176,16 +176,14 @@ fn query_nvidia_vram() -> Option<(f64, f64)> {cmd.args(["--query-gpu=memory.total,memory.free","--format=csv,noheader,nounits",- ])- .stdout(Stdio::piped())- .stderr(Stdio::piped());+ ]);#[cfg(target_os = "windows")]cmd.creation_flags(CREATE_NO_WINDOW);- let out = cmd.output().ok()?;- if !out.status.success() {- return None;- }- let s = String::from_utf8_lossy(&out.stdout);+ // Bounded: every OTHER probe in this report has a timeout, but this one+ // used Command::output() and a wedged driver makes nvidia-smi hang for+ // minutes — leaving the Troubleshoot panel spinning on exactly the machine+ // whose owner opened it because something was wrong.+ let s = crate::commands::shell::output_bounded(cmd, Duration::from_secs(3))?;parse_nvidia_vram_csv(&s)}diff --git a/src-tauri/src/commands/shell.rs b/src-tauri/src/commands/shell.rsindex 80c3dda1..c20ed6b7 100644--- a/src-tauri/src/commands/shell.rs+++ b/src-tauri/src/commands/shell.rs@@ -134,6 +134,40 @@ pub(crate) fn kill_tree(root: u32) {}}+/// Run a short-lived probe command with a HARD deadline and return its stdout.+///+/// `Command::output()` waits forever, and the tools this app probes with can+/// hang for real: a wedged NVIDIA driver makes `nvidia-smi` block for minutes,+/// `wmic` stalls on a busy WMI service, `lspci` can sit on a slow bus scan.+/// Those are exactly the machines whose owner opens the Troubleshoot panel or+/// the hardware picker — and an unbounded probe left both spinning with no+/// answer at all. Returns None on timeout, spawn failure or a non-zero exit.+pub(crate) fn output_bounded(mut cmd: Command, max: std::time::Duration) -> Option<String> {+ cmd.stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped());+ let mut child = cmd.spawn().ok()?;+ let (out_buf, out_done) = drain(child.stdout.take()?);+ let (_err_buf, err_done) = drain(child.stderr.take()?);+ let deadline = std::time::Instant::now() + max;+ loop {+ match child.try_wait() {+ Ok(Some(status)) => {+ settle(&out_done, &err_done, std::time::Duration::from_millis(200));+ return if status.success() { Some(captured_text(&out_buf)) } else { None };+ }+ Ok(None) => {+ if std::time::Instant::now() >= deadline {+ kill_tree(child.id());+ let _ = child.kill();+ let _ = child.wait();+ return None;+ }+ std::thread::sleep(std::time::Duration::from_millis(25));+ }+ Err(_) => return None,+ }+ }+}+/// Give the reader threads a moment to hit EOF after the child is gone. Never/// joins them: a grandchild can keep the pipe open (a spawned dev server), and/// joining would hang the command instead of returning what we already have.@@ -315,6 +349,32 @@ mod tests {assert_eq!(text, "hello\n");}+ #[cfg(unix)]+ #[test]+ fn a_bounded_probe_returns_output_and_gives_up_on_a_hang() {+ use std::process::Command;+ use std::time::{Duration, Instant};++ let mut ok = Command::new("bash");+ ok.arg("-c").arg("echo '12288, 4096'");+ assert_eq!(+ output_bounded(ok, Duration::from_secs(5)).as_deref().map(str::trim),+ Some("12288, 4096"),+ );++ // A wedged probe must not hold the caller hostage.+ let mut hang = Command::new("bash");+ hang.arg("-c").arg("sleep 30");+ let started = Instant::now();+ assert!(output_bounded(hang, Duration::from_millis(400)).is_none());+ assert!(started.elapsed() < Duration::from_secs(5), "the deadline did not bite");++ // A non-zero exit reads as "no answer", same as before.+ let mut fails = Command::new("bash");+ fails.arg("-c").arg("exit 3");+ assert!(output_bounded(fails, Duration::from_secs(5)).is_none());+ }+#[cfg(unix)]#[test]fn a_timeout_takes_the_grandchildren_with_it() {