The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(cloud): offload local model backends in cloud mode; lazy-start Whisper
purpled63fcd372f13
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rsindex 34ff4b49..14020a23 100644--- a/src-tauri/src/commands/process.rs+++ b/src-tauri/src/commands/process.rs@@ -1782,3 +1782,104 @@ mod tests {assert_eq!(probe_comfy_gpu(""), Some(false));}}++/// Cloud mode = cloud-only inference: release every LOCAL model backend so+/// nothing sits in RAM/VRAM while the app talks to the cloud (David 2026-07-11).+/// Best-effort per backend — one failing step never blocks the others. Local+/// mode reloads everything LAZILY on first use, so this is safe to run on every+/// switch into cloud and on launch-in-cloud. (LM Studio is offloaded separately+/// by the frontend via `lmstudio_unload_model("--all")`.)+#[tauri::command]+pub fn offload_local_models(state: State<'_, AppState>) -> Result<serde_json::Value, String> {+ let mut freed: Vec<&str> = Vec::new();++ // 1) Whisper STT — the python server holds the model resident; stopping it+ // frees ~360 MB. transcribe() lazily restarts it on the next local use.+ if let Ok(mut w) = state.whisper.lock() {+ if w.is_running() {+ w.stop();+ freed.push("whisper");+ }+ }++ // 2) Bundled llama.cpp chat + embeddings sidecars (managed GGUF in RAM).+ // Both are graceful no-ops when not running, and lazy-start on next use.+ if crate::commands::engine::stop_bundled_engine(state.clone()).is_ok() {+ freed.push("bundled-engine");+ }+ if crate::commands::engine::stop_bundled_embed(state.clone()).is_ok() {+ freed.push("bundled-embed");+ }++ // 3) Ollama — keep `serve` up (cheap, idle) but evict every loaded model.+ if offload_ollama_loaded_models() {+ freed.push("ollama");+ }++ // 4) ComfyUI — free VRAM/RAM without killing the server, so the next local+ // render just reloads the checkpoint (no slow process restart).+ if free_comfyui_memory() {+ freed.push("comfyui");+ }++ println!("[Offload] cloud mode — released local model backends: {:?}", freed);+ Ok(serde_json::json!({ "offloaded": freed }))+}++/// Evict every model Ollama currently holds in memory via `keep_alive: 0`,+/// leaving `ollama serve` running (idle serve is cheap). Best-effort.+fn offload_ollama_loaded_models() -> bool {+ let client = match reqwest::blocking::Client::builder()+ .timeout(std::time::Duration::from_secs(2))+ .build()+ {+ Ok(c) => c,+ Err(_) => return false,+ };+ let ps = match client+ .get("http://localhost:11434/api/ps")+ .send()+ .ok()+ .and_then(|r| r.json::<serde_json::Value>().ok())+ {+ Some(v) => v,+ None => return false,+ };+ let models = match ps.get("models").and_then(|m| m.as_array()) {+ Some(a) => a,+ None => return false,+ };+ let mut any = false;+ for m in models {+ if let Some(name) = m+ .get("name")+ .or_else(|| m.get("model"))+ .and_then(|n| n.as_str())+ {+ let _ = client+ .post("http://localhost:11434/api/generate")+ .json(&serde_json::json!({ "model": name, "keep_alive": 0 }))+ .send();+ any = true;+ }+ }+ any+}++/// Ask ComfyUI to unload checkpoints and free memory, keeping the server up so+/// the next local render reloads on demand. Best-effort (default port 8188).+fn free_comfyui_memory() -> bool {+ let client = match reqwest::blocking::Client::builder()+ .timeout(std::time::Duration::from_secs(2))+ .build()+ {+ Ok(c) => c,+ Err(_) => return false,+ };+ client+ .post("http://localhost:8188/free")+ .json(&serde_json::json!({ "unload_models": true, "free_memory": true }))+ .send()+ .map(|r| r.status().is_success())+ .unwrap_or(false)+}diff --git a/src-tauri/src/commands/whisper.rs b/src-tauri/src/commands/whisper.rsindex 2c6296bf..a4d07498 100644--- a/src-tauri/src/commands/whisper.rs+++ b/src-tauri/src/commands/whisper.rs@@ -7,7 +7,7 @@ use std::path::PathBuf;use std::os::windows::process::CommandExt;use base64::Engine;-use tauri::{Manager, State};+use tauri::{AppHandle, Manager, State};use tracing::{error, info};use crate::state::AppState;@@ -132,6 +132,11 @@ impl WhisperServer {.map_err(|_| "Whisper transcription timed out".to_string())}+ /// Whether the whisper server child is currently running (model resident).+ pub fn is_running(&self) -> bool {+ self.process.is_some()+ }+pub fn stop(&mut self) {if let Some(ref mut stdin) = self.stdin_tx {let _ = stdin.write_all(b"{\"action\":\"quit\"}\n");@@ -159,7 +164,7 @@ pub fn whisper_status(state: State<'_, AppState>) -> Result<serde_json::Value, S}#[tauri::command]-pub fn transcribe(audio_base64: String, content_type: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {+pub fn transcribe(app: AppHandle, audio_base64: String, content_type: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {let audio_bytes = base64::engine::general_purpose::STANDARD.decode(&audio_base64).map_err(|e| format!("base64 decode: {}", e))?;@@ -186,6 +191,20 @@ pub fn transcribe(audio_base64: String, content_type: String, state: State<'_, Alet audio_path = tmp_file.to_string_lossy().replace('\\', "/");println!("[Whisper] Transcribing: {} ({:.1} KB)", audio_path, audio_bytes.len() as f64 / 1024.0);+ // Lazy-start Whisper on first use — it is no longer pre-started at launch+ // (it kept ~360 MB resident even in Cloud mode). Block until the server is+ // spawned; send_command below then waits for the model to finish loading.+ {+ let needs_start = state.whisper.lock().map(|w| w.process.is_none()).unwrap_or(true);+ if needs_start {+ let python_bin = state.python_bin.lock().unwrap().clone();+ if python_bin.is_empty() {+ return Err("Whisper unavailable: no Python runtime detected. Install Python in the setup step, then retry.".to_string());+ }+ auto_start_whisper_sync(&app, &python_bin, &state.whisper);+ }+ }+// Send to persistent whisper serverlet result = {let mut whisper = state.whisper.lock().unwrap();diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 2175c6c6..3b2d62dd 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -109,6 +109,7 @@ fn main() {commands::process::set_comfyui_host,commands::process::set_ollama_host,commands::process::get_ollama_host,+ commands::process::offload_local_models,// Installationcommands::install::install_comfyui,commands::install::install_comfyui_status,@@ -349,13 +350,16 @@ fn main() {});}- // ─── Auto-start services ───- let state = app.state::<AppState>();-- // Off the main thread: auto_start_comfyui's find_comfyui_path()- // walks $HOME, which can take minutes on a big disk — on the main- // thread that stalls window creation and the app "runs with no- // window" until the scan finishes (2.5.6 regression, re-fixed).+ // ─── Auto-start services (off the main thread) ───+ // find_comfyui_path() walks $HOME, which can take minutes on a big+ // disk — on the main thread that stalls window creation and the app+ // "runs with no window" until the scan finishes (2.5.6 regression).+ // Ollama/ComfyUI here are just SERVERS; no model loads until first use.+ //+ // Whisper STT is intentionally NOT pre-started any more: it used to+ // load its model (~360 MB) at launch even in Cloud mode. It now starts+ // LAZILY on the first transcription (whisper::transcribe) and is+ // released by offload_local_models whenever the app is in Cloud mode.{let handle = app.handle().clone();std::thread::spawn(move || {@@ -365,22 +369,6 @@ fn main() {});}- let handle = app.handle().clone();- let python_bin = state.python_bin.lock().unwrap().clone();- let whisper = state.whisper.clone();- std::thread::spawn(move || {- // Whisper auto-start is best-effort and pip-installs faster-whisper- // on first launch — silently skip when no Python is on the box, so- // a fresh install doesn't fail the whole startup. The user can- // install Python later via the ComfyUI flow; whisper picks up on- // next launch.- if !python_bin.is_empty() {- commands::whisper::auto_start_whisper_sync(&handle, &python_bin, &whisper);- } else {- println!("[Whisper] Skipping auto-start: no Python yet (install via ComfyUI step)");- }- });-Ok(())}).run(tauri::generate_context!())diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 07683601..dff53c5d 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -107,6 +107,19 @@ export function AppShell() {}}, [appMode])+ // ── Cloud = cloud-only: release every LOCAL model backend so nothing sits+ // in RAM/VRAM while inference runs in the cloud (David 2026-07-11). Whisper+ // STT, the bundled llama.cpp sidecar + embeddings, Ollama-loaded models and+ // ComfyUI VRAM are freed by offload_local_models; LM Studio via its own JIT+ // unload (`lms unload --all`). Local mode reloads LAZILY on first use+ // (chat/voice/render) — nothing is pre-warmed. Fires on entering cloud+ // (switch OR launch-in-cloud); local mode is a no-op.+ useEffect(() => {+ if (!isTauri() || appMode !== 'cloud') return+ backendCall('offload_local_models').catch(() => {})+ backendCall('lmstudio_unload_model', { model: '--all' }).catch(() => {})+ }, [appMode])+// Push the persisted ComfyUI GPU override to the backend on boot + change// (rhodium92 AMD, 2026-07-01). The backend resets to "auto" each launch, so// without this a saved force-cpu / force-gpu wouldn't apply until the user