Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio desktop: start the launch preflight's CLI -h probe during setup (#15671)

Daniel Han9594abca1fe4
diff --git a/studio/src-tauri/src/main.rs b/studio/src-tauri/src/main.rs
index e882db27f1b..77a56236ca3 100644
--- a/studio/src-tauri/src/main.rs
+++ b/studio/src-tauri/src/main.rs
@@ -2406,6 +2406,8 @@ fn main() {
if let Err(error) = desktop_backend_owner::ensure_installed_studio_root_id() {
warn!("Desktop backend ownership id unavailable: {error}");
}
+ // After the staged-update reconcile, so the preflight's `-h` overlaps the webview load.
+ preflight::start_launch_cli_probe();
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
{
use tauri_plugin_deep_link::DeepLinkExt;
diff --git a/studio/src-tauri/src/preflight.rs b/studio/src-tauri/src/preflight.rs
index 05692f4209d..27a0bd03ca1 100644
--- a/studio/src-tauri/src/preflight.rs
+++ b/studio/src-tauri/src/preflight.rs
@@ -10,6 +10,7 @@ use crate::desktop_backend_owner::{
use backend::probe_existing_backends;
use log::{info, warn};
pub use managed::managed_install_ready;
+pub(crate) use managed::start_launch_cli_probe;
use managed::probe_managed_install;
use std::path::PathBuf;
use types::{BackendProbe, ManagedProbe};
@@ -24,6 +25,11 @@ pub(crate) use version::{
#[cfg(test)]
use backend::{backend_desktop_auth_status, backend_health};
#[cfg(test)]
+use managed::{
+ begin_launch_cli_probe, install_launch_cli_probe, install_launch_cli_probe_task,
+ launch_cli_probe_task,
+};
+#[cfg(test)]
use managed::probe_managed_bin;
#[cfg(test)]
use version::{
@@ -977,6 +983,124 @@ exit 1
remove_managed_capability_cache();
}
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn a_passing_launch_help_probe_stands_in_for_the_first_preflight_only() {
+ use std::fs;
+
+ let _cache_guard = MANAGED_CAPABILITY_CACHE_TEST_LOCK.lock().await;
+ let _cache_home = ManagedCapabilityCacheHome::new("launch-help");
+ remove_managed_capability_cache();
+ let fake = fake_cli(
+ "launch-help",
+ r#"#!/bin/sh
+log="$0.calls"
+modeh="$0.modeh"
+printf '%s\n' "$*" >> "$log"
+if [ "$1" = "-h" ]; then
+ if [ -f "$modeh" ]; then exit 42; fi
+ exit 0
+fi
+if [ "$1" = "studio" ] && [ "$2" = "desktop-capabilities" ] && [ "$3" = "--json" ]; then
+ printf '{"desktop_protocol_version":1,"desktop_manageability_version":2,"supports_api_only":true,"supports_provision_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_install_ok":true,"version":"2026.8.4"}'
+ exit 0
+fi
+exit 1
+"#,
+ );
+ let bin = fake.bin.clone();
+ let calls = bin.with_extension("calls");
+ let modeh = bin.with_extension("modeh");
+ assert!(matches!(probe_managed_bin(bin.clone()).await, ManagedProbe::Ready { .. }));
+
+ fs::write(&calls, "").unwrap();
+ install_launch_cli_probe(bin.clone());
+ assert!(matches!(probe_managed_bin(bin.clone()).await, ManagedProbe::Ready { .. }));
+ assert_eq!(fs::read_to_string(&calls).unwrap(), "-h\n");
+
+ fs::write(&calls, "").unwrap();
+ assert!(matches!(probe_managed_bin(bin.clone()).await, ManagedProbe::Ready { .. }));
+ assert_eq!(fs::read_to_string(&calls).unwrap(), "-h\n");
+
+ fs::write(&modeh, "broken").unwrap();
+ fs::write(&calls, "").unwrap();
+ install_launch_cli_probe(bin.clone());
+ assert!(matches!(probe_managed_bin(bin.clone()).await, ManagedProbe::Stale { .. }));
+ assert_eq!(fs::read_to_string(&calls).unwrap(), "-h\n-h\n");
+
+ fs::remove_file(&modeh).unwrap();
+ let other = fake_cli("launch-help-other", "#!/bin/sh\nexit 0\n");
+ install_launch_cli_probe(other.bin.clone());
+ fs::write(&calls, "").unwrap();
+ assert!(matches!(probe_managed_bin(bin.clone()).await, ManagedProbe::Ready { .. }));
+ assert_eq!(fs::read_to_string(&calls).unwrap(), "-h\n");
+ assert!(matches!(probe_managed_bin(other.bin.clone()).await, ManagedProbe::Stale { .. }));
+
+ remove_managed_capability_cache();
+ }
+
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn a_preflight_waits_for_a_launch_probe_holding_the_runtime_launch_guard() {
+ let _cache_guard = MANAGED_CAPABILITY_CACHE_TEST_LOCK.lock().await;
+ let _cache_home = ManagedCapabilityCacheHome::new("launch-guard");
+ remove_managed_capability_cache();
+ let fake = fake_cli(
+ "launch-guard",
+ r#"#!/bin/sh
+if [ "$1" = "-h" ]; then exit 0; fi
+if [ "$1" = "studio" ] && [ "$2" = "desktop-capabilities" ] && [ "$3" = "--json" ]; then
+ printf '{"desktop_protocol_version":1,"desktop_manageability_version":2,"supports_api_only":true,"supports_provision_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_install_ok":true,"version":"2026.8.4"}'
+ exit 0
+fi
+exit 1
+"#,
+ );
+ let other = fake_cli("launch-guard-other", "#!/bin/sh\nexit 0\n");
+
+ // A launch probe mid-spawn holds the guard: the preflight waits instead of reading busy.
+ let (acquired_tx, acquired_rx) = tokio::sync::oneshot::channel();
+ let handle = tauri::async_runtime::spawn_blocking(move || {
+ crate::process::with_studio_runtime_launch_guard(|| {
+ let _ = acquired_tx.send(());
+ std::thread::sleep(std::time::Duration::from_millis(300));
+ Ok(true)
+ })
+ });
+ acquired_rx.await.unwrap();
+ install_launch_cli_probe_task(other.bin.clone(), handle);
+ match probe_managed_bin(fake.bin.clone()).await {
+ ManagedProbe::Ready { .. } => {}
+ other => panic!("expected Ready, got {other:?}"),
+ }
+
+ // Same, while the setup thread has not handed its probe over yet.
+ let pending = begin_launch_cli_probe();
+ let (acquired_tx, acquired_rx) = tokio::sync::oneshot::channel();
+ let other_bin = other.bin.clone();
+ std::thread::spawn(move || {
+ let (held_tx, held_rx) = std::sync::mpsc::channel();
+ let handle = tauri::async_runtime::spawn_blocking(move || {
+ crate::process::with_studio_runtime_launch_guard(|| {
+ let _ = held_tx.send(());
+ std::thread::sleep(std::time::Duration::from_millis(300));
+ Ok(true)
+ })
+ });
+ held_rx.recv().unwrap();
+ let _ = acquired_tx.send(());
+ std::thread::sleep(std::time::Duration::from_millis(100));
+ let _ = pending.send(Some(launch_cli_probe_task(other_bin, handle)));
+ });
+ acquired_rx.await.unwrap();
+ match probe_managed_bin(fake.bin.clone()).await {
+ ManagedProbe::Ready { .. } => {}
+ other => panic!("expected Ready, got {other:?}"),
+ }
+
+ remove_managed_capability_cache();
+ }
+
const EXPECTED_ROOT_ID: &str =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const OTHER_ROOT_ID: &str = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
diff --git a/studio/src-tauri/src/preflight/managed.rs b/studio/src-tauri/src/preflight/managed.rs
index b9e9b0d2a95..94afb8f8301 100644
--- a/studio/src-tauri/src/preflight/managed.rs
+++ b/studio/src-tauri/src/preflight/managed.rs
@@ -1055,6 +1055,108 @@ fn working_directory_reason() -> Option<String> {
Some(context_reason(&error))
}
+pub(super) struct LaunchCliProbe {
+ bin: PathBuf,
+ started: Instant,
+ handle: tauri::async_runtime::JoinHandle<Result<bool, String>>,
+}
+
+type PendingLaunchCliProbe = tokio::sync::oneshot::Receiver<Option<LaunchCliProbe>>;
+
+/// Filled before the setup thread runs, so an early preflight still waits for its spawn.
+static LAUNCH_CLI_PROBE: std::sync::Mutex<Option<PendingLaunchCliProbe>> =
+ std::sync::Mutex::new(None);
+
+const LAUNCH_CLI_PROBE_MAX_AGE: Duration = Duration::from_secs(30);
+
+/// The first preflight for the same CLI reuses a passing `-h` from here. Off the main thread:
+/// finding the CLI touches the disk and the runtime's first use builds it.
+pub(crate) fn start_launch_cli_probe() {
+ let pending = begin_launch_cli_probe();
+ let spawned = std::thread::Builder::new()
+ .name("launch-cli-probe".to_string())
+ .spawn(move || {
+ let probe = crate::process::find_unsloth_binary()
+ .filter(|_| crate::process::managed_cli_context_error().is_none())
+ .map(spawn_launch_cli_probe);
+ let _ = pending.send(probe);
+ });
+ if let Err(error) = spawned {
+ warn!("Could not start the launch CLI probe: {error}");
+ }
+}
+
+pub(super) fn begin_launch_cli_probe() -> tokio::sync::oneshot::Sender<Option<LaunchCliProbe>> {
+ let (sender, receiver) = tokio::sync::oneshot::channel();
+ if let Ok(mut slot) = LAUNCH_CLI_PROBE.lock() {
+ *slot = Some(receiver);
+ }
+ sender
+}
+
+fn spawn_launch_cli_probe(bin: PathBuf) -> LaunchCliProbe {
+ let probe_bin = bin.clone();
+ let handle =
+ tauri::async_runtime::spawn(async move { run_cli_probe(&probe_bin, &["-h"]).await });
+ launch_cli_probe_task(bin, handle)
+}
+
+pub(super) fn launch_cli_probe_task(
+ bin: PathBuf,
+ handle: tauri::async_runtime::JoinHandle<Result<bool, String>>,
+) -> LaunchCliProbe {
+ LaunchCliProbe {
+ bin,
+ started: Instant::now(),
+ handle,
+ }
+}
+
+#[cfg(test)]
+pub(super) fn install_launch_cli_probe(bin: PathBuf) {
+ let _ = begin_launch_cli_probe().send(Some(spawn_launch_cli_probe(bin)));
+}
+
+#[cfg(test)]
+pub(super) fn install_launch_cli_probe_task(
+ bin: PathBuf,
+ handle: tauri::async_runtime::JoinHandle<Result<bool, String>>,
+) {
+ let _ = begin_launch_cli_probe().send(Some(launch_cli_probe_task(bin, handle)));
+}
+
+/// `true` only for a recent passing launch `-h` on this CLI, taken once. Any CLI's probe is
+/// awaited: its spawn holds the runtime launch guard, which a spawn beside it reads as busy.
+async fn launch_cli_probe_passed(bin: &Path) -> bool {
+ let pending = match LAUNCH_CLI_PROBE.lock() {
+ Ok(mut slot) => slot.take(),
+ Err(_) => None,
+ };
+ let Some(pending) = pending else {
+ return false;
+ };
+ let Ok(Some(probe)) = pending.await else {
+ return false;
+ };
+ let passed = matches!(probe.handle.await, Ok(Ok(true)));
+ if probe.bin != bin {
+ info!(
+ "Managed preflight: launch -h probe was for {:?}, not {:?}; not reused",
+ probe.bin, bin
+ );
+ return false;
+ }
+ let age = probe.started.elapsed();
+ let fresh = age <= LAUNCH_CLI_PROBE_MAX_AGE;
+ info!(
+ "Managed preflight: launch -h probe passed={} age={}ms reused={}",
+ passed,
+ age.as_millis(),
+ passed && fresh
+ );
+ passed && fresh
+}
+
pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {
let started = Instant::now();
@@ -1071,7 +1173,13 @@ pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {
}
// Always run `-h` first: a matching fingerprint does not prove the CLI still launches.
- match run_cli_probe(&bin, &["-h"]).await {
+ // A passing launch probe stands in; a failed one is asked again.
+ let cli_probe = if launch_cli_probe_passed(&bin).await {
+ Ok(true)
+ } else {
+ run_cli_probe(&bin, &["-h"]).await
+ };
+ match cli_probe {
// The CLI was never asked, so do not report a broken install.
Err(error) => {
info!(