Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: make get_local_api_config async to prevent main thread deadlock

Louis Beaumontc4b6d05007a2
diff --git a/apps/screenpipe-app-tauri/lib/api.ts b/apps/screenpipe-app-tauri/lib/api.ts
index 37b3e1bb2..d2f220705 100644
--- a/apps/screenpipe-app-tauri/lib/api.ts
+++ b/apps/screenpipe-app-tauri/lib/api.ts
@@ -41,10 +41,13 @@ function ensureInitialized(): Promise<void> {
try {
const { invoke } = await import("@tauri-apps/api/core");
- // Retry up to 10 times (5 seconds total) if server hasn't started yet.
+ // Retry up to 30 times (15 seconds total) if server hasn't started yet.
// The server generates the API key on startup, but the webview may load
// before it's ready — get_local_api_config returns key:null in that case.
- const MAX_RETRIES = 10;
+ // Previously 10 retries / 5s, but on heavy DBs the server can take longer,
+ // and if get_local_api_config was sync (main thread) it would deadlock with
+ // tray/window setup — now it's async but we keep a generous timeout.
+ const MAX_RETRIES = 30;
const RETRY_DELAY_MS = 500;
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 864b3c8b8..f4204612b 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -133,11 +133,15 @@ pub fn is_enterprise_build_cmd(app_handle: tauri::AppHandle) -> bool {
}
/// Get the local API auth key and port for the frontend to use.
-/// Returns immediately (no async, no disk I/O) — the key is already in memory.
-/// Returns { key: string | null, port: number, auth_enabled: bool }.
+/// Returns the local API config (key, port, auth flag).
+///
+/// IMPORTANT: This is `async` so it runs on the tokio thread pool, NOT the
+/// main thread. The webview calls this via IPC during early init — if it ran
+/// on the main thread it would deadlock with tray/window setup that also
+/// needs the main thread, causing a 5-second blank screen.
#[tauri::command]
#[specta::specta]
-pub fn get_local_api_config(
+pub async fn get_local_api_config(
app_handle: tauri::AppHandle,
) -> serde_json::Value {
use crate::recording::RecordingState;