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: run -h and desktop-capabilities at once on a capability cache miss (#15672)

Daniel Hanf8dad3fced19
diff --git a/studio/src-tauri/src/preflight.rs b/studio/src-tauri/src/preflight.rs
index 27a0bd03ca1..85220cd2b81 100644
--- a/studio/src-tauri/src/preflight.rs
+++ b/studio/src-tauri/src/preflight.rs
@@ -983,6 +983,128 @@ exit 1
remove_managed_capability_cache();
}
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn a_cache_miss_runs_help_and_the_capability_probe_at_once() {
+ use std::fs;
+
+ let _cache_guard = MANAGED_CAPABILITY_CACHE_TEST_LOCK.lock().await;
+ let _cache_home = ManagedCapabilityCacheHome::new("miss-overlap");
+ remove_managed_capability_cache();
+ // Each probe waits (up to 5s) to see the other one start, so only overlapping probes pass.
+ let fake = fake_cli(
+ "miss-overlap",
+ r#"#!/bin/sh
+printf '%s\n' "$*" >> "$0.calls"
+wait_for() {
+ i=0
+ while [ ! -f "$1" ]; do
+ i=$((i + 1))
+ if [ "$i" -gt 50 ]; then exit 42; fi
+ sleep 0.1
+ done
+}
+if [ "$1" = "-h" ]; then
+ : > "$0.help_started"
+ wait_for "$0.cap_started"
+ exit 0
+fi
+if [ "$1" = "studio" ] && [ "$2" = "desktop-capabilities" ] && [ "$3" = "--json" ]; then
+ : > "$0.cap_started"
+ wait_for "$0.help_started"
+ 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();
+ assert!(matches!(
+ probe_managed_bin(bin.clone()).await,
+ ManagedProbe::Ready { .. }
+ ));
+ let calls = fs::read_to_string(bin.with_extension("calls")).unwrap();
+ assert_eq!(calls.matches("-h\n").count(), 1);
+ assert_eq!(calls.matches("studio desktop-capabilities --json\n").count(), 1);
+
+ fs::write(bin.with_extension("calls"), "").unwrap();
+ fs::write(bin.with_extension("cap_started"), "").unwrap();
+ assert!(matches!(
+ probe_managed_bin(bin.clone()).await,
+ ManagedProbe::Ready { .. }
+ ));
+ assert_eq!(fs::read_to_string(bin.with_extension("calls")).unwrap(), "-h\n");
+
+ remove_managed_capability_cache();
+ }
+
+ #[cfg(unix)]
+ #[tokio::test]
+ async fn a_cache_miss_still_lets_a_failing_help_decide_over_a_capability_answer() {
+ use std::fs;
+
+ let _cache_guard = MANAGED_CAPABILITY_CACHE_TEST_LOCK.lock().await;
+ let _cache_home = ManagedCapabilityCacheHome::new("miss-help-decides");
+ remove_managed_capability_cache();
+ let fake = fake_cli(
+ "miss-help-decides",
+ r#"#!/bin/sh
+printf '%s\n' "$*" >> "$0.calls"
+if [ "$1" = "-h" ]; then
+ if [ -f "$0.modeh" ]; then exit 42; fi
+ exit 0
+fi
+if [ "$1" = "studio" ] && [ "$2" = "desktop-capabilities" ] && [ "$3" = "--json" ]; then
+ if [ -f "$0.modecap" ]; then exit 42; fi
+ 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");
+ let modecap = bin.with_extension("modecap");
+ let reason_of = |probe: ManagedProbe| match probe {
+ ManagedProbe::Stale { reason, .. } => reason,
+ other => panic!("expected Stale, got {other:?}"),
+ };
+
+ // `-h` fails while desktop-capabilities answers: still unusable.
+ fs::write(&modeh, "broken").unwrap();
+ assert_eq!(
+ reason_of(probe_managed_bin(bin.clone()).await),
+ "cli_unusable"
+ );
+
+ fs::remove_file(&modeh).unwrap();
+ fs::write(&calls, "").unwrap();
+ assert!(matches!(
+ probe_managed_bin(bin.clone()).await,
+ ManagedProbe::Ready { .. }
+ ));
+ assert!(fs::read_to_string(&calls)
+ .unwrap()
+ .contains("studio desktop-capabilities --json\n"));
+ remove_managed_capability_cache();
+
+ fs::write(&modeh, "broken").unwrap();
+ fs::write(&modecap, "broken").unwrap();
+ assert_eq!(
+ reason_of(probe_managed_bin(bin.clone()).await),
+ "cli_unusable"
+ );
+
+ fs::remove_file(&modeh).unwrap();
+ assert_eq!(
+ reason_of(probe_managed_bin(bin.clone()).await),
+ "desktop_capability_probe_failed"
+ );
+
+ remove_managed_capability_cache();
+ }
+
#[cfg(unix)]
#[tokio::test]
async fn a_passing_launch_help_probe_stands_in_for_the_first_preflight_only() {
diff --git a/studio/src-tauri/src/preflight/managed.rs b/studio/src-tauri/src/preflight/managed.rs
index 94afb8f8301..fe112b51f66 100644
--- a/studio/src-tauri/src/preflight/managed.rs
+++ b/studio/src-tauri/src/preflight/managed.rs
@@ -1172,13 +1172,31 @@ pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {
};
}
- // Always run `-h` first: a matching fingerprint does not prove the CLI still launches.
- // A passing launch probe stands in; a failed one is asked again.
- let cli_probe = if launch_cli_probe_passed(&bin).await {
- Ok(true)
+ // Fingerprint taken before any probe, so an answer is cached against the tree the CLI read.
+ let fingerprint_before = managed_bin_fingerprint(&bin);
+ let cache_hit = fingerprint_before
+ .as_ref()
+ .is_some_and(|fingerprint| read_cached_capability(fingerprint).is_some());
+
+ // `-h` decides first: a fingerprint does not prove the CLI launches, and a failing `-h` wins over
+ // a capability answer. Awaited before any spawn below, which would find its guard held.
+ let launch_help_passed = launch_cli_probe_passed(&bin).await;
+ let help_probe = async {
+ if launch_help_passed {
+ Ok(true)
+ } else {
+ run_cli_probe(&bin, &["-h"]).await
+ }
+ };
+
+ // A cache miss overlaps both Python starts; one task, so the spawns take the guard in turn.
+ let (cli_probe, capability_probe) = if cache_hit {
+ (help_probe.await, None)
} else {
- run_cli_probe(&bin, &["-h"]).await
+ let (help, capability) = tokio::join!(help_probe, probe_cli_capability(&bin));
+ (help, Some(capability))
};
+
match cli_probe {
// The CLI was never asked, so do not report a broken install.
Err(error) => {
@@ -1207,20 +1225,16 @@ pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {
Ok(true) => {}
}
- // Fingerprint taken before the probe, so the answer is cached against the tree the CLI read.
- let fingerprint_before = managed_bin_fingerprint(&bin);
- if let Some(fingerprint) = fingerprint_before.as_ref() {
- if read_cached_capability(fingerprint).is_some() {
- info!(
- "Managed preflight: using cached desktop capability for {:?} in {}ms",
- bin,
- started.elapsed().as_millis()
- );
- return ManagedProbe::Ready { bin };
- }
- }
+ let Some(capability_probe) = capability_probe else {
+ info!(
+ "Managed preflight: using cached desktop capability for {:?} in {}ms",
+ bin,
+ started.elapsed().as_millis()
+ );
+ return ManagedProbe::Ready { bin };
+ };
- let capability = match probe_cli_capability(&bin).await {
+ let capability = match capability_probe {
Ok(capability) => capability,
Err(error) => {
info!(