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: auto-destructor (#1104)
tribhuwanc7db0a30e752
diff --git a/screenpipe-server/src/auto_destruct.rs b/screenpipe-server/src/auto_destruct.rsindex f2e55df8a..80a7d802e 100644--- a/screenpipe-server/src/auto_destruct.rs+++ b/screenpipe-server/src/auto_destruct.rs@@ -2,21 +2,33 @@ use std::process::Command;use std::time::Duration;use tokio::time::sleep;-use tracing::info;+use tracing::{debug, info};#[cfg(target_os = "windows")]-use windows::Win32::Foundation::{CloseHandle, HANDLE};+use windows::Win32::Foundation::{CloseHandle, HANDLE, STILL_ACTIVE};#[cfg(target_os = "windows")]-use windows::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_INFORMATION};+use windows::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_INFORMATION, GetExitCodeProcess};#[cfg(target_os = "windows")]fn is_process_alive(pid: u32) -> bool {unsafe {- let process: HANDLE = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid).unwrap();+ let process: HANDLE = match OpenProcess(PROCESS_QUERY_INFORMATION, false, pid) {+ Ok(handle) => handle,+ Err(e) => {+ debug!("Failed to open process with PID ({}): {:?}", pid, e);+ return false;+ }+ };if process.is_invalid() {return false;}- CloseHandle(process);- true+ let mut exit_code: u32 = 0;+ let result = GetExitCodeProcess(process, &mut exit_code);+ CloseHandle(process).expect("Failed to close process handle");+ if result.is_err() {+ debug!("Failed to get exit code for process with PID ({})", pid);+ return false;+ }+ exit_code == STILL_ACTIVE.0 as u32}}@@ -28,7 +40,7 @@ pub async fn watch_pid(pid: u32) -> bool {{// Try Windows API firstif !is_process_alive(pid) {- println!("process {} not found via windows api", pid);+ debug!("Process ({}) not found via windows api", pid);return true;}@@ -52,7 +64,7 @@ pub async fn watch_pid(pid: u32) -> bool {let pid_alive = String::from_utf8_lossy(&pid_output.stdout).contains(&pid.to_string());let app_alive = !String::from_utf8_lossy(&app_output.stdout).is_empty();- println!("pid alive: {}, app alive: {}", pid_alive, app_alive);+ info!("pid alive: {}, app alive: {}", pid_alive, app_alive);if !pid_alive || !app_alive {return true;diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rsindex 2b7d1ad4b..afaea086f 100644--- a/screenpipe-server/src/bin/screenpipe-server.rs+++ b/screenpipe-server/src/bin/screenpipe-server.rs@@ -505,9 +505,6 @@ async fn main() -> anyhow::Result<()> {error!("continuous recording error: {:?}", e);}}-- drop(vision_runtime);- drop(audio_runtime);})};@@ -851,7 +848,7 @@ async fn main() -> anyhow::Result<()> {// sleep for 5 secondstokio::time::sleep(std::time::Duration::from_secs(5)).await;if watch_pid(pid).await {- info!("watched pid {} has stopped, initiating shutdown", pid);+ info!("Watched pid ({}) has stopped, initiating shutdown", pid);let _ = shutdown_tx_clone.send(());}});@@ -928,6 +925,11 @@ async fn main() -> anyhow::Result<()> {}}+ tokio::task::block_in_place(|| {+ drop(vision_runtime);+ drop(audio_runtime);+ });+h.shutdown();info!("shutdown complete");