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
Bump app to v2.0.470, CLI to v0.3.145
Louis Beaumont300d588c65a1
diff --git a/Cargo.toml b/Cargo.tomlindex 10928a2f6..7b2d345a4 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.144"+version = "0.3.145"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 1358a64a1..83478f418 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.468"+version = "2.0.469"dependencies = ["anyhow","arboard",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex b86fbc520..4c03b0fee 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.469"+version = "2.0.470"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/crates/screenpipe-audio/src/core/device.rs b/crates/screenpipe-audio/src/core/device.rsindex be57242b3..566cf5933 100644--- a/crates/screenpipe-audio/src/core/device.rs+++ b/crates/screenpipe-audio/src/core/device.rs@@ -120,30 +120,37 @@ whereFut: std::future::Future<Output = Result<T>>,{let mut retries = 0;- let mut delay_ms = 10; // Start with 10ms delay+ let mut delay_ms = 500; // Start with 500ms delay to let Metal/GPU settleloop {match operation().await {Ok(value) => return Ok(value),Err(e) => {if retries >= max_retries {+ tracing::error!(+ "ScreenCaptureKit failed after {} retries: {}",+ max_retries,+ e+ );return Err(anyhow!("Max retries reached: {}", e));}// Add some jitter to prevent synchronized retriesuse rand::{rng, Rng};- let jitter = rng().random_range(0..=10) as u64;+ let jitter = rng().random_range(0..=50) as u64;let delay = std::time::Duration::from_millis(delay_ms + jitter);tracing::warn!(- "ScreenCaptureKit host error, retrying in {}ms: {}",+ "ScreenCaptureKit host error (attempt {}/{}), retrying in {}ms: {}",+ retries + 1,+ max_retries,delay_ms + jitter,e);tokio::time::sleep(delay).await;retries += 1;- delay_ms = std::cmp::min(delay_ms * 2, 1000); // Exponential backoff, max 1s+ delay_ms = std::cmp::min(delay_ms * 2, 3000); // Exponential backoff, max 3s}}}@@ -152,13 +159,13 @@ where/// Gets the ScreenCaptureKit host with retry mechanism#[cfg(target_os = "macos")]async fn get_screen_capture_host() -> Result<cpal::Host> {- // necessary hack because this is unreliable+ // necessary hack because this is unreliable, especially during Metal/GPU initwith_retry(|| async {cpal::host_from_id(cpal::HostId::ScreenCaptureKit).map_err(|e| anyhow!("Failed to get ScreenCaptureKit host: {}", e))},- 3,+ 6,).await}@@ -197,8 +204,18 @@ pub async fn get_cpal_device_and_config(#[cfg(target_os = "macos")]if is_output_device {- if let Ok(screen_capture_host) = get_screen_capture_host().await {- devices = screen_capture_host.input_devices()?;+ match get_screen_capture_host().await {+ Ok(screen_capture_host) => {+ devices = screen_capture_host.input_devices()?;+ }+ Err(e) => {+ tracing::warn!(+ "ScreenCaptureKit unavailable for output device '{}': {} — \+ device lookup may fail",+ device_name,+ e+ );+ }}}@@ -273,14 +290,23 @@ pub async fn list_audio_devices() -> Result<Vec<AudioDevice>> {{// !HACK macos is supposed to use special macos feature "display capture"// ! see https://github.com/RustAudio/cpal/pull/894- if let Ok(screen_capture_host) = get_screen_capture_host().await {- for device in screen_capture_host.input_devices()? {- if let Ok(name) = device.name() {- if should_include_output_device(&name) {- devices.push(AudioDevice::new(name, DeviceType::Output));+ match get_screen_capture_host().await {+ Ok(screen_capture_host) => {+ for device in screen_capture_host.input_devices()? {+ if let Ok(name) = device.name() {+ if should_include_output_device(&name) {+ devices.push(AudioDevice::new(name, DeviceType::Output));+ }}}}+ Err(e) => {+ tracing::warn!(+ "ScreenCaptureKit unavailable when listing audio devices: {} — \+ output device list may be incomplete",+ e+ );+ }}}@@ -440,11 +466,21 @@ pub async fn default_output_device() -> Result<AudioDevice> {{// ! see https://github.com/RustAudio/cpal/pull/894// Try to get device from ScreenCaptureKit first- if let Ok(host) = get_screen_capture_host().await {- if let Some(device) = host.default_input_device() {- if let Ok(name) = device.name() {- return Ok(AudioDevice::new(name, DeviceType::Output));+ match get_screen_capture_host().await {+ Ok(host) => {+ if let Some(device) = host.default_input_device() {+ if let Ok(name) = device.name() {+ return Ok(AudioDevice::new(name, DeviceType::Output));+ }}+ tracing::warn!("ScreenCaptureKit host available but no default input device found");+ }+ Err(e) => {+ tracing::warn!(+ "ScreenCaptureKit unavailable for output audio capture: {} — \+ falling back to physical output device (may not capture system audio)",+ e+ );}}@@ -453,7 +489,12 @@ pub async fn default_output_device() -> Result<AudioDevice> {let device = host.default_output_device().ok_or_else(|| anyhow!("No default output device found"))?;- Ok(AudioDevice::new(device.name()?, DeviceType::Output))+ let name = device.name()?;+ tracing::warn!(+ "using fallback physical output device: '{}' (not ScreenCaptureKit display audio)",+ name+ );+ Ok(AudioDevice::new(name, DeviceType::Output))}// Linux without pulseaudio featurediff --git a/crates/screenpipe-server/src/core.rs b/crates/screenpipe-server/src/core.rsindex 4917a6923..07f34f5b0 100644--- a/crates/screenpipe-server/src/core.rs+++ b/crates/screenpipe-server/src/core.rs@@ -261,11 +261,13 @@ pub async fn record_video();if !video_capture.check_health() {error!(- "One or more VideoCapture tasks have terminated for monitor {}",+ "One or more VideoCapture tasks have terminated for monitor {}, triggering restart",monitor_id);- // Instead of immediately failing, log the error and continue- // This helps us diagnose which task is failing+ return Err(anyhow::anyhow!(+ "VideoCapture task(s) terminated for monitor {}",+ monitor_id+ ));}}@@ -293,7 +295,7 @@ pub async fn record_video(Some(info) => info.offset as i64,None => {video_capture.metrics.record_drop();- debug!(+ warn!("Skipping frame {} - not written to video within 5s timeout",frame.frame_number);diff --git a/crates/screenpipe-server/src/video.rs b/crates/screenpipe-server/src/video.rsindex d3f0ace14..4bc6a1ad3 100644--- a/crates/screenpipe-server/src/video.rs+++ b/crates/screenpipe-server/src/video.rs@@ -299,7 +299,7 @@ impl VideoCapture {);return false;}- debug!(+ warn!("{} queue was full, dropped oldest frame, new size: {}/{}",queue_name,queue.len(),@@ -442,7 +442,7 @@ impl VideoCapture {);return false;}- debug!(+ warn!("{} queue was full, dropped oldest frame, new size: {}/{}",queue_name,queue.len(),@@ -818,6 +818,19 @@ async fn save_frames_as_video(.await;}+ // Detect FFmpeg write failure: process_frames sets current_stdin to None+ // when writes fail. Kill the dead process so the outer loop starts a fresh chunk.+ if current_stdin.is_none() && current_ffmpeg.is_some() {+ if let Some(mut child) = current_ffmpeg.take() {+ error!(+ "FFmpeg write failure detected for monitor {}, killing process to recover",+ monitor_id+ );+ let _ = child.kill().await;+ }+ // current_ffmpeg is now None → outer loop condition triggers chunk rotation+ }+// Update total frame countframes_total = frames_total.max(frame_count);@@ -887,6 +900,8 @@ async fn process_frames(if let Some(stdin) = current_stdin.as_mut() {if let Err(e) = write_frame_with_retry(stdin, &buffer).await {error!("Failed to write frame to ffmpeg after max retries: {}", e);+ // Signal the outer loop that FFmpeg is broken by dropping stdin+ *current_stdin = None;break;}@@ -1210,4 +1225,184 @@ mod tests {assert_eq!(width, 3840, "Expected width 3840, got {}", width);assert_eq!(height, 1440, "Expected height 1440, got {}", height);}++ // --- Reliability fix tests ---++ /// Test that FrameWriteTracker returns None when frame was never written (timeout)+ #[tokio::test]+ async fn test_frame_write_tracker_timeout_returns_none() {+ let tracker = FrameWriteTracker::new();+ // Wait for a frame that was never recorded — should return None after timeout+ let result = tracker+ .wait_for_offset(42, Duration::from_millis(100))+ .await;+ assert!(+ result.is_none(),+ "Expected None for unwritten frame, got {:?}",+ result+ );+ }++ /// Test that FrameWriteTracker returns immediately for already-written frames+ #[tokio::test]+ async fn test_frame_write_tracker_immediate_return() {+ let tracker = FrameWriteTracker::new();+ tracker.record_write(7, 3, "/tmp/test.mp4".to_string());++ let result = tracker+ .wait_for_offset(7, Duration::from_secs(5))+ .await;+ assert!(result.is_some(), "Expected Some for written frame");+ let info = result.unwrap();+ assert_eq!(info.offset, 3);+ assert_eq!(info.video_path, "/tmp/test.mp4");+ }++ /// Test that FrameWriteTracker wakes waiter when frame is recorded concurrently+ #[tokio::test]+ async fn test_frame_write_tracker_concurrent_notify() {+ let tracker = Arc::new(FrameWriteTracker::new());+ let tracker_writer = tracker.clone();++ // Spawn a delayed write+ tokio::spawn(async move {+ tokio::time::sleep(Duration::from_millis(50)).await;+ tracker_writer.record_write(99, 5, "/tmp/test2.mp4".to_string());+ });++ // Wait should succeed well before the 5s timeout+ let start = std::time::Instant::now();+ let result = tracker+ .wait_for_offset(99, Duration::from_secs(5))+ .await;+ let elapsed = start.elapsed();++ assert!(result.is_some(), "Expected Some for concurrently written frame");+ assert!(+ elapsed < Duration::from_secs(1),+ "Should have woken up quickly, took {:?}",+ elapsed+ );+ }++ /// Test that writing to a dead FFmpeg process returns an error+ #[tokio::test]+ async fn test_write_to_dead_ffmpeg_fails() {+ let temp_dir = tempdir().expect("Failed to create temp dir");+ let output_path = temp_dir.path().join("test_dead.mp4");+ let output_str = output_path.to_str().unwrap();++ let mut child = start_ffmpeg_process(output_str, 1.0, "balanced")+ .await+ .expect("Failed to start FFmpeg");+ let mut stdin = child.stdin.take().expect("Failed to get stdin");++ // Kill the process+ child.kill().await.expect("Failed to kill FFmpeg");+ let _ = child.wait().await;++ // Write should fail — this is the trigger for our recovery path+ let png_data = create_test_png(640, 480);+ let result = write_frame_with_retry(&mut stdin, &png_data).await;+ assert!(+ result.is_err(),+ "Expected error writing to dead FFmpeg, got Ok"+ );+ }++ /// Test that queue overflow drops oldest frame and accepts new one+ #[tokio::test]+ async fn test_queue_overflow_drops_oldest() {+ use crossbeam::queue::ArrayQueue;+ use image::DynamicImage;++ let queue: ArrayQueue<Arc<RawCaptureResult>> = ArrayQueue::new(2);++ let make_frame = |n: u64| -> Arc<RawCaptureResult> {+ Arc::new(RawCaptureResult {+ image: DynamicImage::new_rgb8(1, 1),+ window_images: vec![],+ frame_number: n,+ timestamp: std::time::Instant::now(),+ captured_at: chrono::Utc::now(),+ })+ };++ // Fill queue to capacity+ assert!(queue.push(make_frame(1)).is_ok());+ assert!(queue.push(make_frame(2)).is_ok());+ assert_eq!(queue.len(), 2);++ // Third push should fail+ assert!(queue.push(make_frame(3)).is_err());++ // Simulate push_to_raw_queue overflow logic: pop oldest, push new+ queue.pop(); // drops frame 1+ assert!(queue.push(make_frame(3)).is_ok());++ // Queue should contain frames 2 and 3 (frame 1 was dropped)+ let first = queue.pop().unwrap();+ let second = queue.pop().unwrap();+ assert_eq!(first.frame_number, 2, "Expected frame 2 (oldest surviving)");+ assert_eq!(second.frame_number, 3, "Expected frame 3 (newest)");+ }++ /// Test FFmpeg recovery signal: process_frames sets stdin to None on write failure+ #[tokio::test]+ async fn test_process_frames_signals_broken_stdin() {+ use crossbeam::queue::ArrayQueue;+ use image::DynamicImage;++ let temp_dir = tempdir().expect("Failed to create temp dir");+ let output_path = temp_dir.path().join("test_signal.mp4");+ let output_str = output_path.to_str().unwrap();++ // Start and immediately kill FFmpeg to get a broken stdin+ let mut child = start_ffmpeg_process(output_str, 1.0, "balanced")+ .await+ .expect("Failed to start FFmpeg");+ let stdin = child.stdin.take().expect("Failed to get stdin");+ child.kill().await.expect("Failed to kill FFmpeg");+ let _ = child.wait().await;++ let mut current_stdin: Option<ChildStdin> = Some(stdin);+ let frame_queue: Arc<ArrayQueue<Arc<RawCaptureResult>>> = Arc::new(ArrayQueue::new(10));+ let tracker = Arc::new(FrameWriteTracker::new());+ let metrics = Arc::new(PipelineMetrics::new());++ // Push a frame into the queue+ assert!(frame_queue+ .push(Arc::new(RawCaptureResult {+ image: DynamicImage::new_rgb8(64, 64),+ window_images: vec![],+ frame_number: 0,+ timestamp: std::time::Instant::now(),+ captured_at: chrono::Utc::now(),+ }))+ .is_ok());++ let mut frame_count = 0usize;+ process_frames(+ &frame_queue,+ &mut current_stdin,+ &mut frame_count,+ 100,+ 1.0,+ &tracker,+ output_str,+ &metrics,+ )+ .await;++ // Key assertion: stdin should be None, signaling the outer loop to recover+ assert!(+ current_stdin.is_none(),+ "Expected stdin to be None after write failure — this signals FFmpeg recovery"+ );+ // Frame should NOT have been recorded in tracker+ assert!(+ tracker.get_offset(0).is_none(),+ "Frame should not be in tracker after write failure"+ );+ }}