Skip to content

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

fix(support): include persistent migration state in unattended diagnostics (#7750)

Ezra Ellettee5cc32c75fea
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
index b58d211f0..5e4953e90 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
@@ -6,8 +6,8 @@
//!
//! This module deliberately knows nothing about remote requests, users, or
//! upload endpoints. It builds a small bundle from the app's own logs, including
-//! rotated panic logs, and passes every byte through the shared deterministic
-//! on-device filtering pipeline. The manual "send logs" flow can additionally
+//! rotated panic logs and persisted migration metadata, and passes every byte
+//! through the shared deterministic on-device filtering pipeline. The manual "send logs" flow can additionally
//! use the Tinfoil enclave, but unattended diagnostics never send raw text to a
//! third-party redaction service. Because no automated filter can guarantee
//! removal of every name or path, the consent UI explicitly discloses that
@@ -54,7 +54,11 @@ pub async fn collect_redacted(app: &AppHandle) -> Result<String, String> {
let files = crate::log_files::get_log_files(app.clone())
.await
.unwrap_or_default();
- redact_files(&owned_log_files(files)).await
+ redact_files_with_migration(
+ &owned_log_files(files),
+ Some(crate::db_relaunch::active_data_dir()),
+ )
+ .await
}
/// Collect from explicit app-owned log directories.
@@ -62,8 +66,15 @@ pub async fn collect_redacted(app: &AppHandle) -> Result<String, String> {
/// Enterprise's mandatory collector uses this entry point so both managed and
/// opted-in builds share one filesystem, size, timeout, and redaction policy.
pub async fn collect_redacted_from_dirs(dirs: &[std::path::PathBuf]) -> Result<String, String> {
+ collect_redacted_from_dirs_at_root(dirs, crate::db_relaunch::active_data_dir()).await
+}
+
+async fn collect_redacted_from_dirs_at_root(
+ dirs: &[std::path::PathBuf],
+ root: std::path::PathBuf,
+) -> Result<String, String> {
let files = crate::log_files::collect_log_files(dirs).await;
- redact_files(&owned_log_files(files)).await
+ redact_files_with_migration(&owned_log_files(files), Some(root)).await
}
fn owned_log_files(files: Vec<LogFile>) -> Vec<LogFile> {
@@ -132,8 +143,26 @@ fn is_dated_rolling_log(name: &str, prefix: &str) -> bool {
})
}
+#[cfg(test)]
async fn redact_files(files: &[LogFile]) -> Result<String, String> {
- let raw = build_bundle(files).await;
+ redact_files_with_migration(files, None).await
+}
+
+async fn redact_files_with_migration(
+ files: &[LogFile],
+ data_root: Option<std::path::PathBuf>,
+) -> Result<String, String> {
+ // Persistent evidence goes first so rolling logs cannot displace it at the
+ // existing redacted-bundle boundary. Reuse the manual support reader and
+ // send all bytes through the same local redaction as unattended logs.
+ let mut raw = match data_root {
+ Some(root) => format!(
+ "=== Storage migration diagnostics ===\n{}\n",
+ crate::feedback_upload::collect_migration_diagnostics_from_root(root).await
+ ),
+ None => String::new(),
+ };
+ raw.push_str(&build_bundle(files).await);
let redacted = tokio::time::timeout(
REDACTION_TIMEOUT,
crate::feedback_redact::redact_diagnostics_locally(raw),
@@ -284,6 +313,86 @@ mod tests {
);
}
+ #[tokio::test]
+ async fn unattended_migration_evidence_survives_missing_logs_and_redaction() {
+ use screenpipe_db::{storage, DatabaseManager};
+ let root = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new_hybrid(root.path(), Default::default(), Default::default())
+ .await
+ .unwrap();
+ db.close().await;
+ let descriptor = storage::StorageDescriptor::read(root.path())
+ .unwrap()
+ .unwrap();
+ let receipt = serde_json::json!({
+ "database_id": descriptor.database_id, "generation": descriptor.generation,
+ "frames": 0, "tables": [], "source_bytes": 4096,
+ "index_bytes": 2048, "payload_bytes": 0,
+ });
+ let receipt_path = root.path().join("storage-migration-complete.json");
+ std::fs::write(&receipt_path, serde_json::to_vec(&receipt).unwrap()).unwrap();
+ // No rolling logs: a later process must still expose the matching
+ // durable receipt without reading the recording database.
+ let report = collect_redacted_from_dirs_at_root(&[], root.path().to_path_buf())
+ .await
+ .unwrap();
+ assert!(report.contains("\"receipt_matches_active_storage\": true"));
+ assert!(report.contains("\"pending\": false"));
+ assert!(report.contains(&descriptor.database_id));
+
+ // Interrupted/failed work must remain diagnosable even with a receipt
+ // from another generation and enough log text to fill the old bundle.
+ let mut mismatched = receipt;
+ mismatched["generation"] = serde_json::json!(uuid::Uuid::new_v4().to_string());
+ std::fs::write(&receipt_path, serde_json::to_vec(&mismatched).unwrap()).unwrap();
+ std::fs::write(root.path().join("storage-migration.json"), "{}").unwrap();
+ std::fs::write(root.path().join("storage-migration-error.txt"),
+ "archive verification failed; pending data retained; contact [email protected]").unwrap();
+ let logs = root.path().join("logs");
+ std::fs::create_dir(&logs).unwrap();
+ for day in 10..17 {
+ std::fs::write(
+ logs.join(format!("screenpipe.2026-10-{day}.log")),
+ "INFO normal recording resumed\n".repeat(8192),
+ )
+ .unwrap();
+ }
+ let report = collect_redacted_from_dirs_at_root(&[logs], root.path().to_path_buf())
+ .await
+ .unwrap();
+ assert!(report.contains("\"receipt_matches_active_storage\": false"));
+ assert!(report.contains("\"pending\": true"));
+ assert!(report.contains("archive verification failed"));
+ assert!(report.contains("pending data retained"));
+ assert!(!report.contains("[email protected]"));
+
+ // Verify the exact redacted bytes received by the support upload port,
+ // rather than only an unredacted snapshot or local tracing line.
+ use wiremock::{
+ matchers::{body_string_contains, method},
+ Mock, MockServer, ResponseTemplate,
+ };
+ let support = MockServer::start().await;
+ Mock::given(method("PUT"))
+ .and(body_string_contains("archive verification failed"))
+ .respond_with(ResponseTemplate::new(200))
+ .expect(1)
+ .mount(&support)
+ .await;
+ reqwest::Client::new()
+ .put(support.uri())
+ .body(report)
+ .send()
+ .await
+ .unwrap()
+ .error_for_status()
+ .unwrap();
+ let uploads = support.received_requests().await.unwrap();
+ let received = String::from_utf8_lossy(&uploads[0].body);
+ assert!(received.contains("\"pending\": true"));
+ assert!(!received.contains("[email protected]"));
+ }
+
#[tokio::test(flavor = "current_thread")]
async fn required_pii_failure_survives_rotation_and_support_redaction() {
use std::sync::Arc;
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
index c2a644bec..fcf5da4cd 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
@@ -332,7 +332,7 @@ async fn collect_migration_diagnostics(app: &AppHandle) -> String {
collect_migration_diagnostics_from_root(root).await
}
-async fn collect_migration_diagnostics_from_root(root: std::path::PathBuf) -> String {
+pub(crate) async fn collect_migration_diagnostics_from_root(root: std::path::PathBuf) -> String {
match timeout(
DIAGNOSTIC_PROBE_TIMEOUT,
tokio::task::spawn_blocking(move || {
@@ -342,10 +342,43 @@ async fn collect_migration_diagnostics_from_root(root: std::path::PathBuf) -> St
json!({"error": format!("Could not read migration diagnostics: {error}")})
}
};
+ // Read receipt metadata only: never open the recording database or
+ // include its contents, paths, privacy policy or settings.
+ let descriptor = screenpipe_db::storage::StorageDescriptor::read(&root);
+ let receipt = screenpipe_db::storage::migration_report(&root);
+ let pending = root.join("storage-migration.json").try_exists();
+ let completion = match (descriptor, receipt) {
+ (Ok(descriptor), Ok(receipt)) => json!({
+ "active_storage": descriptor.as_ref().map(|d| json!({
+ "database_id": d.database_id, "generation": d.generation, "mode": d.mode,
+ })),
+ "receipt": receipt.as_ref().map(|r| json!({
+ "database_id": r.database_id, "generation": r.generation,
+ "source_bytes": r.source_bytes, "index_bytes": r.index_bytes,
+ "payload_bytes": r.payload_bytes,
+ })),
+ "receipt_matches_active_storage": descriptor.as_ref().zip(receipt.as_ref())
+ .is_some_and(|(d, r)| d.database_id == r.database_id && d.generation == r.generation),
+ "pending": pending.as_ref().ok().copied(),
+ "pending_error": pending.err().map(|e| e.to_string()),
+ }),
+ (descriptor, receipt) => json!({
+ "error": "Could not verify migration receipt and active storage",
+ "descriptor_error": descriptor.err().map(|e| e.to_string()),
+ "receipt_error": receipt.err().map(|e| e.to_string()),
+ }),
+ };
// The retry block can predate attempt diagnostics. Include it even
// if the snapshot directory is missing or unreadable.
json!({
"attempts": attempts,
+ "completion": completion,
+ // Expose the observed native prerequisites, not a second copy
+ // of the automatic-migration arbitration or desired policy.
+ "automatic_migration_prerequisites": {
+ "ui_hidden": crate::enterprise_policy::is_app_ui_hidden(),
+ "recording_authorized": crate::enterprise_policy::recording_authorized(),
+ },
"sqlite_planner": match screenpipe_db::planner_stats::report(&root) {
Ok(report) => json!(report),
Err(_) => json!({"error": "Could not read SQLite planner maintenance diagnostics"}),
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
index 42f533054..6583ae3f3 100644
--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
@@ -298,8 +298,7 @@ fn main() -> anyhow::Result<()> {
let runtime = tokio::runtime::Runtime::new()?;
#[cfg(target_os = "macos")]
- if let Some(code) = runtime.block_on(screenpipe_audio::core::vpio_process::run_hidden_mode())
- {
+ if let Some(code) = runtime.block_on(screenpipe_audio::core::vpio_process::run_hidden_mode()) {
std::process::exit(code);
}