From 861ae69ebc7b1212df53a958fcaa59897fff510f Mon Sep 17 00:00:00 2001 From: IanShaw027 <131567472+IanShaw027@users.noreply.github.com> Date: Thu, 5 Feb 2026 14:06:57 +0800 Subject: [PATCH] fix(desktop): fix macOS orphaned process cleanup on startup The previous implementation used `killall opencode-cli` which doesn't match the actual process name. The binary is named `opencode`, not `opencode-cli`. This caused orphaned processes to accumulate across app restarts, leading to: - Memory leak (observed 5 opencode processes consuming 1.3GB RAM) - WebView white screen when system memory pressure kills the render process Changes: - Use `pkill -f` to match processes by full path instead of process name - Clean up all three process types: opencode, openwrk, openwork-server - Add comments explaining the purpose of the cleanup --- packages/desktop/src-tauri/src/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/desktop/src-tauri/src/lib.rs b/packages/desktop/src-tauri/src/lib.rs index d309b918b66..b4d5a94df11 100644 --- a/packages/desktop/src-tauri/src/lib.rs +++ b/packages/desktop/src-tauri/src/lib.rs @@ -281,10 +281,23 @@ pub fn run() { ) .expect("Failed to export typescript bindings"); + // Kill any orphaned processes from previous runs on macOS + // This prevents memory accumulation from zombie processes #[cfg(all(target_os = "macos", not(debug_assertions)))] - let _ = std::process::Command::new("killall") - .arg("opencode-cli") - .output(); + { + // Kill opencode server processes + let _ = std::process::Command::new("pkill") + .args(["-f", "OpenWork.app/Contents/MacOS/opencode"]) + .output(); + // Kill openwrk daemon processes + let _ = std::process::Command::new("pkill") + .args(["-f", "OpenWork.app/Contents/MacOS/openwrk"]) + .output(); + // Kill openwork-server processes + let _ = std::process::Command::new("pkill") + .args(["-f", "OpenWork.app/Contents/MacOS/openwork-server"]) + .output(); + } let mut builder = tauri::Builder::default() .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {