Skip to content

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.

fix(agent+stt): the two remaining long blockers ran on the main thread

purple67483df92915
diff --git a/src-tauri/src/commands/agent.rs b/src-tauri/src/commands/agent.rs
index 4997d72d..4e96a230 100644
--- a/src-tauri/src/commands/agent.rs
+++ b/src-tauri/src/commands/agent.rs
@@ -5,7 +5,7 @@ use std::process::{Command, Stdio};
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
-use tauri::State;
+use tauri::{AppHandle, Manager, State};
use crate::state::AppState;
@@ -266,13 +266,33 @@ mod path_tests {
}
}
+/// Runs on the blocking pool: the poll loop below waits for the Python process
+/// for up to `timeout_ms`, and a sync #[command] would spend all of that on the
+/// Tauri main thread with the window frozen (same class as install.rs and the
+/// built-in engine). The shell tool next door already did it this way.
#[tauri::command]
-pub fn execute_code(
+pub async fn execute_code(
+ app: AppHandle,
code: String,
timeout: Option<u64>,
#[allow(non_snake_case)] chatId: Option<String>,
#[allow(non_snake_case)] workingDirectory: Option<String>,
- state: State<'_, AppState>,
+) -> Result<serde_json::Value, String> {
+ tauri::async_runtime::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ execute_code_blocking(code, timeout, chatId, workingDirectory, &state)
+ })
+ .await
+ .map_err(|e| format!("Code execution task failed to run: {e}"))?
+}
+
+#[allow(non_snake_case)]
+pub(crate) fn execute_code_blocking(
+ code: String,
+ timeout: Option<u64>,
+ chatId: Option<String>,
+ workingDirectory: Option<String>,
+ state: &State<'_, AppState>,
) -> Result<serde_json::Value, String> {
let timeout_ms = timeout.unwrap_or(30000);
diff --git a/src-tauri/src/commands/remote.rs b/src-tauri/src/commands/remote.rs
index 55051b27..cfe787a1 100644
--- a/src-tauri/src/commands/remote.rs
+++ b/src-tauri/src/commands/remote.rs
@@ -620,7 +620,7 @@ async fn handle_agent_tool(
let code = body.args.get("code").and_then(|v| v.as_str()).unwrap_or("").to_string();
let timeout = body.args.get("timeout").and_then(|v| v.as_u64());
if code.is_empty() { Err("code_execute needs a non-empty `code` argument.".into()) }
- else { crate::commands::agent::execute_code(code, timeout, chat_id.clone(), None, app_state) }
+ else { crate::commands::agent::execute_code_blocking(code, timeout, chat_id.clone(), None, &app_state) }
}
"web_search" => {
let query = body.args.get("query").and_then(|v| v.as_str()).unwrap_or("").to_string();
diff --git a/src-tauri/src/commands/whisper.rs b/src-tauri/src/commands/whisper.rs
index 5c9942fe..69dd3439 100644
--- a/src-tauri/src/commands/whisper.rs
+++ b/src-tauri/src/commands/whisper.rs
@@ -233,7 +233,29 @@ fn whisper_package_installed(state: &AppState) -> bool {
}
#[tauri::command]
-pub fn transcribe(app: AppHandle, audio_base64: String, content_type: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {
+pub async fn transcribe(
+ app: AppHandle,
+ audio_base64: String,
+ content_type: String,
+) -> Result<serde_json::Value, String> {
+ // On the first dictation this starts the whisper server and waits for the
+ // model — up to five minutes — and every transcription after that blocks for
+ // up to 60 s. As a sync #[command] all of that froze the Tauri main thread,
+ // so the window locked up for the whole take.
+ tauri::async_runtime::spawn_blocking(move || {
+ let state = app.state::<AppState>();
+ transcribe_blocking(&app, audio_base64, content_type, &state)
+ })
+ .await
+ .map_err(|e| format!("Transcription task failed to run: {e}"))?
+}
+
+fn transcribe_blocking(
+ 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))?;
@@ -276,7 +298,7 @@ pub fn transcribe(app: AppHandle, audio_base64: String, content_type: String, st
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)?;
+ auto_start_whisper_sync(app, &python_bin, &state.whisper)?;
}
}