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(privacy): preserve certified images during media compaction (#7764)

Ezra Ellette5d84243ab130
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 4d192ac1e..82dde6a4a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
@@ -579,6 +579,73 @@ mod tests {
assert!(!report.contains("[email protected]"));
}
+ #[cfg(feature = "enterprise-build")]
+ #[tokio::test(flavor = "current_thread")]
+ async fn image_source_revocation_and_recovery_survive_support_collection() {
+ let dir = tempfile::tempdir().unwrap();
+ let db = screenpipe_db::DatabaseManager::new(
+ dir.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ db.configure_release(&screenpipe_db::privacy_release::ReleasePolicy {
+ identity: "image-test-v1".into(),
+ text: false,
+ images: true,
+ })
+ .await
+ .unwrap();
+ db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,snapshot_path) VALUES(1,'2026-10-16','[email protected]')").await.unwrap();
+ let job = db.release_pending("image", 1).await.unwrap().remove(0);
+ assert!(db.publish_image_release(&job).await.unwrap());
+ let export = db.storage_export_token().await.unwrap();
+ db.execute_raw_sql_write("UPDATE frames SET snapshot_path='replacement.jpg' WHERE id=1")
+ .await
+ .unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err();
+ let job = db.release_pending("image", 1).await.unwrap().remove(0);
+ // Send the real database failure through the production sync worker,
+ // retry retention, recovery acknowledgement and support upload path.
+ let uploaded = crate::enterprise::sync::tests::check_sync_retry_failure_with_cause(
+ dir.path(),
+ Some(&error.to_string()),
+ )
+ .await;
+ assert!(uploaded.contains("privacy revision changed"));
+ assert!(uploaded.contains("pending data retained"));
+ let current = dir.path().join("screenpipe-app.log");
+ drop(export);
+ db.close().await;
+ tokio::fs::rename(&current, dir.path().join("screenpipe-app.2026-10-23.1.log"))
+ .await
+ .unwrap();
+ let db = screenpipe_db::DatabaseManager::new(
+ dir.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ assert!(db.publish_image_release(&job).await.unwrap());
+ let export = db.storage_export_token().await.unwrap();
+ drop(export.admit(&db.pool).await.unwrap());
+ drop(export);
+ db.close().await;
+ tokio::fs::write(
+ &current,
+ "INFO recorder restarted [email protected]\n",
+ )
+ .await
+ .unwrap();
+ let report = collect_redacted_from_dirs(&[dir.path().to_path_buf()])
+ .await
+ .unwrap();
+ assert!(report.contains("privacy revision changed"));
+ assert!(report.contains("pending data retained"));
+ assert!(report.contains("recorder restarted"));
+ assert!(!report.contains("[email protected]"));
+ }
+
#[cfg(feature = "enterprise-support")]
#[tokio::test(flavor = "current_thread")]
async fn protected_upload_revocation_survives_collected_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.rs
index f9f98bfd7..2c05e7d92 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise/sync.rs
@@ -5606,6 +5606,13 @@ pub(crate) mod tests {
}
pub(crate) async fn check_sync_retry_failure(log_dir: &std::path::Path) -> String {
+ check_sync_retry_failure_with_cause(log_dir, None).await
+ }
+
+ pub(crate) async fn check_sync_retry_failure_with_cause(
+ log_dir: &std::path::Path,
+ cause: Option<&str>,
+ ) -> String {
let _env_lock = ENV_LOCK.lock().unwrap();
let _mode_env = UploadModeEnvGuard::clear();
let server = wiremock::MockServer::start().await;
@@ -5652,7 +5659,12 @@ pub(crate) mod tests {
}
let dir = TempDir::new().unwrap();
- let cfg = test_cfg(&dir, format!("{}/api/enterprise/ingest", server.uri()));
+ let mut cfg = test_cfg(&dir, format!("{}/api/enterprise/ingest", server.uri()));
+ if cause.is_some() {
+ // The caller reopens and recollects after this helper returns.
+ // Keep the production-retained failure in its surviving directory.
+ cfg.cursor_path = log_dir.join("cursor.json");
+ }
let cursor_path = cfg.cursor_path.clone();
let mut diagnostic_cfg = cfg.clone();
diagnostic_cfg.log_dirs = vec![log_dir.to_path_buf()];
@@ -5690,12 +5702,13 @@ pub(crate) mod tests {
} else {
"prepare export"
},
- cause: if attempt % 2 == 0 {
- "database disk image is malformed"
- } else {
- "frame storage: payload read deadline exceeded"
- }
- .into(),
+ cause: cause
+ .unwrap_or(if attempt % 2 == 0 {
+ "database disk image is malformed"
+ } else {
+ "frame storage: payload read deadline exceeded"
+ })
+ .into(),
}))
.unwrap();
tokio::time::timeout(Duration::from_secs(10), async {
@@ -5774,8 +5787,12 @@ pub(crate) mod tests {
.unwrap();
let logged = std::fs::read_to_string(log_path).unwrap();
assert!(logged.contains("enterprise upload storage prepare export failed"));
- assert!(logged.contains("frame storage: payload read deadline exceeded"));
- assert!(logged.contains("database disk image is malformed"));
+ if let Some(cause) = cause {
+ assert!(logged.contains(cause));
+ } else {
+ assert!(logged.contains("frame storage: payload read deadline exceeded"));
+ assert!(logged.contains("database disk image is malformed"));
+ }
assert!(logged.contains("pending work retained, retrying in 300s"));
assert!(!logged.contains("backing off 3600s"));
String::from_utf8(diagnostic.body.clone()).unwrap()
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs
index 13c5ce19e..21fe9524b 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs
@@ -3558,11 +3558,51 @@ mod imp {
use std::sync::Arc;
struct CapturingLocal {
db: Arc<screenpipe_db::DatabaseManager>,
+ protected: Option<Arc<screenpipe_db::DatabaseManager>>,
change: u8,
reads: std::sync::atomic::AtomicUsize,
}
#[async_trait::async_trait]
impl LocalApiClient for CapturingLocal {
+ async fn privacy_release_required(&self) -> Result<bool, EnterpriseSyncError> {
+ Ok(self.change == 5)
+ }
+
+ async fn fetch_release_page(
+ &self,
+ kind: &str,
+ after: i64,
+ cutoff: &str,
+ end: Option<&str>,
+ limit: u32,
+ ) -> Result<screenpipe_db::privacy_release::ReleasePage, EnterpriseSyncError>
+ {
+ let page = self
+ .protected
+ .as_ref()
+ .unwrap()
+ .release_export_range_page(kind, after, cutoff, end, limit)
+ .await
+ .unwrap();
+ if kind == "frames" && !page.rows.as_array().unwrap().is_empty() {
+ assert_eq!(
+ self.reads.fetch_add(1, std::sync::atomic::Ordering::SeqCst),
+ 0
+ );
+ self.db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,full_text) VALUES(3,'2026-10-09','new capture')").await.unwrap();
+ let chunk = self
+ .db
+ .insert_video_chunk_with_fps("compacted.mp4", "test", 1.0)
+ .await
+ .unwrap();
+ self.db
+ .compact_snapshots_queued(chunk, vec![(1, 0)])
+ .await
+ .unwrap();
+ }
+ Ok(page)
+ }
+
async fn begin_export(
&self,
) -> Result<Option<Box<dyn ExportFilter>>, EnterpriseSyncError> {
@@ -3576,6 +3616,7 @@ mod imp {
_: u32,
_: u32,
) -> Result<Vec<FrameRow>, EnterpriseSyncError> {
+ assert_ne!(self.change, 5, "protected exports must use certified pages");
let first = self.reads.fetch_add(1, std::sync::atomic::Ordering::SeqCst) == 0;
let ids = if first { vec![1, 2] } else { vec![1, 2, 3] };
let payloads = self
@@ -3640,7 +3681,7 @@ mod imp {
Ok(Vec::new())
}
}
- for (change, hybrid) in (0..5).flat_map(|change| [(change, false), (change, true)]) {
+ for (change, hybrid) in (0..6).flat_map(|change| [(change, false), (change, true)]) {
let dir = tempfile::tempdir().unwrap();
let db = Arc::new(if hybrid {
// Synthetic export fixture; disk admission is covered by
@@ -3663,9 +3704,28 @@ mod imp {
.unwrap()
});
db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,full_text) VALUES(1,'2026-10-09','pending upload'),(2,'2026-10-09','surviving record')").await.unwrap();
- if change == 4 {
+ if change >= 4 {
db.execute_raw_sql_write("UPDATE frames SET snapshot_path='redacted.jpg',full_text_redacted_at=1,image_redacted_at=1 WHERE id=1").await.unwrap();
}
+ if change == 5 {
+ db.configure_release(&screenpipe_db::privacy_release::ReleasePolicy {
+ identity: "compaction-image-v1".into(),
+ text: true,
+ images: true,
+ })
+ .await
+ .unwrap();
+ for job in db.release_pending("frames", 10).await.unwrap() {
+ assert!(db.publish_release(&job, &job.values).await.unwrap());
+ }
+ let images = db.release_pending("image", 10).await.unwrap();
+ let mut ids: Vec<_> = images.iter().map(|image| image.id.as_str()).collect();
+ ids.sort_unstable();
+ assert_eq!(ids, ["1", "2"]);
+ for image in images {
+ assert!(db.publish_image_release(&image).await.unwrap());
+ }
+ }
let server = wiremock::MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::path("/ingest"))
.respond_with(wiremock::ResponseTemplate::new(200))
@@ -3674,8 +3734,22 @@ mod imp {
.await;
let cfg = sync::tests::test_cfg(&dir, format!("{}/ingest", server.uri()));
let mut cursor = sync::Cursor::default();
+ if change == 5 {
+ cursor.privacy.insert(
+ "frames".into(),
+ sync::PrivacyCursor {
+ sequence: 0,
+ cutoff: "2026-10-09T00:00:00Z".into(),
+ },
+ );
+ }
let local = CapturingLocal {
db: db.clone(),
+ protected: if change == 5 {
+ Some(db.protected_reads().await.unwrap())
+ } else {
+ None
+ },
change,
reads: std::sync::atomic::AtomicUsize::new(0),
};
@@ -3687,12 +3761,12 @@ mod imp {
_ => 2,
};
assert_eq!(result.unwrap().frames, expected);
- assert_eq!(
- sync::Cursor::load(&cfg.cursor_path)
- .last_frame_ts
- .as_deref(),
- Some("2026-10-09T00:00:00Z")
- );
+ let saved = sync::Cursor::load(&cfg.cursor_path);
+ if change == 5 {
+ assert!(saved.privacy["frames"].sequence > 0);
+ } else {
+ assert_eq!(saved.last_frame_ts.as_deref(), Some("2026-10-09T00:00:00Z"));
+ }
let requests = server.received_requests().await.unwrap();
if change != 3 {
let body = String::from_utf8_lossy(&requests[0].body);
@@ -3701,10 +3775,10 @@ mod imp {
!body.contains("new capture"),
"new rows belong to the next page"
);
- assert_eq!(body.contains("pending upload"), matches!(change, 0 | 4));
+ assert_eq!(body.contains("pending upload"), matches!(change, 0 | 4 | 5));
assert_eq!(body.contains("[REDACTED]"), change == 2);
}
- if hybrid && change == 4 {
+ if (hybrid && change == 4) || change == 5 {
assert_eq!(
local.reads.load(std::sync::atomic::Ordering::SeqCst),
1,
diff --git a/crates/screenpipe-db/src/db/privacy_release.rs b/crates/screenpipe-db/src/db/privacy_release.rs
index 716776b7d..5684e6316 100644
--- a/crates/screenpipe-db/src/db/privacy_release.rs
+++ b/crates/screenpipe-db/src/db/privacy_release.rs
@@ -303,10 +303,38 @@ impl DatabaseManager {
} else {
mutation
};
- let create = format!("CREATE TRIGGER privacy_{kind}_{event} AFTER {clause} ON {table} {when} BEGIN
+ let create_trigger = |when: &str| {
+ format!("CREATE TRIGGER privacy_{kind}_{event} AFTER {clause} ON {table} {when} BEGIN
UPDATE _privacy_policy SET epoch=epoch+1,revocation=revocation+1 WHERE EXISTS(SELECT 1 FROM _privacy_release WHERE kind='{kind}' AND id=CAST({id} AS TEXT) AND policy IS NOT NULL);
{mutation}
- END");
+ END")
+ };
+ let old_image_update =
+ (kind == "image" && event == "UPDATE").then(|| create_trigger(&when));
+ let create = if old_image_update.is_some() {
+ let changed = watched
+ .iter()
+ .map(|column| {
+ let changed = format!("NEW.\"{column}\" IS NOT OLD.\"{column}\"");
+ if *column == "snapshot_path" {
+ format!(
+ "({changed} AND NOT ({} AND EXISTS(SELECT 1 FROM _privacy_release r JOIN _privacy_policy p ON CAST(p.receipt_key AS TEXT)=r.policy WHERE r.kind='image' AND r.id=CAST(NEW.id AS TEXT))))",
+ crate::storage::read_schema::SNAPSHOT_MEDIA_RELOCATION
+ )
+ } else {
+ changed
+ }
+ })
+ .collect::<Vec<_>>()
+ .join(" OR ");
+ // Relocation preserves the image receipt. A simultaneous
+ // name or timestamp edit still invalidates that receipt.
+ // Pending inference must restart against the new locator:
+ // it may still be processing the JPEG that compaction moved.
+ create_trigger(&format!("WHEN {active} AND ({changed}){maintenance}"))
+ } else {
+ create_trigger(&when)
+ };
let existing: Option<String> = sqlx::query_scalar(
"SELECT sql FROM sqlite_master WHERE type='trigger' AND name=?",
)
@@ -317,7 +345,11 @@ impl DatabaseManager {
// triggers invalidates cached FTS/write statements in other
// pooled connections and adds needless schema-lock work.
if existing.as_deref() != Some(create.as_str()) {
- changed_contract |= existing.is_some();
+ // This exact installed image contract already certified all
+ // watched values. Removing its relocation false positive
+ // adds no coverage and needs no historical reprocessing.
+ changed_contract |=
+ existing.is_some() && existing.as_deref() != old_image_update.as_deref();
schema_changed = true;
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
"DROP TRIGGER IF EXISTS privacy_{kind}_{event}; {create};"
diff --git a/crates/screenpipe-db/src/storage/read_schema.rs b/crates/screenpipe-db/src/storage/read_schema.rs
index 37410a54f..875b90587 100644
--- a/crates/screenpipe-db/src/storage/read_schema.rs
+++ b/crates/screenpipe-db/src/storage/read_schema.rs
@@ -7,6 +7,10 @@
use super::{storage_error, HybridStorage};
use sqlx::{Connection, Row, SqliteConnection};
+/// The compaction writer replaces a JPEG locator with its video locator while
+/// preserving the captured image. Privacy receipts use the same exception.
+pub(crate) const SNAPSHOT_MEDIA_RELOCATION: &str = "OLD.snapshot_path IS NOT NULL AND NEW.snapshot_path IS NULL AND NEW.video_chunk_id IS NOT NULL AND OLD.video_chunk_id IS NOT NEW.video_chunk_id";
+
const REVOCATION: &str = r#"
CREATE TABLE IF NOT EXISTS _storage_revocation(id INTEGER PRIMARY KEY CHECK(id=1),revision INTEGER NOT NULL);
INSERT OR IGNORE INTO _storage_revocation VALUES(1,0);
@@ -167,23 +171,29 @@ async fn upgrade_export_revocation(conn: &mut SqliteConnection) -> Result<bool,
&revocation(&name, true),
)
};
- let sql = if name == "hybrid_read_revoke_redaction_frames"
- && !sql.contains("AFTER UPDATE OF")
- {
- // UPDATE OF matters: a repeated image watermark in the same second
- // still revokes, even if a statement also relocates its media.
- let content = sql.replace(
- "AFTER UPDATE ON",
- &format!("AFTER UPDATE OF {content_updates} ON"),
- );
- let media_name = "hybrid_read_revoke_media_frames";
- let media = sql.replace(&name, media_name)
- .replace("AFTER UPDATE ON", &format!("AFTER UPDATE OF {} ON", MEDIA.join(",")))
- .replace(" BEGIN ", " AND NOT (OLD.snapshot_path IS NOT NULL AND NEW.snapshot_path IS NULL AND NEW.video_chunk_id IS NOT NULL AND OLD.video_chunk_id IS NOT NEW.video_chunk_id) BEGIN ");
- format!("{content}; {media}")
- } else {
- sql
- };
+ let sql =
+ if name == "hybrid_read_revoke_redaction_frames" && !sql.contains("AFTER UPDATE OF") {
+ // UPDATE OF matters: a repeated image watermark in the same second
+ // still revokes, even if a statement also relocates its media.
+ let content = sql.replace(
+ "AFTER UPDATE ON",
+ &format!("AFTER UPDATE OF {content_updates} ON"),
+ );
+ let media_name = "hybrid_read_revoke_media_frames";
+ let media = sql
+ .replace(&name, media_name)
+ .replace(
+ "AFTER UPDATE ON",
+ &format!("AFTER UPDATE OF {} ON", MEDIA.join(",")),
+ )
+ .replace(
+ " BEGIN ",
+ &format!(" AND NOT ({SNAPSHOT_MEDIA_RELOCATION}) BEGIN "),
+ );
+ format!("{content}; {media}")
+ } else {
+ sql
+ };
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
"DROP TRIGGER \"{}\"; {sql}",
name.replace('"', "\"\"")
diff --git a/crates/screenpipe-db/tests/snapshot_compaction_test.rs b/crates/screenpipe-db/tests/snapshot_compaction_test.rs
index 734eaecb1..6788c94ff 100644
--- a/crates/screenpipe-db/tests/snapshot_compaction_test.rs
+++ b/crates/screenpipe-db/tests/snapshot_compaction_test.rs
@@ -187,3 +187,169 @@ async fn compaction_of_redacted_snapshots_preserves_export_admission() {
);
db.close().await;
}
+
+#[tokio::test]
+async fn compaction_preserves_certified_image_receipts_and_exports_across_restart() {
+ for hybrid in [false, true] {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("db.sqlite");
+ let db = if hybrid {
+ DatabaseManager::new_hybrid(dir.path(), Default::default(), Default::default())
+ .await
+ .unwrap()
+ } else {
+ DatabaseManager::new(path.to_str().unwrap(), Default::default())
+ .await
+ .unwrap()
+ };
+ let policy = screenpipe_db::privacy_release::ReleasePolicy {
+ identity: "compaction-image-v1".into(),
+ text: false,
+ images: true,
+ };
+ db.configure_release(&policy).await.unwrap();
+ let frame = snapshot(&db, "sanitized-original.jpg").await;
+ let job = db.release_pending("image", 1).await.unwrap().remove(0);
+ assert!(db.publish_image_release(&job).await.unwrap());
+ // Installed #7634 databases use this exact trigger contract. Narrowing
+ // its false positive must not invalidate previously certified content.
+ let maintenance = if hybrid {
+ " AND (SELECT maintenance=0 FROM storage_metadata WHERE singleton=1)"
+ } else {
+ ""
+ };
+ db.execute_raw_sql_write(&format!(
+ "DROP TRIGGER privacy_image_UPDATE;
+ CREATE TRIGGER privacy_image_UPDATE AFTER UPDATE OF \"snapshot_path\",\"name\",\"timestamp\" ON frames WHEN ((SELECT image_required FROM _privacy_policy WHERE id=1)=1 OR EXISTS(SELECT 1 FROM _privacy_release WHERE kind='image' AND id=CAST(NEW.id AS TEXT))) AND (NEW.\"snapshot_path\" IS NOT OLD.\"snapshot_path\" OR NEW.\"name\" IS NOT OLD.\"name\" OR NEW.\"timestamp\" IS NOT OLD.\"timestamp\"){maintenance} BEGIN
+ UPDATE _privacy_policy SET epoch=epoch+1,revocation=revocation+1 WHERE EXISTS(SELECT 1 FROM _privacy_release WHERE kind='image' AND id=CAST(NEW.id AS TEXT) AND policy IS NOT NULL);
+ INSERT INTO _privacy_release(kind,id,revision) VALUES('image',CAST(NEW.id AS TEXT),1) ON CONFLICT(kind,id) DO UPDATE SET revision=revision+1,policy=NULL,attempts=0,retry_at=NULL;
+ END;"
+ ))
+ .await
+ .unwrap();
+ let before_upgrade = db.release_revocation().await.unwrap();
+ db.configure_release(&policy).await.unwrap();
+ assert_eq!(db.release_revocation().await.unwrap(), before_upgrade);
+ assert!(db.release_ready("image", &frame.to_string()).await.unwrap());
+ let export = db.storage_export_token().await.unwrap();
+ let chunk = db
+ .insert_video_chunk_with_fps("sanitized-original.mp4", "compaction-test", 1.0)
+ .await
+ .unwrap();
+ let (compacted, captured) = tokio::join!(
+ db.compact_snapshots_queued(chunk, vec![(frame, 0)]),
+ snapshot(&db, "pending-new-capture.jpg")
+ );
+ compacted.unwrap();
+ drop(
+ export
+ .admit(&db.pool)
+ .await
+ .expect("relocation revoked a certified image export"),
+ );
+ assert!(db.release_ready("image", &frame.to_string()).await.unwrap());
+ assert!(!db
+ .release_ready("image", &captured.to_string())
+ .await
+ .unwrap());
+ let in_flight = db.release_pending("image", 1).await.unwrap().remove(0);
+ assert_eq!(in_flight.id, captured.to_string());
+ db.compact_snapshots_queued(chunk, vec![(captured, 1)])
+ .await
+ .unwrap();
+ // Inference against the old JPEG cannot certify its replacement video.
+ assert!(!db.publish_image_release(&in_flight).await.unwrap());
+ drop(export.admit(&db.pool).await.unwrap());
+ drop(export);
+ db.close().await;
+
+ let db = std::sync::Arc::new(
+ DatabaseManager::new(path.to_str().unwrap(), Default::default())
+ .await
+ .unwrap(),
+ );
+ db.configure_release(&policy).await.unwrap();
+ assert!(db.release_ready("image", &frame.to_string()).await.unwrap());
+ let protected = db.protected_reads().await.unwrap();
+ assert_eq!(
+ protected.get_frame(frame).await.unwrap(),
+ Some(("sanitized-original.mp4".into(), 0, false))
+ );
+ let pending = db.release_pending("image", 10).await.unwrap();
+ assert_eq!(pending.len(), 1);
+ assert_eq!(pending[0].id, captured.to_string());
+ assert_eq!(protected.get_frame(captured).await.unwrap(), None);
+ assert_eq!(
+ db.get_frame(captured).await.unwrap(),
+ Some(("sanitized-original.mp4".into(), 1, false))
+ );
+ assert!(db.publish_image_release(&pending[0]).await.unwrap());
+ assert_eq!(
+ protected.get_frame(captured).await.unwrap(),
+ db.get_frame(captured).await.unwrap()
+ );
+ protected.close().await;
+ db.close().await;
+ }
+}
+
+#[tokio::test]
+async fn image_receipts_revoke_reference_removal_and_combined_content_changes() {
+ for hybrid in [false, true] {
+ let dir = tempfile::tempdir().unwrap();
+ let db = if hybrid {
+ DatabaseManager::new_hybrid(dir.path(), Default::default(), Default::default())
+ .await
+ .unwrap()
+ } else {
+ DatabaseManager::new(
+ dir.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap()
+ };
+ db.configure_release(&screenpipe_db::privacy_release::ReleasePolicy {
+ identity: "compaction-image-v1".into(),
+ text: false,
+ images: true,
+ })
+ .await
+ .unwrap();
+ let chunk = db
+ .insert_video_chunk_with_fps("replacement.mp4", "compaction-test", 1.0)
+ .await
+ .unwrap();
+ for update in [
+ "snapshot_path=NULL".to_string(),
+ "snapshot_path='different-image.jpg'".to_string(),
+ format!("snapshot_path=NULL,video_chunk_id={chunk},name='different source'"),
+ format!("snapshot_path=NULL,video_chunk_id={chunk},timestamp='2026-10-16T00:00:00Z'"),
+ ] {
+ let frame = snapshot(&db, "sanitized.jpg").await;
+ let job = db.release_pending("image", 1).await.unwrap().remove(0);
+ assert_eq!(job.id, frame.to_string());
+ assert!(db.publish_image_release(&job).await.unwrap());
+ let export = db.storage_export_token().await.unwrap();
+ db.execute_raw_sql_write(&format!("UPDATE frames SET {update} WHERE id={frame}"))
+ .await
+ .unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err().to_string();
+ assert!(
+ error.contains("privacy revision changed"),
+ "{update}: {error}"
+ );
+ assert!(!db.release_ready("image", &frame.to_string()).await.unwrap());
+ // A refused export does not discard the source or its retry work.
+ let pending = db.release_pending("image", 10).await.unwrap();
+ assert!(pending.iter().any(|job| job.id == frame.to_string()));
+ assert!(db
+ .query_raw_sql(&format!("SELECT id FROM frames WHERE id={frame}"))
+ .await
+ .unwrap()
+ .as_array()
+ .is_some_and(|rows| rows.len() == 1));
+ }
+ db.close().await;
+ }
+}
diff --git a/docs/COVERAGE.md b/docs/COVERAGE.md
index a75cc826f..6458c674f 100644
--- a/docs/COVERAGE.md
+++ b/docs/COVERAGE.md
@@ -38,15 +38,15 @@ results and `cargo llvm-cov` data on top when judging release confidence.
- Mapped suites: 37
- Mapped Rust files: 402
-- Active test blocks: 3920
+- Active test blocks: 3923
- Ignored/manual test blocks: 188
-- Weighted coverage points: 3229.4
+- Weighted coverage points: 3232.1
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 33 | 3757 | 170 | 3156.4 | 21 | 11 | 100% |
-| macos | 32 | 3800 | 149 | 3151.7 | 22 | 11 | 100% |
-| linux | 29 | 3335 | 145 | 2774.7 | 20 | 11 | 100% |
+| windows | 33 | 3760 | 170 | 3159.1 | 21 | 11 | 100% |
+| macos | 32 | 3803 | 149 | 3154.4 | 22 | 11 | 100% |
+| linux | 29 | 3338 | 145 | 2777.4 | 20 | 11 | 100% |
## Refresh
diff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.md
index d1db3959f..d6ff01206 100644
--- a/docs/coverage/CORE.md
+++ b/docs/coverage/CORE.md
@@ -9,10 +9,10 @@ confidence, and criticality.
- Tracked crates: screenpipe-engine, screenpipe-db, screenpipe-sqlite-coordinator, screenpipe-audio, screenpipe-screen, screenpipe-a11y, screenpipe-fs
- Mapped suites: 37
- Mapped Rust files: 402
-- Active test blocks: 3920
+- Active test blocks: 3923
- Ignored/manual test blocks: 188
-- Declared test blocks: 4108
-- Weighted coverage points: 3229.4
+- Declared test blocks: 4111
+- Weighted coverage points: 3232.1
Confidence weights: strong=1.0, partial=0.7, conditional=0.4, smoke=0.3.
Criticality weights: high=1.0, medium=0.7, low=0.4.
@@ -23,16 +23,16 @@ are explicitly enabled in a runtime lane.
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 33 | 3757 | 170 | 3156.4 | 21 | 11 | 100% |
-| macos | 32 | 3800 | 149 | 3151.7 | 22 | 11 | 100% |
-| linux | 29 | 3335 | 145 | 2774.7 | 20 | 11 | 100% |
+| windows | 33 | 3760 | 170 | 3159.1 | 21 | 11 | 100% |
+| macos | 32 | 3803 | 149 | 3154.4 | 22 | 11 | 100% |
+| linux | 29 | 3338 | 145 | 2777.4 | 20 | 11 | 100% |
## Crate Summary
| Crate | Suites | Integration files | Source unit files | Active tests | Ignored tests | Weighted points | Flows |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| screenpipe-engine | 12 | 22 | 131 | 1872 | 53 | 1441.1 | 10 |
-| screenpipe-db | 5 | 69 | 29 | 634 | 32 | 604.4 | 9 |
+| screenpipe-engine | 12 | 22 | 131 | 1873 | 53 | 1441.8 | 10 |
+| screenpipe-db | 5 | 69 | 29 | 636 | 32 | 606.4 | 9 |
| screenpipe-sqlite-coordinator | 1 | 0 | 3 | 27 | 0 | 27.0 | 2 |
| screenpipe-audio | 8 | 29 | 54 | 705 | 56 | 616.0 | 5 |
| screenpipe-screen | 6 | 9 | 19 | 278 | 9 | 246.4 | 4 |
@@ -66,22 +66,22 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| audio | 10 suites / 843 active / 60 ignored / 754.0 pts | 9 suites / 837 active / 60 ignored / 749.8 pts | 8 suites / 758 active / 59 ignored / 694.5 pts |
| audio-device | 2 suites / 242 active / 10 ignored / 218.3 pts | 2 suites / 242 active / 10 ignored / 218.3 pts | 1 suites / 163 active / 9 ignored / 163.0 pts |
| configuration | 2 suites / 153 active / 3 ignored / 138.7 pts | 2 suites / 153 active / 3 ignored / 138.7 pts | 2 suites / 153 active / 3 ignored / 138.7 pts |
-| database | 7 suites / 590 active / 28 ignored / 560.4 pts | 7 suites / 590 active / 28 ignored / 560.4 pts | 7 suites / 590 active / 28 ignored / 560.4 pts |
+| database | 7 suites / 592 active / 28 ignored / 562.4 pts | 7 suites / 592 active / 28 ignored / 562.4 pts | 7 suites / 592 active / 28 ignored / 562.4 pts |
| db-search | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts |
| engine-lifecycle | 6 suites / 274 active / 1 ignored / 244.8 pts | 6 suites / 274 active / 1 ignored / 244.8 pts | 6 suites / 270 active / 9 ignored / 243.9 pts |
-| local-api | 3 suites / 490 active / 12 ignored / 346.9 pts | 3 suites / 490 active / 12 ignored / 346.9 pts | 3 suites / 490 active / 12 ignored / 346.9 pts |
-| meeting | 6 suites / 1758 active / 32 ignored / 1437.9 pts | 6 suites / 1758 active / 32 ignored / 1437.9 pts | 4 suites / 1404 active / 28 ignored / 1107.6 pts |
+| local-api | 3 suites / 491 active / 12 ignored / 347.6 pts | 3 suites / 491 active / 12 ignored / 347.6 pts | 3 suites / 491 active / 12 ignored / 347.6 pts |
+| meeting | 6 suites / 1759 active / 32 ignored / 1438.6 pts | 6 suites / 1759 active / 32 ignored / 1438.6 pts | 4 suites / 1405 active / 28 ignored / 1108.3 pts |
| ocr | 4 suites / 141 active / 7 ignored / 130.8 pts | 4 suites / 134 active / 7 ignored / 128.6 pts | 3 suites / 125 active / 6 ignored / 119.6 pts |
| os-integration | 1 suites / 6 active / 0 ignored / 1.7 pts | 1 suites / 6 active / 0 ignored / 1.7 pts | - |
-| performance | 13 suites / 1705 active / 86 ignored / 1505.4 pts | 14 suites / 1830 active / 94 ignored / 1555.4 pts | 13 suites / 1705 active / 86 ignored / 1505.4 pts |
+| performance | 13 suites / 1707 active / 86 ignored / 1507.4 pts | 14 suites / 1832 active / 94 ignored / 1557.4 pts | 13 suites / 1707 active / 86 ignored / 1507.4 pts |
| pipes | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts |
| privacy | 5 suites / 1013 active / 42 ignored / 816.8 pts | 5 suites / 1069 active / 21 ignored / 818.5 pts | 5 suites / 971 active / 14 ignored / 781.7 pts |
| real-app | - | 1 suites / 125 active / 8 ignored / 50.0 pts | - |
| speaker | 2 suites / 416 active / 18 ignored / 416.0 pts | 2 suites / 416 active / 18 ignored / 416.0 pts | 2 suites / 416 active / 18 ignored / 416.0 pts |
-| storage | 4 suites / 703 active / 41 ignored / 586.0 pts | 4 suites / 703 active / 41 ignored / 586.0 pts | 4 suites / 703 active / 41 ignored / 586.0 pts |
+| storage | 4 suites / 705 active / 41 ignored / 588.0 pts | 4 suites / 705 active / 41 ignored / 588.0 pts | 4 suites / 705 active / 41 ignored / 588.0 pts |
| sync | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts |
-| timeline | 4 suites / 1250 active / 48 ignored / 1026.8 pts | 4 suites / 1250 active / 48 ignored / 1026.8 pts | 4 suites / 1250 active / 48 ignored / 1026.8 pts |
-| transcription | 7 suites / 900 active / 53 ignored / 703.6 pts | 6 suites / 894 active / 53 ignored / 699.4 pts | 6 suites / 894 active / 53 ignored / 699.4 pts |
+| timeline | 4 suites / 1253 active / 48 ignored / 1029.5 pts | 4 suites / 1253 active / 48 ignored / 1029.5 pts | 4 suites / 1253 active / 48 ignored / 1029.5 pts |
+| transcription | 7 suites / 901 active / 53 ignored / 704.3 pts | 6 suites / 895 active / 53 ignored / 700.1 pts | 6 suites / 895 active / 53 ignored / 700.1 pts |
| ui-events | 4 suites / 828 active / 34 ignored / 627.7 pts | 3 suites / 759 active / 5 ignored / 579.4 pts | 3 suites / 759 active / 5 ignored / 579.4 pts |
| vision-capture | 6 suites / 579 active / 32 ignored / 455.3 pts | 6 suites / 572 active / 32 ignored / 453.1 pts | 5 suites / 563 active / 31 ignored / 444.1 pts |
@@ -135,8 +135,8 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-audio-meetings-speakers | screenpipe-db | windows, macos, linux | database, audio, meeting, speaker | audio-record-transcribe, audio-device-health, meeting-live-notes | high | strong | integration | 19 | 135 | 4 | Audio transcript dedupe, live meeting mirroring, end-generation and open-meeting invariants, liveness, and speaker reassignment coverage. |
| db-runtime-reliability | screenpipe-db | windows, macos, linux | database, performance | performance-liveness | high | partial | mixed | 18 | 51 | 7 | SQLite hard-fault classification, failpoint VFS injection, fresh-identity recovery verification with integrity/FK/write canaries, query cancellation, close-severs-connections regressions, multi-pool WAL parity, runtime version pinning, and WAL chaos plus memory-pressure probes, plus read-only quarantine self-heal verification for transient IOERR faults. |
| db-search-indexing | screenpipe-db | windows, macos, linux | db-search, ocr, accessibility, performance | local-api-search, capture-ocr-pipeline, accessibility-ui-events, performance-liveness | high | strong | mixed | 14 | 107 | 4 | FTS, tokenizer, OCR snapshot search, query planning, ordering, accessibility search, and contention coverage. |
-| db-timeline-frames | screenpipe-db | windows, macos, linux | database, timeline, storage, performance | timeline-streaming, performance-liveness | high | strong | mixed | 40 | 313 | 15 | Frame/audio joins, timeline query shape, suggestions frames, write queue, DB primitives (src/db.rs split into src/db/ modules), feedback record upserts, media eviction anti-join regressions, SAF output registry, semantic storage, and timeline performance. |
-| engine-api-routes | screenpipe-engine | windows, macos, linux | local-api, timeline, meeting, transcription | local-api-search, timeline-streaming, meeting-live-notes, audio-record-transcribe | high | partial | mixed | 46 | 437 | 7 | Route/unit coverage for search, health, streaming, meetings, time/timezone, and transcription. Legacy endpoint/websocket tests require local data and remain ignored. |
+| db-timeline-frames | screenpipe-db | windows, macos, linux | database, timeline, storage, performance | timeline-streaming, performance-liveness | high | strong | mixed | 40 | 315 | 15 | Frame/audio joins, timeline query shape, suggestions frames, write queue, DB primitives (src/db.rs split into src/db/ modules), feedback record upserts, media eviction anti-join regressions, SAF output registry, semantic storage, and timeline performance. |
+| engine-api-routes | screenpipe-engine | windows, macos, linux | local-api, timeline, meeting, transcription | local-api-search, timeline-streaming, meeting-live-notes, audio-record-transcribe | high | partial | mixed | 46 | 438 | 7 | Route/unit coverage for search, health, streaming, meetings, time/timezone, and transcription. Legacy endpoint/websocket tests require local data and remain ignored. |
| engine-capture-timeline | screenpipe-engine | windows, macos, linux | vision-capture, timeline, storage, performance | capture-ocr-pipeline, timeline-streaming, performance-liveness | high | partial | mixed | 25 | 307 | 26 | Covers capture trigger logic, frame/audio linking, hot cache, timeline refresh regressions, fragmented MP4 extraction, and HD-mode control. Several real-data tests are intentionally ignored by default. |
| engine-config-lifecycle | screenpipe-engine | windows, macos, linux | configuration, engine-lifecycle, performance | settings-to-engine-config, engine-health-lifecycle, performance-liveness | high | strong | mixed | 13 | 125 | 1 | Fast logic coverage for the config bridge, health-endpoint identity, tray health debounce, sleep/power policies, and queue backpressure. |
| engine-db-recovery-cli | screenpipe-engine | windows, macos, linux | database, engine-lifecycle | engine-health-lifecycle, performance-liveness | high | strong | unit | 1 | 33 | 0 | Exact DB/WAL/SHM working-copy preservation, rollback on archive failure, and restart repair for crashes during the multi-file generation swap. |
@@ -357,7 +357,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-search-indexing | screenpipe-db | tests/search_ocr_snapshot_test.rs | integration | 4 | 0 | 4 |
| db-timeline-frames | screenpipe-db | tests/semantic_storage_test.rs | integration | 13 | 0 | 13 |
| db-audio-meetings-speakers | screenpipe-db | tests/single_open_meeting_invariant_test.rs | integration | 3 | 0 | 3 |
-| db-timeline-frames | screenpipe-db | tests/snapshot_compaction_test.rs | integration | 2 | 0 | 2 |
+| db-timeline-frames | screenpipe-db | tests/snapshot_compaction_test.rs | integration | 4 | 0 | 4 |
| db-audio-meetings-speakers | screenpipe-db | tests/speaker_benchmark.rs | integration | 0 | 1 | 1 |
| db-audio-meetings-speakers | screenpipe-db | tests/speaker_delete_test.rs | integration | 3 | 0 | 3 |
| db-audio-meetings-speakers | screenpipe-db | tests/speaker_identity_eval.rs | integration | 4 | 0 | 4 |
@@ -486,7 +486,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| engine-api-routes | screenpipe-engine | src/routes/structured_outputs.rs | source | 1 | 0 | 1 |
| engine-api-routes | screenpipe-engine | src/routes/time.rs | source | 12 | 0 | 12 |
| engine-api-routes | screenpipe-engine | src/routes/timezone.rs | source | 8 | 0 | 8 |
-| engine-api-routes | screenpipe-engine | src/routes/websocket.rs | source | 4 | 0 | 4 |
+| engine-api-routes | screenpipe-engine | src/routes/websocket.rs | source | 5 | 0 | 5 |
| engine-workflows | screenpipe-engine | src/routes/workflow_catalog.rs | source | 7 | 0 | 7 |
| engine-workflows | screenpipe-engine | src/routes/workflow_edits.rs | source | 16 | 0 | 16 |
| engine-workflows | screenpipe-engine | src/routes/workflow_pipeline.rs | source | 4 | 0 | 4 |