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(enterprise): preserve local upload transport failure causes (#7792)
Ezra Elletteaafc8612e2d9
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rsindex 6d6e1e20d..684c28d44 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs@@ -525,6 +525,31 @@ mod tests {assert!(!report.contains("private-license"));}+ #[cfg(feature = "enterprise-build")]+ #[tokio::test]+ async fn local_transport_cause_survives_rotation_and_support_redaction() {+ let dir = tempfile::tempdir().unwrap();+ crate::enterprise::sync::tests::check_retained_local_transport_error(dir.path()).await;+ for index in 0..7 {+ tokio::fs::write(+ dir.path()+ .join(format!("screenpipe-app.2026-10-27.{index}.log")),+ "INFO recorder restarted\n",+ )+ .await+ .unwrap();+ }+ let report = collect_redacted_from_dirs(&[dir.path().to_path_buf()])+ .await+ .unwrap();+ assert!(report.contains("read frame recordings"));+ assert!(report.to_lowercase().contains("refused"));+ assert!(report.contains("os error"));+ assert!(report.contains("pending data retained"));+ assert!(!report.contains("[email protected]"));+ assert!(!report.contains("private-signature"));+ }+#[cfg(feature = "enterprise-build")]#[tokio::test]async fn retained_sync_diagnostic_survives_rotation_and_support_redaction() {diff --git a/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rsindex 2c05e7d92..bf0eaa0e4 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rs@@ -778,6 +778,11 @@ fn http_error_detail(operation: &str, error: reqwest::Error) -> String {detail}+/// Preserve the originating local recording failure before retention redacts URLs.+pub(crate) fn local_api_http_error(operation: &str, error: reqwest::Error) -> EnterpriseSyncError {+ EnterpriseSyncError::LocalApi(http_error_detail(operation, error))+}+/// POST a JSONL body to the ingest endpoint. Returns `Ok(())` on 2xx./// Distinguishes auth (401/403) from transient (5xx) so the caller can apply/// the appropriate retry handling.@@ -5977,6 +5982,77 @@ pub(crate) mod tests {assert!(!retained.contains("private-license"));}+ #[tokio::test]+ async fn local_transport_cause_survives_retention() {+ let dir = TempDir::new().unwrap();+ check_retained_local_transport_error(dir.path()).await;+ }++ #[tokio::test]+ async fn local_transport_timeout_and_decode_preserve_their_causes() {+ let server = wiremock::MockServer::start().await;+ wiremock::Mock::given(wiremock::matchers::path("/slow"))+ .respond_with(wiremock::ResponseTemplate::new(200).set_delay(Duration::from_secs(1)))+ .mount(&server)+ .await;+ wiremock::Mock::given(wiremock::matchers::path("/invalid"))+ .respond_with(wiremock::ResponseTemplate::new(200).set_body_string("invalid JSON"))+ .mount(&server)+ .await;+ let http = reqwest::Client::builder()+ .no_proxy()+ .timeout(Duration::from_millis(30))+ .build()+ .unwrap();+ let error = http+ .get(format!("{}/slow?signature=private-signature", server.uri()))+ .send()+ .await+ .unwrap_err();+ assert!(error.is_timeout());+ let detail = local_api_http_error("read audio recordings", error).to_string();+ assert!(detail.contains("read audio recordings"), "{detail}");+ assert!(detail.contains("timed out"), "{detail}");+ assert!(!detail.contains("private-signature"), "{detail}");+ let response = reqwest::Client::new()+ .get(format!("{}/invalid", server.uri()))+ .send()+ .await+ .unwrap();+ let error = response.json::<serde_json::Value>().await.unwrap_err();+ let detail = local_api_http_error("decode frame recordings", error).to_string();+ assert!(detail.contains("decode frame recordings"), "{detail}");+ assert!(detail.contains("expected value"), "{detail}");+ }++ // The desktop support test also runs the real collector after log rotation.+ pub(crate) async fn check_retained_local_transport_error(log_dir: &std::path::Path) {+ let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();+ let address = listener.local_addr().unwrap();+ drop(listener);+ let url = format!("http://{address}/search?signature=private-signature");+ let http = reqwest::Client::builder().no_proxy().build().unwrap();+ let error = http.get(&url).send().await.unwrap_err();+ let error = local_api_http_error("read frame recordings", error);+ assert!(matches!(error, EnterpriseSyncError::LocalApi(_)));+ let detail = error.to_string();+ assert!(detail.contains("read frame recordings"), "{detail}");+ assert!(detail.to_lowercase().contains("refused"), "{detail}");+ assert!(detail.contains("os error"), "{detail}");+ assert!(!detail.contains("private-signature"), "{detail}");+ assert!(!detail.contains("http://"), "{detail}");+ let dir = TempDir::new().unwrap();+ let mut cfg = test_cfg(&dir, url);+ cfg.cursor_path = log_dir.join("cursor.json");+ diagnostics::retain(&cfg, &format!("{detail}; upload did not complete, pending data retained; retry in 300 seconds; [email protected]"))+ .await.unwrap();+ let retained = std::fs::read_to_string(log_dir.join(diagnostics::LOG_NAME)).unwrap();+ assert!(retained.contains("read frame recordings"));+ assert!(retained.to_lowercase().contains("refused"));+ assert!(retained.contains("pending data retained"));+ assert!(!retained.contains("[email protected]"));+ }+pub(crate) async fn check_retained_diagnostic(log_dir: &std::path::Path) {let dir = TempDir::new().unwrap();let mut cfg = test_cfg(&dir, "https://control.example/api/enterprise/ingest".into());diff --git a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rsindex 21fe9524b..2eac56135 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs@@ -634,7 +634,7 @@ mod imp {.query(&query).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read certified recording page", e))?;if !response.status().is_success() {return Err(EnterpriseSyncError::LocalApi("privacy release page unavailable; retry pending".into(),@@ -643,7 +643,7 @@ mod imp {response.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))+ .map_err(|e| ee_sync::local_api_http_error("read certified recording page", e))}async fn begin_export(@@ -768,14 +768,14 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read frame recordings", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}let body: LocalSearchResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode frame recordings", e))?;let mut out = Vec::with_capacity(body.data.len());for item in body.data {if let LocalSearchItem::OCR(o) = item {@@ -838,14 +838,14 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read audio recordings", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}let body: LocalSearchResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode audio recordings", e))?;let mut out = Vec::with_capacity(body.data.len());for item in body.data {if let LocalSearchItem::Audio(a) = item {@@ -879,14 +879,14 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read parsed recordings", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}let body: LocalSearchResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode parsed recordings", e))?;let mut out = body.data.into_iter()@@ -1001,14 +1001,14 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read UI recordings", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}let body: LocalSearchResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode UI recordings", e))?;let mut out = Vec::with_capacity(body.data.len());for item in body.data {if let LocalSearchItem::Input(i) = item {@@ -1072,14 +1072,14 @@ mod imp {.auth(self.http.get(&search_url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read recording snapshot", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &search_url).await);}let body: LocalSearchResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode recording snapshot", e))?;// Newest first, so we snapshot the freshest frame that decodes.let mut candidates: Vec<(i64, chrono::DateTime<chrono::Utc>)> = body@@ -1108,7 +1108,7 @@ mod imp {.auth(self.http.get(&img_url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read recording snapshot", e))?;if !resp.status().is_success() {continue;}@@ -1190,14 +1190,14 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|e| EnterpriseSyncError::LocalApi(e.to_string()))?;+ .map_err(|e| ee_sync::local_api_http_error("read recording memories", e))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}let body: LocalMemoriesResponse = resp.json().await- .map_err(|e| EnterpriseSyncError::LocalApi(format!("decode: {e}")))?;+ .map_err(|e| ee_sync::local_api_http_error("decode recording memories", e))?;let out = body.data.into_iter()@@ -1235,14 +1235,13 @@ mod imp {.auth(self.http.get(&url)).send().await- .map_err(|error| EnterpriseSyncError::LocalApi(error.to_string()))?;+ .map_err(|error| ee_sync::local_api_http_error("read recording feedback", error))?;if !resp.status().is_success() {return Err(local_api_error(resp, &url).await);}- let body: LocalFeedbackResponse = resp- .json()- .await- .map_err(|error| EnterpriseSyncError::LocalApi(format!("decode: {error}")))?;+ let body: LocalFeedbackResponse = resp.json().await.map_err(|error| {+ ee_sync::local_api_http_error("decode recording feedback", error)+ })?;Ok(body.data.into_iter()