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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: isolate Pi process from Tauri Metal/GPU context (fixes bundled bun hang)
Louis Beaumontc9681558ce0b
diff --git a/Cargo.lock b/Cargo.lockindex 4683168a9..bffeb181b 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5518,7 +5518,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.143"+version = "0.3.144"dependencies = ["anyhow","bytemuck",@@ -5574,7 +5574,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.143"+version = "0.3.144"dependencies = ["accessibility","accessibility-sys",@@ -5615,7 +5615,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.143"+version = "0.3.144"dependencies = ["anyhow","chrono",@@ -5640,7 +5640,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.143"+version = "0.3.144"dependencies = ["anyhow","chrono",@@ -5658,7 +5658,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.143"+version = "0.3.144"dependencies = ["anyhow","chrono",@@ -5679,7 +5679,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.143"+version = "0.3.144"dependencies = ["anyhow","async-trait",@@ -5740,7 +5740,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.143"+version = "0.3.144"dependencies = ["accessibility-sys","anyhow",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 1cdea290f..7d352b0f1 100755--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -8097,7 +8097,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.0.464"+version = "2.0.465"dependencies = ["anyhow","arboard",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex eb4386984..dfaa81dec 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "2.0.465"+version = "2.0.466"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rsindex 85fc6a7c1..9a6800035 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs@@ -38,18 +38,9 @@ fn build_command_for_path(path: &str) -> Command {/// On Unix, pi's shebang is `#!/usr/bin/env node` but screenpipe only bundles/// bun. Run `bun <pi_path>` so it works without node installed.-///-/// NOTE: We prefer the user's system bun over the bundled bun for running Pi.-/// The bundled bun (in the .app bundle) causes Pi to hang during startup due to-/// Metal/GPU native module loading in the sandboxed app context. The system bun-/// (installed at ~/.bun/bin/bun) does not have this issue.#[cfg(not(windows))]fn build_command_for_path(path: &str) -> Command {- if let Some(bun) = find_user_bun_executable() {- let mut cmd = Command::new(bun);- cmd.arg(path);- cmd- } else if let Some(bun) = find_bun_executable() {+ if let Some(bun) = find_bun_executable() {let mut cmd = Command::new(bun);cmd.arg(path);cmd@@ -74,11 +65,7 @@ fn build_async_command_for_path(path: &str) -> tokio::process::Command {/// bun. Run `bun <pi_path>` so it works without node installed.#[cfg(not(windows))]fn build_async_command_for_path(path: &str) -> tokio::process::Command {- if let Some(bun) = find_user_bun_executable() {- let mut cmd = tokio::process::Command::new(bun);- cmd.arg(path);- cmd- } else if let Some(bun) = find_bun_executable() {+ if let Some(bun) = find_bun_executable() {let mut cmd = tokio::process::Command::new(bun);cmd.arg(path);cmd@@ -661,6 +648,26 @@ pub async fn pi_start_inner(}}+ // On macOS, isolate the child process from the parent Tauri app's Metal/GPU+ // context. Without this, Pi's native modules (clipboard-darwin-universal) try+ // to initialize Metal and deadlock on inherited Mach ports from the webview.+ // setsid() creates a new session; closing FDs 3+ drops inherited Mach ports.+ #[cfg(target_os = "macos")]+ {+ use std::os::unix::process::CommandExt;+ unsafe {+ cmd.pre_exec(|| {+ libc::setsid();+ let max_fd = libc::sysconf(libc::_SC_OPEN_MAX) as i32;+ let max_fd = if max_fd > 0 { max_fd.min(4096) } else { 1024 };+ for fd in 3..max_fd {+ libc::close(fd);+ }+ Ok(())+ });+ }+ }+// Spawn processlet mut child = cmd.spawn().map_err(|e| format!("Failed to spawn pi: {}", e))?;@@ -709,7 +716,7 @@ pub async fn pi_start_inner(let event_type = serde_json::from_str::<Value>(&line).ok().and_then(|v| v.get("type").and_then(|t| t.as_str()).map(|s| s.to_string()));- info!("Pi stdout #{} (pid {}): type={}", line_count, pid,+ debug!("Pi stdout #{} (pid {}): type={}", line_count, pid,event_type.as_deref().unwrap_or("non-json"));// Try to parse as JSON and emit event@@ -751,7 +758,7 @@ pub async fn pi_start_inner(// Try to parse as JSON RPC event and forward like stdoutif let Ok(event) = serde_json::from_str::<Value>(&line) {let event_type = event.get("type").and_then(|t| t.as_str()).unwrap_or("?");- info!("Pi stderr JSON: type={}", event_type);+ debug!("Pi stderr JSON: type={}", event_type);if let Err(e) = app_handle.emit("pi_event", &event) {error!("Failed to emit pi_event from stderr: {}", e);}@@ -760,7 +767,7 @@ pub async fn pi_start_inner(}} else {// Not JSON — log as plain stderr- info!("Pi stderr (non-JSON): {}", &line[..line.len().min(200)]);+ debug!("Pi stderr (non-JSON): {}", &line[..line.len().min(200)]);}let _ = app_handle.emit("pi_log", &line);}@@ -1027,35 +1034,6 @@ pub fn kill(pid: u32) -> Result<(), String> {Ok(())}-/// Find the user's system-installed bun (skipping the bundled app bun).-/// The bundled bun in the .app bundle causes Pi to hang on macOS due to-/// Metal/GPU native module loading. Prefer the user's own bun for running Pi.-fn find_user_bun_executable() -> Option<String> {- let home = dirs::home_dir()- .map(|h| h.to_string_lossy().to_string())- .unwrap_or_default();-- #[cfg(unix)]- let paths = vec![- format!("{}/.bun/bin/bun", home),- "/opt/homebrew/bin/bun".to_string(),- "/usr/local/bin/bun".to_string(),- ];-- #[cfg(windows)]- let paths = vec![- format!("{}\\.bun\\bin\\bun.exe", home),- format!("{}\\AppData\\Local\\bun\\bin\\bun.exe", home),- ];-- for path in paths {- if std::path::Path::new(&path).exists() {- return Some(path);- }- }- None-}-/// Find bun executable (shared by pi_install and ensure_pi_installed_background)fn find_bun_executable() -> Option<String> {// First check next to our own executable (bundled bun in AppData/Local/screenpipe/)