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: eliminate silent frame loss from FFmpeg death, DB chunk registration, and error loops
Louis Beaumont68973c9d69c0
diff --git a/Cargo.lock b/Cargo.lockindex bffeb181b..cd07a99be 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5518,7 +5518,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.144"+version = "0.3.145"dependencies = ["anyhow","bytemuck",@@ -5574,7 +5574,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.144"+version = "0.3.145"dependencies = ["accessibility","accessibility-sys",@@ -5615,7 +5615,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.144"+version = "0.3.145"dependencies = ["anyhow","chrono",@@ -5640,7 +5640,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.144"+version = "0.3.145"dependencies = ["anyhow","chrono",@@ -5658,7 +5658,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.144"+version = "0.3.145"dependencies = ["anyhow","chrono",@@ -5679,7 +5679,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.144"+version = "0.3.145"dependencies = ["anyhow","async-trait",@@ -5740,7 +5740,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.144"+version = "0.3.145"dependencies = ["accessibility-sys","anyhow",diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rsindex 46fbd91d2..a1060c57e 100644--- a/crates/screenpipe-db/src/db.rs+++ b/crates/screenpipe-db/src/db.rs@@ -831,6 +831,10 @@ impl DatabaseManager {let (video_chunk_id, file_path) = match video_chunk {Some((id, path)) => (id, path),None => {+ tracing::warn!(+ "No video chunk found for device '{}' — frames will not be inserted",+ device_name+ );// tx will rollback automatically on dropreturn Ok(vec![]);}diff --git a/crates/screenpipe-server/src/core.rs b/crates/screenpipe-server/src/core.rsindex 07f34f5b0..8b39b7fff 100644--- a/crates/screenpipe-server/src/core.rs+++ b/crates/screenpipe-server/src/core.rs@@ -177,12 +177,11 @@ pub async fn record_video(let new_chunk_callback = {let db_clone = Arc::clone(&db);let device_name_clone = Arc::clone(&device_name);- move |file_path: &str, chunk_fps: f64| {+ move |file_path: &str, chunk_fps: f64| -> tokio::task::JoinHandle<()> {let file_path = file_path.to_string();let db = Arc::clone(&db_clone);let device_name = Arc::clone(&device_name_clone);- // Just spawn the task directlytokio::spawn(async move {debug!("Inserting new video chunk: {} (fps={})",@@ -196,7 +195,7 @@ pub async fn record_video(} else {debug!("Successfully inserted video chunk: {}", file_path);}- });+ })}};@@ -423,11 +422,14 @@ pub async fn record_video(// Check if we're seeing too many consecutive DB errorsif consecutive_db_errors > MAX_CONSECUTIVE_DB_ERRORS {error!(- "Excessive consecutive database errors ({}), vision processing may be impaired",- consecutive_db_errors+ "Excessive consecutive database errors ({}) for monitor {}, triggering restart",+ consecutive_db_errors, monitor_id);- // Instead of failing, we'll continue but log the issue clearly- consecutive_db_errors = 0; // Reset to prevent continuous error logging+ return Err(anyhow::anyhow!(+ "Too many consecutive DB errors ({}) for monitor {}",+ consecutive_db_errors,+ monitor_id+ ));}}}diff --git a/crates/screenpipe-server/src/video.rs b/crates/screenpipe-server/src/video.rsindex 4bc6a1ad3..ba6324951 100644--- a/crates/screenpipe-server/src/video.rs+++ b/crates/screenpipe-server/src/video.rs@@ -178,7 +178,7 @@ impl VideoCapture {output_path: &str,fps: f64,video_chunk_duration: Duration,- new_chunk_callback: impl Fn(&str, f64) + Send + Sync + 'static,+ new_chunk_callback: impl Fn(&str, f64) -> tokio::task::JoinHandle<()> + Send + Sync + 'static,ocr_engine: Arc<OcrEngine>,monitor_id: u32,ignore_list: &[String],@@ -685,7 +685,7 @@ async fn save_frames_as_video(frame_queue: &Arc<ArrayQueue<Arc<RawCaptureResult>>>,output_path: &str,fps: f64,- new_chunk_callback: Arc<dyn Fn(&str, f64) + Send + Sync>,+ new_chunk_callback: Arc<dyn Fn(&str, f64) -> tokio::task::JoinHandle<()> + Send + Sync>,monitor_id: u32,video_chunk_duration: Duration,frame_write_tracker: &Arc<FrameWriteTracker>,@@ -763,9 +763,19 @@ async fn save_frames_as_video(frame_count += 1;frames_total += 1;- // Register in DB only after first frame is written successfully- // This ensures the file has valid headers and content before timeline can request it- new_chunk_callback(&output_file, fps);+ // Register in DB only after first frame is written successfully.+ // This ensures the file has valid headers and content before timeline can request it.+ // IMPORTANT: We await the DB insert to guarantee the video_chunk row exists+ // before any frames try to reference it via insert_frames_with_ocr_batch.+ // Previously this was fire-and-forget (tokio::spawn without await), which+ // caused silent data loss when the insert failed or was slow.+ let chunk_handle = new_chunk_callback(&output_file, fps);+ if let Err(e) = chunk_handle.await {+ error!(+ "Video chunk registration panicked for monitor {}: {}",+ monitor_id, e+ );+ }current_ffmpeg = Some(child);current_stdin = Some(stdin);