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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio desktop: ask desktop-capabilities in the launch probe on a capability cache miss (#15823)
Daniel Hanec051ae23780
diff --git a/studio/src-tauri/src/preflight.rs b/studio/src-tauri/src/preflight.rsindex 85220cd2b81..7887997dba4 100644--- a/studio/src-tauri/src/preflight.rs+++ b/studio/src-tauri/src/preflight.rs@@ -26,8 +26,8 @@ pub(crate) use version::{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,+ begin_launch_cli_probe, install_launch_cli_probe, install_launch_cli_probe_like_setup,+ install_launch_cli_probe_task, launch_cli_probe_task,};#[cfg(test)]use managed::probe_managed_bin;@@ -1161,6 +1161,77 @@ exit 1remove_managed_capability_cache();}+ #[cfg(unix)]+ #[tokio::test]+ async fn a_launch_probe_on_a_cache_miss_answers_the_capability_probe_too() {+ use std::fs;++ let _cache_guard = MANAGED_CAPABILITY_CACHE_TEST_LOCK.lock().await;+ let _cache_home = ManagedCapabilityCacheHome::new("launch-capability");+ remove_managed_capability_cache();+ let fake = fake_cli(+ "launch-capability",+ r#"#!/bin/sh+printf '%s\n' "$*" >> "$0.calls"+if [ "$1" = "-h" ]; then exit 0; fi+if [ "$1" = "studio" ] && [ "$2" = "desktop-capabilities" ] && [ "$3" = "--json" ]; then+ if [ -f "$0.failonce" ]; then rm -f "$0.failonce"; 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 fail_once = bin.with_extension("failonce");+ let read_calls = || fs::read_to_string(&calls).unwrap_or_default();+ let capability_calls = || {+ read_calls()+ .matches("studio desktop-capabilities --json\n")+ .count()+ };+ let ready = |probe: ManagedProbe| matches!(probe, ManagedProbe::Ready { .. });++ // Miss at launch: asked before any preflight, which then starts no Python.+ install_launch_cli_probe_like_setup(bin.clone());+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);+ while capability_calls() == 0 && std::time::Instant::now() < deadline {+ tokio::time::sleep(std::time::Duration::from_millis(10)).await;+ }+ assert_eq!(capability_calls(), 1, "{}", read_calls());+ assert!(ready(probe_managed_bin(bin.clone()).await));+ assert_eq!(read_calls().matches("-h\n").count(), 1, "{}", read_calls());+ assert_eq!(capability_calls(), 1, "{}", read_calls());+ fs::write(&calls, "").unwrap();+ assert!(ready(probe_managed_bin(bin.clone()).await));+ assert_eq!(read_calls(), "-h\n");++ // Hit at launch: `-h` only.+ fs::write(&calls, "").unwrap();+ install_launch_cli_probe_like_setup(bin.clone());+ assert!(ready(probe_managed_bin(bin.clone()).await));+ assert_eq!(read_calls(), "-h\n");++ // Tree changed after the launch probe: asked again.+ remove_managed_capability_cache();+ fs::write(&calls, "").unwrap();+ install_launch_cli_probe_like_setup(bin.clone());+ fs::write(fake.dir.join("uv.lock"), "changed").unwrap();+ assert!(ready(probe_managed_bin(bin.clone()).await));+ assert_eq!(capability_calls(), 2, "{}", read_calls());++ // A failed launch capability probe: asked again.+ remove_managed_capability_cache();+ fs::write(&calls, "").unwrap();+ fs::write(&fail_once, "").unwrap();+ install_launch_cli_probe_like_setup(bin.clone());+ assert!(ready(probe_managed_bin(bin.clone()).await));+ assert_eq!(capability_calls(), 2, "{}", read_calls());++ remove_managed_capability_cache();+ }+#[cfg(unix)]#[tokio::test]async fn a_preflight_waits_for_a_launch_probe_holding_the_runtime_launch_guard() {diff --git a/studio/src-tauri/src/preflight/managed.rs b/studio/src-tauri/src/preflight/managed.rsindex fe112b51f66..b92c541b4f8 100644--- a/studio/src-tauri/src/preflight/managed.rs+++ b/studio/src-tauri/src/preflight/managed.rs@@ -1059,6 +1059,15 @@ pub(super) struct LaunchCliProbe {bin: PathBuf,started: Instant,handle: tauri::async_runtime::JoinHandle<Result<bool, String>>,+ capability: Option<LaunchCapabilityProbe>,+}++type CapabilityProbeResult = Result<Option<DesktopCapability>, String>;++/// The capability answer a launch probe took on a cache miss, with the tree it was asked against.+struct LaunchCapabilityProbe {+ fingerprint: ManagedBinFingerprint,+ answer: tokio::sync::oneshot::Receiver<CapabilityProbeResult>,}type PendingLaunchCliProbe = tokio::sync::oneshot::Receiver<Option<LaunchCliProbe>>;@@ -1078,7 +1087,10 @@ pub(crate) fn start_launch_cli_probe() {.spawn(move || {let probe = crate::process::find_unsloth_binary().filter(|_| crate::process::managed_cli_context_error().is_none())- .map(spawn_launch_cli_probe);+ .map(|bin| {+ let miss = capability_cache_miss(&bin);+ spawn_launch_cli_probe(bin, miss)+ });let _ = pending.send(probe);});if let Err(error) = spawned {@@ -1094,11 +1106,37 @@ pub(super) fn begin_launch_cli_probe() -> tokio::sync::oneshot::Sender<Option<Lasender}-fn spawn_launch_cli_probe(bin: PathBuf) -> LaunchCliProbe {+/// The fingerprint to ask capabilities against, when the cache has no answer for it.+fn capability_cache_miss(bin: &Path) -> Option<ManagedBinFingerprint> {+ managed_bin_fingerprint(bin).filter(|fingerprint| read_cached_capability(fingerprint).is_none())+}++fn spawn_launch_cli_probe(+ bin: PathBuf,+ capability_miss: Option<ManagedBinFingerprint>,+) -> 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)+ let Some(fingerprint) = capability_miss else {+ let handle =+ tauri::async_runtime::spawn(async move { run_cli_probe(&probe_bin, &["-h"]).await });+ return launch_cli_probe_task(bin, handle);+ };+ // One task, as in the preflight's own miss, so the two spawns take the launch guard in turn.+ let (sender, answer) = tokio::sync::oneshot::channel();+ let handle = tauri::async_runtime::spawn(async move {+ let (help, capability) = tokio::join!(+ run_cli_probe(&probe_bin, &["-h"]),+ probe_cli_capability(&probe_bin)+ );+ let _ = sender.send(capability);+ help+ });+ let mut probe = launch_cli_probe_task(bin, handle);+ probe.capability = Some(LaunchCapabilityProbe {+ fingerprint,+ answer,+ });+ probe}pub(super) fn launch_cli_probe_task(@@ -1109,12 +1147,20 @@ pub(super) fn launch_cli_probe_task(bin,started: Instant::now(),handle,+ capability: None,}}#[cfg(test)]pub(super) fn install_launch_cli_probe(bin: PathBuf) {- let _ = begin_launch_cli_probe().send(Some(spawn_launch_cli_probe(bin)));+ let _ = begin_launch_cli_probe().send(Some(spawn_launch_cli_probe(bin, None)));+}++/// What `start_launch_cli_probe` hands over for `bin`, including its cache-miss decision.+#[cfg(test)]+pub(super) fn install_launch_cli_probe_like_setup(bin: PathBuf) {+ let miss = capability_cache_miss(&bin);+ let _ = begin_launch_cli_probe().send(Some(spawn_launch_cli_probe(bin, miss)));}#[cfg(test)]@@ -1125,18 +1171,28 @@ pub(super) fn install_launch_cli_probe_task(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 {+#[derive(Default)]+struct LaunchProbeReuse {+ help_passed: bool,+ /// Only when asked against the tree the preflight sees.+ capability: Option<DesktopCapability>,+}++/// The launch probe's reusable answers for `bin`, taken once. Any CLI's probe is awaited:+/// its spawns hold the runtime launch guard, which a spawn beside them reads as busy.+async fn take_launch_cli_probe(+ bin: &Path,+ fingerprint: Option<&ManagedBinFingerprint>,+) -> LaunchProbeReuse {let pending = match LAUNCH_CLI_PROBE.lock() {Ok(mut slot) => slot.take(),Err(_) => None,};let Some(pending) = pending else {- return false;+ return LaunchProbeReuse::default();};let Ok(Some(probe)) = pending.await else {- return false;+ return LaunchProbeReuse::default();};let passed = matches!(probe.handle.await, Ok(Ok(true)));if probe.bin != bin {@@ -1144,7 +1200,7 @@ async fn launch_cli_probe_passed(bin: &Path) -> bool {"Managed preflight: launch -h probe was for {:?}, not {:?}; not reused",probe.bin, bin);- return false;+ return LaunchProbeReuse::default();}let age = probe.started.elapsed();let fresh = age <= LAUNCH_CLI_PROBE_MAX_AGE;@@ -1154,7 +1210,25 @@ async fn launch_cli_probe_passed(bin: &Path) -> bool {age.as_millis(),passed && fresh);- passed && fresh+ if !(passed && fresh) {+ return LaunchProbeReuse::default();+ }+ let mut capability = None;+ if let Some(launch) = probe.capability {+ let same_tree = fingerprint == Some(&launch.fingerprint);+ // Only an answer: a failed or unasked probe is asked again, as on a miss without one.+ if let Ok(Ok(Some(answer))) = launch.answer.await {+ capability = same_tree.then_some(answer);+ }+ info!(+ "Managed preflight: launch desktop-capabilities probe reused={}",+ capability.is_some()+ );+ }+ LaunchProbeReuse {+ help_passed: true,+ capability,+ }}pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {@@ -1180,7 +1254,8 @@ pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {// `-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 launch = take_launch_cli_probe(&bin, fingerprint_before.as_ref()).await;+ let launch_help_passed = launch.help_passed;let help_probe = async {if launch_help_passed {Ok(true)@@ -1192,6 +1267,9 @@ pub(super) async fn probe_managed_bin(bin: PathBuf) -> ManagedProbe {// 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 if let Some(capability) = launch.capability {+ drop(help_probe);+ (Ok(true), Some(Ok(Some(capability))))} else {let (help, capability) = tokio::join!(help_probe, probe_cli_capability(&bin));(help, Some(capability))