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: handle corrupted video files gracefully (return 410 instead of 500)
Louis Beaumont29fa7a5828ed
diff --git a/crates/screenpipe-server/src/server.rs b/crates/screenpipe-server/src/server.rsindex c1f7da5c8..510807f03 100644--- a/crates/screenpipe-server/src/server.rs+++ b/crates/screenpipe-server/src/server.rs@@ -3184,6 +3184,24 @@ pub async fn get_frame_data(serve_file(&frame_path).await}Err(e) => {+ let err_str = e.to_string();++ // Check for corrupted/missing video errors - return 410 Gone+ // This tells frontend the frame is permanently unavailable+ if err_str.contains("VIDEO_CORRUPTED") || err_str.contains("VIDEO_NOT_FOUND") {+ debug!("Frame {} unavailable (corrupted/missing video): {}", frame_id, e);+ return Err((+ StatusCode::GONE, // 410 = permanently unavailable+ JsonResponse(json!({+ "error": "Frame unavailable - video file corrupted or missing",+ "error_type": "video_corrupted",+ "frame_id": frame_id,+ "file_path": file_path,+ "details": err_str+ })),+ ));+ }+error!("Failed to extract frame {}: {}", frame_id, e);Err((StatusCode::INTERNAL_SERVER_ERROR,diff --git a/crates/screenpipe-server/src/video_utils.rs b/crates/screenpipe-server/src/video_utils.rsindex df4ded23f..320f5e23d 100644--- a/crates/screenpipe-server/src/video_utils.rs+++ b/crates/screenpipe-server/src/video_utils.rs@@ -704,11 +704,43 @@ impl VideoMetadataOverride {pub async fn extract_frame_from_video(file_path: &str, offset_index: i64) -> Result<String> {let ffmpeg_path = find_ffmpeg_path().expect("failed to find ffmpeg path");- // Get video FPS and duration+ // Check if file exists first+ if !std::path::Path::new(file_path).exists() {+ return Err(anyhow::anyhow!("VIDEO_NOT_FOUND: {}", file_path));+ }++ // Check file size - empty files are definitely corrupted+ if let Ok(metadata) = tokio::fs::metadata(file_path).await {+ if metadata.len() == 0 {+ return Err(anyhow::anyhow!("VIDEO_CORRUPTED: empty file {}", file_path));+ }+ // Files under 1KB are likely corrupted (no valid video that small)+ if metadata.len() < 1024 {+ return Err(anyhow::anyhow!(+ "VIDEO_CORRUPTED: file too small ({} bytes) {}",+ metadata.len(),+ file_path+ ));+ }+ }++ // Get video FPS and duration - if this fails, the video is likely corruptedlet (source_fps, video_duration) =match get_video_fps_and_duration(&ffmpeg_path, file_path).await {Ok((fps, duration)) => (fps, duration),Err(e) => {+ // Check if this is a corrupted video (moov atom missing, invalid data, etc)+ let err_str = e.to_string().to_lowercase();+ if err_str.contains("moov")+ || err_str.contains("invalid data")+ || err_str.contains("no such file")+ {+ return Err(anyhow::anyhow!(+ "VIDEO_CORRUPTED: cannot read metadata from {} - {}",+ file_path,+ e+ ));+ }error!("failed to get video metadata, using defaults: {}", e);(1.0, f64::MAX) // Use MAX duration to disable validation on error}