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: fix login failures during slow startup (#11289)
Nilay525acb8394bb
diff --git a/studio/src-tauri/src/desktop_auth.rs b/studio/src-tauri/src/desktop_auth.rsindex ed89b5c8ddf..19f3188e19a 100644--- a/studio/src-tauri/src/desktop_auth.rs+++ b/studio/src-tauri/src/desktop_auth.rs@@ -5,6 +5,7 @@ use log::{info, warn};use reqwest::Client;use serde::{Deserialize, Serialize};use std::path::{Path, PathBuf};+use std::time::Duration;static DESKTOP_AUTH_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());@@ -195,6 +196,11 @@ fn classify_auth_send_error(error: reqwest::Error) -> AuthError {}}+// Long enough for a backend still importing its ML stack at startup.+fn desktop_auth_client() -> Result<Client, reqwest::Error> {+ crate::loopback_http::client(Duration::from_secs(30))+}+fn should_retry_with_discovered_port(source: PortSource, error: &AuthError) -> bool {matches!((source, error),@@ -365,8 +371,7 @@ async fn desktop_auth_inner(if backend.source == PortSource::Discovered {diagnostics::record_attached_external_backend(diagnostics, backend.port);}- let client = crate::loopback_http::client(std::time::Duration::from_secs(5))- .map_err(|e| format!("Desktop auth failed: {}", e))?;+ let client = desktop_auth_client().map_err(|e| format!("Desktop auth failed: {}", e))?;for attempt in 0..2 {if attempt == 1 {@@ -408,6 +413,10 @@ mod tests {}async fn login_server_with_body(status: &str, body: &str) -> u16 {+ delayed_login_server(status, body, Duration::ZERO).await+ }++ async fn delayed_login_server(status: &str, body: &str, delay: Duration) -> u16 {let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();let port = listener.local_addr().unwrap().port();let status = status.to_string();@@ -417,6 +426,7 @@ mod tests {let (mut stream, _) = listener.accept().await.unwrap();let mut buffer = [0; 1024];let _ = stream.read(&mut buffer).await.unwrap();+ tokio::time::sleep(delay).await;let response = format!("HTTP/1.1 {status}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",body.len()@@ -427,6 +437,17 @@ mod tests {port}+ #[tokio::test]+ async fn desktop_login_waits_for_a_slow_response() {+ let body = r#"{"access_token":"access","refresh_token":"refresh"}"#;+ let port = delayed_login_server("200 OK", body, Duration::from_secs(6)).await;+ let response =+ exchange_desktop_secret(&desktop_auth_client().unwrap(), port, "desktop-secret")+ .await+ .unwrap();+ assert!(matches!(response, Some(DesktopAuthResponse::Tokens { .. })));+ }+#[tokio::test]async fn desktop_login_required_is_a_success_without_tokens() {let body = r#"{"login_required":true,"login_mode":"multi"}"#;