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(vision): dynamic monitor management - stop/start recording on plug/unplug
Louis Beaumont28e5c2477b55
diff --git a/Cargo.lock b/Cargo.lockindex 7bc39d969..1a40331b0 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -6642,7 +6642,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","bytemuck",@@ -6695,7 +6695,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.126"+version = "0.3.127"dependencies = ["accessibility","accessibility-sys",@@ -6746,7 +6746,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","chrono",@@ -6770,7 +6770,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","chrono",@@ -6788,7 +6788,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","image",@@ -6803,7 +6803,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","async-trait",@@ -6874,7 +6874,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.126"+version = "0.3.127"dependencies = ["accessibility-sys","anyhow",diff --git a/Cargo.toml b/Cargo.tomlindex 6e53f5472..8b1e3ebd2 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -6,7 +6,7 @@ exclude = ["apps/screenpipe-app-tauri/src-tauri"]resolver = "2"[workspace.package]-version = "0.3.127"+version = "0.3.128"authors = ["louis030195 <[email protected]>"]description = ""repository = "https://github.com/screenpipe/screenpipe"diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 90bc03e8e..3bae5e819 100755--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -9007,7 +9007,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.0.340"+version = "2.0.341"dependencies = ["anyhow","async-stream",@@ -9100,7 +9100,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","bytemuck",@@ -9148,7 +9148,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.126"+version = "0.3.127"dependencies = ["accessibility","accessibility-sys",@@ -9199,7 +9199,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","chrono",@@ -9223,7 +9223,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","chrono",@@ -9239,7 +9239,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","image 0.25.9",@@ -9254,7 +9254,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.126"+version = "0.3.127"dependencies = ["anyhow","async-trait",@@ -9320,7 +9320,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.126"+version = "0.3.127"dependencies = ["accessibility-sys","anyhow",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex d525cd6f4..6963c6189 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.341"+version = "2.0.342"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/crates/screenpipe-apple-intelligence/src/lib.rs b/crates/screenpipe-apple-intelligence/src/lib.rsindex 12d047bcc..ad8b4ba00 100644--- a/crates/screenpipe-apple-intelligence/src/lib.rs+++ b/crates/screenpipe-apple-intelligence/src/lib.rs@@ -15,8 +15,5 @@ mod engine;#[cfg(all(target_os = "macos", target_arch = "aarch64"))]pub use engine::*;-#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]-compile_error!(- "screenpipe-apple-intelligence requires macOS on Apple Silicon (aarch64). \- Foundation Models framework is only available on macOS 26+ with Apple Silicon."-);+// On non-macOS/non-aarch64 this crate is a no-op.+// The feature gate in screenpipe-server ensures this code is never actually used.diff --git a/crates/screenpipe-audio/src/core/mod.rs b/crates/screenpipe-audio/src/core/mod.rsindex bc8dde018..953a1e6a6 100644--- a/crates/screenpipe-audio/src/core/mod.rs+++ b/crates/screenpipe-audio/src/core/mod.rs@@ -12,7 +12,7 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};use std::sync::Arc;use std::time::{Duration, SystemTime, UNIX_EPOCH};use stream::AudioStream;-use tracing::{error, info, warn};+use tracing::{error, info};lazy_static! {// Global fallback timestamp for backward compatibilitydiff --git a/crates/screenpipe-server/src/video.rs b/crates/screenpipe-server/src/video.rsindex 726322fdf..40122fccf 100644--- a/crates/screenpipe-server/src/video.rs+++ b/crates/screenpipe-server/src/video.rs@@ -3,14 +3,13 @@ use crossbeam::queue::ArrayQueue;use dashmap::DashMap;use image::ImageFormat::{self};use screenpipe_core::{find_ffmpeg_path, Language};-use screenpipe_vision::monitor::get_monitor_by_id;use screenpipe_vision::{capture_screenshot_by_window::WindowFilters, continuous_capture, CaptureResult, OcrEngine,};use std::borrow::Cow;use std::path::PathBuf;use std::process::Stdio;-use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};+use std::sync::atomic::{AtomicU64, Ordering};use std::sync::Arc;use std::time::Duration;use tokio::io::AsyncBufReadExt;@@ -104,13 +103,11 @@ pub struct VideoCapture {/// Tracks which frames were written to video and at what offset./// Used by DB insertion to ensure correct offset mapping.pub frame_write_tracker: Arc<FrameWriteTracker>,- // Add handles to tasks so we can monitor their status+ // Task handles — aborted on Drop for clean shutdowncapture_thread_handle: tokio::task::JoinHandle<()>,queue_thread_handle: tokio::task::JoinHandle<()>,video_thread_handle: tokio::task::JoinHandle<()>,- monitor_check_handle: tokio::task::JoinHandle<()>, // New handle for monitor check- monitor_available: Arc<AtomicBool>, // Flag to track monitor availability- monitor_id: u32, // Store monitor ID for availability checks+ monitor_id: u32,}impl VideoCapture {@@ -142,8 +139,6 @@ impl VideoCapture {let frame_write_tracker = Arc::new(FrameWriteTracker::new());let new_chunk_callback = Arc::new(new_chunk_callback);let new_chunk_callback_clone = Arc::clone(&new_chunk_callback);- let monitor_available = Arc::new(AtomicBool::new(true));- let monitor_available_clone = monitor_available.clone();info!("Starting VideoCapture for monitor {}, max queue size: {}, fps: {}",@@ -155,9 +150,7 @@ impl VideoCapture {let (result_sender, mut result_receiver) = channel(512);let window_filters = Arc::new(WindowFilters::new(ignore_list, include_list, ignored_urls));- // Add parameters for monitoring restartlet capture_ocr_engine = ocr_engine.clone();- let capture_monitor_available = monitor_available.clone();let capture_window_filters = window_filters.clone();let capture_languages = languages.clone();let capture_result_sender = result_sender.clone();@@ -165,26 +158,13 @@ impl VideoCapture {let capture_unfocused = capture_unfocused_windows;let capture_activity_feed = activity_feed;- // Store task handles for health monitoringlet capture_thread = tokio::spawn(async move {info!(- "Starting continuous_capture task for monitor {}",+ "Starting continuous_capture for monitor {}",monitor_id);loop {- // Check if monitor is available before starting capture- if !capture_monitor_available.load(Ordering::SeqCst) {- warn!(- "Monitor {} is not available, waiting before starting capture",- monitor_id- );- tokio::time::sleep(Duration::from_secs(5)).await;- continue;- }-- info!("Starting continuous_capture for monitor {}", monitor_id);-match continuous_capture(capture_result_sender.clone(),capture_interval,@@ -197,19 +177,21 @@ impl VideoCapture {).await{- Ok(_) => warn!(- "continuous_capture task for monitor {} completed unexpectedly",- monitor_id- ),- Err(e) => error!(- "continuous_capture task for monitor {} failed with error: {}",- monitor_id, e- ),+ Ok(_) => {+ info!(+ "continuous_capture for monitor {} completed",+ monitor_id+ );+ break;+ }+ Err(e) => {+ error!(+ "continuous_capture for monitor {} failed: {}, restarting in 5s",+ monitor_id, e+ );+ tokio::time::sleep(Duration::from_secs(5)).await;+ }}-- // If we get here, either the task completed or failed- // Wait before attempting restart- tokio::time::sleep(Duration::from_secs(5)).await;}});@@ -348,34 +330,6 @@ impl VideoCapture {);});- // Add monitor availability check task- let monitor_check_handle = tokio::spawn(async move {- info!(- "Starting monitor availability check for monitor {}",- monitor_id- );- let mut check_interval = tokio::time::interval(Duration::from_secs(10));-- loop {- check_interval.tick().await;-- // Check if monitor is available- let monitor_exists = (get_monitor_by_id(monitor_id).await).is_some();-- // Update availability flag- let current_availability = monitor_available_clone.load(Ordering::SeqCst);- if monitor_exists != current_availability {- monitor_available_clone.store(monitor_exists, Ordering::SeqCst);-- if monitor_exists {- info!("Monitor {} is now available", monitor_id);- } else {- warn!("Monitor {} is no longer available", monitor_id);- }- }- }- });-VideoCapture {video_frame_queue,ocr_frame_queue,@@ -383,42 +337,26 @@ impl VideoCapture {capture_thread_handle: capture_thread,queue_thread_handle: queue_thread,video_thread_handle: video_thread,- monitor_check_handle,- monitor_available,monitor_id,}}- // Modify check_health to include monitor check taskpub fn check_health(&self) -> bool {let capture_ok = !self.capture_thread_handle.is_finished();let queue_ok = !self.queue_thread_handle.is_finished();let video_ok = !self.video_thread_handle.is_finished();- let monitor_check_ok = !self.monitor_check_handle.is_finished();- let monitor_available = self.monitor_available.load(Ordering::SeqCst);if !capture_ok {- error!("continuous_capture task has terminated unexpectedly");+ error!("monitor {}: capture task terminated", self.monitor_id);}if !queue_ok {- error!("queue processing task has terminated unexpectedly");+ error!("monitor {}: queue task terminated", self.monitor_id);}if !video_ok {- error!("save_frames_as_video task has terminated unexpectedly");+ error!("monitor {}: video task terminated", self.monitor_id);}- if !monitor_check_ok {- error!("monitor check task has terminated unexpectedly");- }- if !monitor_available {- warn!("monitor {} is currently unavailable", self.monitor_id);- }-- capture_ok && queue_ok && video_ok && monitor_check_ok- }- // Add method to check if monitor is available- pub fn is_monitor_available(&self) -> bool {- self.monitor_available.load(Ordering::SeqCst)+ capture_ok && queue_ok && video_ok}}@@ -431,7 +369,6 @@ impl Drop for VideoCapture {self.capture_thread_handle.abort();self.queue_thread_handle.abort();self.video_thread_handle.abort();- self.monitor_check_handle.abort();}}diff --git a/crates/screenpipe-server/src/vision_manager/monitor_watcher.rs b/crates/screenpipe-server/src/vision_manager/monitor_watcher.rsindex 2aa82fb50..9fe0a6cfd 100644--- a/crates/screenpipe-server/src/vision_manager/monitor_watcher.rs+++ b/crates/screenpipe-server/src/vision_manager/monitor_watcher.rs@@ -19,7 +19,7 @@ pub async fn start_monitor_watcher(vision_manager: Arc<VisionManager>) -> anyhow// Stop existing watcher if anystop_monitor_watcher().await?;- info!("Starting monitor watcher (polling every 2 seconds)");+ info!("Starting monitor watcher (polling every 5 seconds)");let handle = tokio::spawn(async move {// Track monitors that were disconnected (for reconnection detection)@@ -47,7 +47,7 @@ pub async fn start_monitor_watcher(vision_manager: Arc<VisionManager>) -> anyhowloop {// Only poll when runningif vision_manager.status().await != VisionManagerStatus::Running {- tokio::time::sleep(Duration::from_secs(2)).await;+ tokio::time::sleep(Duration::from_secs(5)).await;continue;}@@ -118,8 +118,8 @@ pub async fn start_monitor_watcher(vision_manager: Arc<VisionManager>) -> anyhow}}- // Poll every 2 seconds- tokio::time::sleep(Duration::from_secs(2)).await;+ // Poll every 5 seconds — monitor connect/disconnect is not latency-sensitive+ tokio::time::sleep(Duration::from_secs(5)).await;}});