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(enterprise): preserve exports during snapshot compaction (#7662)

Ezra Elletted7886d620261
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 2e08c677d..5471e4c45 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs
@@ -274,6 +274,53 @@ mod tests {
crate::enterprise::sync::tests::check_retained_diagnostic(dir.path()).await;
}
+ #[tokio::test]
+ async fn storage_revocation_cause_survives_support_rotation_and_redaction() {
+ let dir = tempfile::tempdir().unwrap();
+ let db = screenpipe_db::DatabaseManager::new_hybrid(
+ dir.path(),
+ Default::default(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,full_text) VALUES(1,'2026-10-16','[email protected]')").await.unwrap();
+ let export = db.storage_export_token().await.unwrap();
+ db.execute_raw_sql_write("DELETE FROM frames WHERE id=1")
+ .await
+ .unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err();
+ let current = dir.path().join("screenpipe-app.2026-10-16.log");
+ let subscriber = tracing_subscriber::fmt()
+ .with_ansi(false)
+ .with_writer(std::sync::Mutex::new(
+ std::fs::File::create(&current).unwrap(),
+ ))
+ .finish();
+ tracing::subscriber::with_default(subscriber, || {
+ tracing::warn!(%error, "storage read failed; query remains pending");
+ tracing::info!("[email protected]");
+ });
+ drop(export);
+ db.close().await;
+ tokio::fs::rename(&current, dir.path().join("screenpipe-app.2026-10-16.1.log"))
+ .await
+ .unwrap();
+ tokio::fs::write(&current, "INFO recorder restarted\n")
+ .await
+ .unwrap();
+ let report = collect_redacted_from_dirs(&[dir.path().to_path_buf()])
+ .await
+ .unwrap();
+ assert!(report.contains("frame storage: read revision changed"));
+ assert!(report.contains("cause=hybrid_read_revoke_delete_frames"));
+ assert!(report.contains("expected_revocation="));
+ assert!(report.contains("current_revocation="));
+ assert!(report.contains("query remains pending"));
+ assert!(report.contains("recorder restarted"));
+ assert!(!report.contains("[email protected]"));
+ }
+
#[tokio::test]
async fn installer_failure_reaches_redacted_support_bundle() {
let dir = tempfile::tempdir().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 7cac9d0be..fcf41176f 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs
@@ -2344,7 +2344,7 @@ mod imp {
struct CapturingLocal {
db: Arc<screenpipe_db::DatabaseManager>,
change: u8,
- selected: std::sync::atomic::AtomicBool,
+ reads: std::sync::atomic::AtomicUsize,
}
#[async_trait::async_trait]
impl LocalApiClient for CapturingLocal {
@@ -2359,9 +2359,7 @@ mod imp {
_: u32,
_: u32,
) -> Result<Vec<FrameRow>, EnterpriseSyncError> {
- let first = !self
- .selected
- .swap(true, std::sync::atomic::Ordering::SeqCst);
+ 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
.db
@@ -2399,6 +2397,17 @@ mod imp {
.await
.unwrap();
}
+ 4 => {
+ 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();
+ }
_ => {}
}
}
@@ -2414,7 +2423,7 @@ mod imp {
Ok(Vec::new())
}
}
- for (change, hybrid) in (0..4).flat_map(|change| [(change, false), (change, true)]) {
+ for (change, hybrid) in (0..5).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
@@ -2437,6 +2446,9 @@ 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 {
+ 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();
+ }
let server = wiremock::MockServer::start().await;
wiremock::Mock::given(wiremock::matchers::path("/ingest"))
.respond_with(wiremock::ResponseTemplate::new(200))
@@ -2448,7 +2460,7 @@ mod imp {
let local = CapturingLocal {
db: db.clone(),
change,
- selected: std::sync::atomic::AtomicBool::new(false),
+ reads: std::sync::atomic::AtomicUsize::new(0),
};
let result =
sync::run_one_sync(&cfg, &mut cursor, &local, &reqwest::Client::new()).await;
@@ -2472,9 +2484,16 @@ mod imp {
!body.contains("new capture"),
"new rows belong to the next page"
);
- assert_eq!(body.contains("pending upload"), change == 0);
+ assert_eq!(body.contains("pending upload"), matches!(change, 0 | 4));
assert_eq!(body.contains("[REDACTED]"), change == 2);
}
+ if hybrid && change == 4 {
+ assert_eq!(
+ local.reads.load(std::sync::atomic::Ordering::SeqCst),
+ 1,
+ "physical compaction must not force an export refresh"
+ );
+ }
server.verify().await;
let captured = db
.frame_payloads(&[3], screenpipe_db::storage::Projection::All)
diff --git a/crates/screenpipe-db/src/db/setup.rs b/crates/screenpipe-db/src/db/setup.rs
index c3cee3399..49ac7a308 100644
--- a/crates/screenpipe-db/src/db/setup.rs
+++ b/crates/screenpipe-db/src/db/setup.rs
@@ -554,7 +554,8 @@ impl DatabaseManager {
let cleanup_indexes_changed =
crate::storage::schema::ensure_cleanup_indexes(&mut conn, storage.has_bulk())
.await?;
- crate::storage::read_schema::upgrade(&mut conn, storage).await?;
+ let read_hooks_changed =
+ crate::storage::read_schema::upgrade(&mut conn, storage).await?;
let resident_hooks_changed = crate::storage::schema::ensure_resident_table_hooks(
&mut conn,
storage.has_bulk(),
@@ -562,7 +563,11 @@ impl DatabaseManager {
.await?;
storage.verify_catalog(&db_manager.pool).await?;
drop(conn);
- if upgraded || cleanup_indexes_changed || resident_hooks_changed {
+ if upgraded
+ || cleanup_indexes_changed
+ || read_hooks_changed
+ || resident_hooks_changed
+ {
// Connections opened before the trigger migration need a
// schema read before their first DML preparation. Refresh
// every existing writer while startup still owns admission.
diff --git a/crates/screenpipe-db/src/storage/maintenance.rs b/crates/screenpipe-db/src/storage/maintenance.rs
index 2542e1ed8..5d5351bad 100644
--- a/crates/screenpipe-db/src/storage/maintenance.rs
+++ b/crates/screenpipe-db/src/storage/maintenance.rs
@@ -398,7 +398,7 @@ pub async fn export_sqlite(
let mut output=sqlx::SqliteConnection::connect_with(&sqlx::sqlite::SqliteConnectOptions::new().filename(&index)).await?;
let triggers:Vec<String>=sqlx::query_scalar("SELECT name FROM sqlite_master WHERE type='trigger' AND name LIKE 'hybrid_%'").fetch_all(&mut output).await?;
for name in triggers {sqlx::raw_sql(sqlx::AssertSqlSafe(format!("DROP TRIGGER \"{}\"",name.replace('"',"\"\"")))).execute(&mut output).await?;}
- sqlx::raw_sql("DROP VIEW IF EXISTS _bulk_element_search; DROP TABLE IF EXISTS _bulk_element_lookup; DROP TABLE IF EXISTS _storage_revocation;").execute(&mut output).await?;
+ sqlx::raw_sql("DROP VIEW IF EXISTS _bulk_element_search; DROP TABLE IF EXISTS _bulk_element_lookup; DROP TABLE IF EXISTS _storage_revocation; DROP TABLE IF EXISTS _storage_revocation_cause;").execute(&mut output).await?;
super::bulk::export(&source,&mut output).await?;
sqlx::raw_sql("DROP TABLE frames_fts; DROP TABLE frame_payloads; DROP TABLE payload_files; DROP TABLE upload_bindings; DROP TABLE storage_metadata; DROP TABLE _hybrid_migrations;").execute(&mut output).await?;
// A standalone export starts a new conversion if imported again. Its
diff --git a/crates/screenpipe-db/src/storage/read_schema.rs b/crates/screenpipe-db/src/storage/read_schema.rs
index e1b1bed7c..37410a54f 100644
--- a/crates/screenpipe-db/src/storage/read_schema.rs
+++ b/crates/screenpipe-db/src/storage/read_schema.rs
@@ -32,7 +32,7 @@ BEGIN UPDATE _storage_revocation SET revision=revision+1; END;
pub(crate) async fn upgrade(
conn: &mut SqliteConnection,
storage: &HybridStorage,
-) -> Result<(), sqlx::Error> {
+) -> Result<bool, sqlx::Error> {
use sha2::{Digest, Sha256};
let checksum = format!(
"{:x}",
@@ -46,7 +46,7 @@ pub(crate) async fn upgrade(
.await?;
if let Some(installed) = installed {
return if installed == checksum {
- Ok(())
+ upgrade_export_revocation(conn).await
} else {
Err(storage_error("read schema checksum mismatch"))
};
@@ -123,7 +123,92 @@ pub(crate) async fn upgrade(
.await?;
}
tx.commit().await?;
- Ok(())
+ upgrade_export_revocation(conn).await
+}
+
+/// Preserve v3's recorded identity, but upgrade installed hooks atomically.
+/// Snapshot compaction moves the same image into a video. All other updates,
+/// deletions and privacy-policy changes retain their existing revocation rules.
+async fn upgrade_export_revocation(conn: &mut SqliteConnection) -> Result<bool, sqlx::Error> {
+ const IDENTITY: &str = "export-revocation-causes-and-frame-locators-v7";
+ let installed: Option<String> =
+ sqlx::query_scalar("SELECT checksum FROM _hybrid_migrations WHERE version=7")
+ .fetch_optional(&mut *conn)
+ .await?;
+ if let Some(installed) = installed {
+ return if installed == IDENTITY {
+ Ok(false)
+ } else {
+ Err(storage_error("export revocation schema checksum mismatch"))
+ };
+ }
+ let mut tx = conn.begin().await?;
+ sqlx::raw_sql("CREATE TABLE IF NOT EXISTS _storage_revocation_cause(id INTEGER PRIMARY KEY CHECK(id=1),cause TEXT NOT NULL); INSERT OR IGNORE INTO _storage_revocation_cause VALUES(1,'unknown_before_upgrade');")
+ .execute(&mut *tx).await?;
+ let columns: Vec<String> = sqlx::query_scalar("SELECT name FROM pragma_table_info('frames')")
+ .fetch_all(&mut *tx)
+ .await?;
+ const MEDIA: [&str; 3] = ["video_chunk_id", "offset_index", "snapshot_path"];
+ let content_updates = columns
+ .iter()
+ .filter(|column| !MEDIA.contains(&column.as_str()))
+ .map(|column| format!("\"{}\"", column.replace('"', "\"\"")))
+ .collect::<Vec<_>>()
+ .join(",");
+ let hooks: Vec<(String, String)> = sqlx::query_as(
+ "SELECT name,sql FROM sqlite_master WHERE type='trigger' AND name GLOB 'hybrid_read_revoke_*'",
+ ).fetch_all(&mut *tx).await?;
+ for (name, sql) in hooks {
+ let sql = if sql.contains("UPDATE _storage_revocation_cause") {
+ sql
+ } else {
+ sql.replace(
+ "UPDATE _storage_revocation SET revision=revision+1;",
+ &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
+ };
+ sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
+ "DROP TRIGGER \"{}\"; {sql}",
+ name.replace('"', "\"\"")
+ )))
+ .execute(&mut *tx)
+ .await?;
+ }
+ sqlx::query("INSERT INTO _hybrid_migrations VALUES(7,?)")
+ .bind(IDENTITY)
+ .execute(&mut *tx)
+ .await?;
+ tx.commit().await?;
+ Ok(true)
+}
+
+fn revocation(trigger: &str, with_cause: bool) -> String {
+ let cause = if with_cause {
+ format!(
+ " UPDATE _storage_revocation_cause SET cause='{}' WHERE id=1;",
+ trigger.replace('\'', "''")
+ )
+ } else {
+ String::new()
+ };
+ format!("UPDATE _storage_revocation SET revision=revision+1;{cause}")
}
// Shared by initial conversion and tables introduced by later SQLx migrations.
@@ -137,8 +222,14 @@ pub(super) async fn install_resident_hooks(
.await?;
let escaped = table.replace('"', "\"\"");
let quoted = format!("\"{escaped}\"");
+ let with_cause: bool = sqlx::query_scalar(
+ "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='_storage_revocation_cause')",
+ )
+ .fetch_one(&mut *conn)
+ .await?;
+ let deletion = revocation(&format!("hybrid_read_revoke_delete_{table}"), with_cause);
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
- "CREATE TRIGGER IF NOT EXISTS \"hybrid_read_revoke_delete_{escaped}\" AFTER DELETE ON {quoted} BEGIN UPDATE _storage_revocation SET revision=revision+1; END;"
+ "CREATE TRIGGER IF NOT EXISTS \"hybrid_read_revoke_delete_{escaped}\" AFTER DELETE ON {quoted} BEGIN {deletion} END;"
))).execute(&mut *conn).await?;
let redacted = columns
.iter()
@@ -147,9 +238,105 @@ pub(super) async fn install_resident_hooks(
.collect::<Vec<_>>()
.join(" OR ");
if !redacted.is_empty() {
+ let update = revocation(&format!("hybrid_read_revoke_redaction_{table}"), with_cause);
sqlx::raw_sql(sqlx::AssertSqlSafe(format!(
- "CREATE TRIGGER IF NOT EXISTS \"hybrid_read_revoke_redaction_{escaped}\" AFTER UPDATE ON {quoted} WHEN (SELECT maintenance=0 FROM storage_metadata) AND ({redacted}) BEGIN UPDATE _storage_revocation SET revision=revision+1; END;"
+ "CREATE TRIGGER IF NOT EXISTS \"hybrid_read_revoke_redaction_{escaped}\" AFTER UPDATE ON {quoted} WHEN (SELECT maintenance=0 FROM storage_metadata) AND ({redacted}) BEGIN {update} END;"
))).execute(&mut *conn).await?;
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::DatabaseManager;
+
+ #[tokio::test]
+ async fn existing_revocation_hooks_upgrade_atomically_and_survive_reopen() {
+ let root = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new_hybrid(root.path(), Default::default(), Default::default())
+ .await
+ .unwrap();
+ let identities: Vec<(i64, String)> = sqlx::query_as(
+ "SELECT version,checksum FROM _hybrid_migrations WHERE version<7 ORDER BY version",
+ )
+ .fetch_all(&db.pool)
+ .await
+ .unwrap();
+ // Restore the installed pre-v7 hooks, including the unconditional
+ // redacted-frame update hook. No stored recordings are rewritten.
+ let mut tx = db.begin_immediate_with_retry().await.unwrap();
+ let hooks: Vec<(String, String)> = sqlx::query_as(
+ "SELECT name,sql FROM sqlite_master WHERE type='trigger' AND name GLOB 'hybrid_read_revoke_*'"
+ ).fetch_all(&mut **tx.conn()).await.unwrap();
+ for (name, sql) in hooks {
+ sqlx::raw_sql(sqlx::AssertSqlSafe(format!("DROP TRIGGER \"{name}\"")))
+ .execute(&mut **tx.conn())
+ .await
+ .unwrap();
+ if name == "hybrid_read_revoke_media_frames" {
+ continue;
+ }
+ let mut sql = sql.replace(&revocation(&name, true), &revocation(&name, false));
+ if name == "hybrid_read_revoke_redaction_frames" {
+ let start = sql.find("AFTER UPDATE OF").unwrap();
+ let end = start + sql[start..].find(" ON ").unwrap();
+ sql.replace_range(start..end, "AFTER UPDATE");
+ }
+ sqlx::raw_sql(sqlx::AssertSqlSafe(sql))
+ .execute(&mut **tx.conn())
+ .await
+ .unwrap();
+ }
+ sqlx::raw_sql(
+ "DROP TABLE _storage_revocation_cause; DELETE FROM _hybrid_migrations WHERE version=7;",
+ )
+ .execute(&mut **tx.conn())
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+ db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,full_text,snapshot_path) VALUES(1,'2026-10-16','retained','redacted.jpg'); UPDATE frames SET image_redacted_at=1 WHERE id=1;").await.unwrap();
+ db.close().await;
+ for reopen in 0..2 {
+ let db = DatabaseManager::new(
+ root.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(identities, sqlx::query_as::<_,(i64,String)>(
+ "SELECT version,checksum FROM _hybrid_migrations WHERE version<7 ORDER BY version"
+ ).fetch_all(&db.pool).await.unwrap());
+ let export = db.storage_export_token().await.unwrap();
+ if reopen == 0 {
+ let chunk = db
+ .insert_video_chunk_with_fps("compacted.mp4", "test", 1.0)
+ .await
+ .unwrap();
+ db.compact_snapshots_queued(chunk, vec![(1, 0)])
+ .await
+ .unwrap();
+ drop(export.admit(&db.pool).await.unwrap());
+ } else {
+ db.execute_raw_sql_write("UPDATE frames SET image_redacted_at=1 WHERE id=1")
+ .await
+ .unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err().to_string();
+ assert!(
+ error.contains("cause=hybrid_read_revoke_redaction_frames"),
+ "{error}"
+ );
+ }
+ assert_eq!(
+ db.frame_payloads(&[1], super::super::Projection::All)
+ .await
+ .unwrap()[&1]
+ .full_text
+ .as_deref(),
+ Some("retained")
+ );
+ drop(export);
+ db.close().await;
+ }
+ }
+}
diff --git a/crates/screenpipe-db/src/storage/reader.rs b/crates/screenpipe-db/src/storage/reader.rs
index c3336b9e1..5c899262a 100644
--- a/crates/screenpipe-db/src/storage/reader.rs
+++ b/crates/screenpipe-db/src/storage/reader.rs
@@ -53,14 +53,14 @@ impl StorageReadToken {
return Err(sqlx::Error::PoolClosed);
}
if let Some(expected) = self.revocation {
- let current: i64 =
- sqlx::query_scalar("SELECT revision FROM _storage_revocation WHERE id=1")
+ let (current, cause): (i64, String) =
+ sqlx::query_as("SELECT revision,(SELECT cause FROM _storage_revocation_cause WHERE id=1) FROM _storage_revocation WHERE id=1")
.fetch_one(pool)
.await?;
if current != expected {
- return Err(storage_error(
- "read revision changed; retry the complete query",
- ));
+ return Err(storage_error(format!(
+ "read revision changed; retry the complete query (expected_revocation={expected}, current_revocation={current}, cause={cause})"
+ )));
}
return Ok(Some(gate));
}
diff --git a/crates/screenpipe-db/tests/snapshot_compaction_test.rs b/crates/screenpipe-db/tests/snapshot_compaction_test.rs
index 61fb5861f..734eaecb1 100644
--- a/crates/screenpipe-db/tests/snapshot_compaction_test.rs
+++ b/crates/screenpipe-db/tests/snapshot_compaction_test.rs
@@ -83,3 +83,107 @@ async fn compaction_repoints_every_selected_frame_only_and_survives_restart() {
);
reopened.close().await;
}
+
+#[tokio::test]
+async fn compaction_of_redacted_snapshots_preserves_export_admission() {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new_hybrid(dir.path(), Default::default(), Default::default())
+ .await
+ .unwrap();
+ let frame = snapshot(&db, "redacted.jpg").await;
+ db.execute_raw_sql_write(&format!(
+ "UPDATE frames SET full_text_redacted_at=1,image_redacted_at=1 WHERE id={frame}"
+ ))
+ .await
+ .unwrap();
+ let export = db.storage_export_token().await.unwrap();
+ let chunk = db
+ .insert_video_chunk_with_fps("compacted.mp4", "compaction-test", 1.0)
+ .await
+ .unwrap();
+ let (compacted, captured) = tokio::join!(
+ db.compact_snapshots_queued(chunk, vec![(frame, 0)]),
+ snapshot(&db, "concurrent.jpg")
+ );
+ compacted.unwrap();
+ drop(
+ export
+ .admit(&db.pool)
+ .await
+ .expect("physical compaction revoked export"),
+ );
+ assert_eq!(
+ db.get_frame(frame).await.unwrap(),
+ Some(("compacted.mp4".into(), 0, false))
+ );
+ assert_eq!(
+ db.get_frame(captured).await.unwrap(),
+ Some(("concurrent.jpg".into(), 0, true))
+ );
+ drop(export);
+ db.execute_raw_sql_write(&format!(
+ "UPDATE frames SET image_redacted_at=1 WHERE id={captured}"
+ ))
+ .await
+ .unwrap();
+ let export = db.storage_export_token().await.unwrap();
+ // Clearing a reference without replacement media is not compaction.
+ db.clear_snapshot_paths_queued(vec![captured])
+ .await
+ .unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err().to_string();
+ assert!(
+ error.contains("cause=hybrid_read_revoke_media_frames"),
+ "{error}"
+ );
+ drop(export);
+
+ let export = db.storage_export_token().await.unwrap();
+ // An image can be redacted twice in one timestamp second. Even an
+ // unchanged watermark must revoke the previously prepared image bytes.
+ db.execute_raw_sql_write(&format!(
+ "UPDATE frames SET image_redacted_at=1 WHERE id={frame}"
+ ))
+ .await
+ .unwrap();
+ assert!(export.admit(&db.pool).await.is_err());
+ drop(export);
+
+ // A combined relocation + same-second redaction must not take the
+ // physical-only exception, even when the watermark value is identical.
+ db.execute_raw_sql_write(&format!(
+ "UPDATE frames SET snapshot_path='again.jpg' WHERE id={frame}"
+ ))
+ .await
+ .unwrap();
+ let chunk = db
+ .insert_video_chunk_with_fps("mixed.mp4", "compaction-test", 1.0)
+ .await
+ .unwrap();
+ let export = db.storage_export_token().await.unwrap();
+ db.execute_raw_sql_write(&format!("UPDATE frames SET video_chunk_id={chunk},offset_index=0,snapshot_path=NULL,image_redacted_at=1 WHERE id={frame}"))
+ .await.unwrap();
+ let error = export.admit(&db.pool).await.unwrap_err().to_string();
+ assert!(
+ error.contains("cause=hybrid_read_revoke_redaction_frames"),
+ "{error}"
+ );
+ drop(export);
+ db.close().await;
+ let db = DatabaseManager::new(
+ dir.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let payloads = db
+ .frame_payloads(&[frame, captured], screenpipe_db::storage::Projection::All)
+ .await
+ .unwrap();
+ assert_eq!(payloads[&frame].full_text.as_deref(), Some("retained text"));
+ assert_eq!(
+ payloads[&captured].full_text.as_deref(),
+ Some("retained text")
+ );
+ db.close().await;
+}
diff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.md
index 1255e3fec..40f8e7cf6 100644
--- a/docs/coverage/CORE.md
+++ b/docs/coverage/CORE.md
@@ -133,7 +133,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| audio-windows-parakeet-provider | screenpipe-audio | windows | audio, transcription | audio-record-transcribe | high | partial | unit | 1 | 6 | 0 | Registers existing CPU override, eligible adapter selection, DXGI ordinal, error fallback and adapter determinism tests. Windows-only; manifest registration does not verify execution on physical GPU hardware. |
| db-accessibility-ui-events | screenpipe-db | windows, macos, linux | database, configuration, accessibility, ui-events, performance | settings-to-engine-config, accessibility-ui-events, performance-liveness | medium | partial | integration | 7 | 28 | 2 | Elements bulk insert, on-screen filtering, UI event batching, DB tier config, and ignored heavy-read real-DB probes. |
| 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 | 16 | 50 | 6 | 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-runtime-reliability | screenpipe-db | windows, macos, linux | database, performance | performance-liveness | high | partial | mixed | 17 | 51 | 6 | 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 | 106 | 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 | 39 | 307 | 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 | 45 | 430 | 7 | Route/unit coverage for search, health, streaming, meetings, time/timezone, and transcription. Legacy endpoint/websocket tests require local data and remain ignored. |
@@ -295,6 +295,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-timeline-frames | screenpipe-db | src/storage/diagnostics.rs | source | 7 | 0 | 7 |
| db-timeline-frames | screenpipe-db | src/storage/lifecycle.rs | source | 3 | 1 | 4 |
| db-timeline-frames | screenpipe-db | src/storage/parity.rs | source | 2 | 0 | 2 |
+| db-runtime-reliability | screenpipe-db | src/storage/read_schema.rs | source | 1 | 0 | 1 |
| db-runtime-reliability | screenpipe-db | src/storage/reader.rs | source | 7 | 0 | 7 |
| db-timeline-frames | screenpipe-db | src/storage/reclaim.rs | source | 3 | 1 | 4 |
| db-timeline-frames | screenpipe-db | src/storage/schema.rs | source | 3 | 1 | 4 |
@@ -350,7 +351,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 | 1 | 0 | 1 |
+| db-timeline-frames | screenpipe-db | tests/snapshot_compaction_test.rs | integration | 2 | 0 | 2 |
| 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 |
diff --git a/docs/coverage/core-engine-map.json b/docs/coverage/core-engine-map.json
index 5f26a63f6..a8404dc9d 100644
--- a/docs/coverage/core-engine-map.json
+++ b/docs/coverage/core-engine-map.json
@@ -748,6 +748,7 @@
"src/failpoint_vfs.rs",
"src/recovery.rs",
"src/sqlite_error.rs",
+ "src/storage/read_schema.rs",
"src/storage/reader.rs",
"tests/cancellable_query_test.rs",
"tests/cancellation_performance_bench.rs",