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
Retry the desktop ownership id read that a concurrent publish denies (#9459)
Daniel Hanb2f02efb5b2c
diff --git a/studio/backend/tests/test_imatrix_gguf_filtering.py b/studio/backend/tests/test_imatrix_gguf_filtering.pyindex 9c6d802616c..b09f7278f52 100644--- a/studio/backend/tests/test_imatrix_gguf_filtering.py+++ b/studio/backend/tests/test_imatrix_gguf_filtering.py@@ -157,9 +157,7 @@ def test_the_models_dir_scanner_does_not_publish_an_imatrix_only_child(tmp_path)(repo / "Qwen3.8-27B-UD-Q4_K_XL.gguf").write_bytes(b"GGUF" + b"0" * 64)rows = _scan_models_dir(tmp_path)- assert [(Path(r.path).name, r.model_format) for r in rows] == [- ("Qwen3.8-27B-GGUF", "gguf")- ]+ assert [(Path(r.path).name, r.model_format) for r in rows] == [("Qwen3.8-27B-GGUF", "gguf")]def test_an_mmproj_only_child_still_decides_presence(tmp_path):@@ -217,9 +215,7 @@ def test_the_lmstudio_scanner_does_not_publish_an_imatrix_only_model_dir(tmp_pat(model_dir / "Qwen3.8-27B-UD-Q4_K_XL.gguf").write_bytes(b"GGUF" + b"0" * 64)rows = _scan_lmstudio_dir(tmp_path)- assert [(r.model_id, r.model_format) for r in rows] == [- ("unsloth/Qwen3.8-27B-GGUF", "gguf")- ]+ assert [(r.model_id, r.model_format) for r in rows] == [("unsloth/Qwen3.8-27B-GGUF", "gguf")]def test_a_downloaded_imatrix_is_not_a_downloaded_gguf_repo(tmp_path):diff --git a/studio/backend/tests/test_mmproj_placement_policy.py b/studio/backend/tests/test_mmproj_placement_policy.pyindex 8fb370a9f3a..d9b0c48a6ca 100644--- a/studio/backend/tests/test_mmproj_placement_policy.py+++ b/studio/backend/tests/test_mmproj_placement_policy.py@@ -1202,9 +1202,9 @@ def test_the_speculative_reserve_is_normalized_before_anything_prices_it(tmp_patsource = Path(inspect.getsourcefile(LlamaCppBackend)).read_text()normalize_at = source.index("if _draft_cpu_no_embedded and mtp_overhead_fn is not None:")probe_at = source.index("_mm_mtp_on_gpu = _mtp_will_engage and not _draft_cpu_no_embedded")- assert normalize_at < probe_at, (- "the CPU-drafter reserve must be normalized before the projector probe prices it"- )+ assert (+ normalize_at < probe_at+ ), "the CPU-drafter reserve must be normalized before the projector probe prices it"def test_a_shared_device_beside_a_discrete_one_does_not_veto_the_pin(tmp_path):diff --git a/studio/src-tauri/src/desktop_backend_owner.rs b/studio/src-tauri/src/desktop_backend_owner.rsindex b127de8544f..4e38f484410 100644--- a/studio/src-tauri/src/desktop_backend_owner.rs+++ b/studio/src-tauri/src/desktop_backend_owner.rs@@ -328,8 +328,46 @@ fn is_blank_studio_root_id(raw: &str) -> bool {raw.trim().is_empty()}+// create_studio_root_id_file hard-links the temp file onto the real path and then+// removes the temp name, so for the width of that unlink there are two names for one+// file. Windows denies an open of EITHER name while a delete is pending, with+// ERROR_ACCESS_DENIED rather than a sharing violation, so a concurrent reader is turned+// away from a file that is intact on both sides of the window.+const STUDIO_ROOT_ID_READ_ATTEMPTS: usize = 5;+const STUDIO_ROOT_ID_READ_BACKOFF: Duration = Duration::from_millis(20);++fn read_studio_root_id_to_string(path: &Path) -> std::io::Result<String> {+ read_studio_root_id_to_string_with(path, |path| std::fs::read_to_string(path))+}++fn read_studio_root_id_to_string_with(+ path: &Path,+ mut read: impl FnMut(&Path) -> std::io::Result<String>,+) -> std::io::Result<String> {+ let mut attempt = 0;+ loop {+ match read(path) {+ Ok(raw) => return Ok(raw),+ // Absent is an answer, not a transient state.+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Err(error),+ Err(error) if is_transient_read_denial(&error) => {+ attempt += 1;+ if attempt >= STUDIO_ROOT_ID_READ_ATTEMPTS {+ return Err(error);+ }+ std::thread::sleep(STUDIO_ROOT_ID_READ_BACKOFF);+ }+ Err(error) => return Err(error),+ }+ }+}++fn is_transient_read_denial(error: &std::io::Error) -> bool {+ matches!(error.kind(), std::io::ErrorKind::PermissionDenied)+}+fn read_studio_root_id_file(path: &Path) -> Result<Option<String>, String> {- let raw = match std::fs::read_to_string(path) {+ let raw = match read_studio_root_id_to_string(path) {Ok(raw) => raw,Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),Err(error) => {@@ -1817,6 +1855,68 @@ mod tests {let _ = std::fs::remove_dir_all(path.parent().unwrap().parent().unwrap());}+ // Injected reader, not a real race: the window is one unlink wide, so a test that+ // raced for it would pass on any machine that never entered it.+ fn denial() -> std::io::Error {+ std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Access is denied.")+ }++ #[test]+ fn a_reader_denied_while_the_temp_name_is_unlinked_still_gets_the_id() {+ let mut seen = 0;+ let raw = read_studio_root_id_to_string_with(Path::new("id"), |_| {+ seen += 1;+ if seen < 3 {+ Err(denial())+ } else {+ Ok("an-id".to_string())+ }+ })+ .unwrap();+ assert_eq!(raw, "an-id");+ assert_eq!(seen, 3, "the read should have been retried until it succeeded");+ }++ #[test]+ fn a_denial_that_never_clears_is_still_reported() {+ // Bounded: a genuinely unreadable file must not become a hang or a silent+ // success, and the last error is what the caller sees.+ let mut seen = 0;+ let error = read_studio_root_id_to_string_with(Path::new("id"), |_| {+ seen += 1;+ Err(denial())+ })+ .unwrap_err();+ assert_eq!(error.kind(), std::io::ErrorKind::PermissionDenied);+ assert_eq!(seen, STUDIO_ROOT_ID_READ_ATTEMPTS);+ }++ #[test]+ fn a_missing_id_is_answered_without_waiting() {+ // A first start has no id file; retrying would add backoff to every cold+ // launch for the same answer.+ let mut seen = 0;+ let error = read_studio_root_id_to_string_with(Path::new("id"), |_| {+ seen += 1;+ Err(std::io::Error::from(std::io::ErrorKind::NotFound))+ })+ .unwrap_err();+ assert_eq!(error.kind(), std::io::ErrorKind::NotFound);+ assert_eq!(seen, 1, "a missing id must not be retried");+ }++ #[test]+ fn an_unrelated_read_error_is_not_retried() {+ let mut seen = 0;+ let error = read_studio_root_id_to_string_with(Path::new("id"), |_| {+ seen += 1;+ Err(std::io::Error::from(std::io::ErrorKind::InvalidData))+ })+ .unwrap_err();+ assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);+ assert_eq!(seen, 1, "only a denial is treated as transient");+ }+#[test]fn blank_studio_root_id_is_replaced_like_a_missing_one() {// Blank IDs are interrupted writes and must not block later starts.