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: prevent background privacy history starvation (#7785)

Louis Beaumonta3389cc18046
diff --git a/crates/screenpipe-redact/src/image/worker.rs b/crates/screenpipe-redact/src/image/worker.rs
index 8cfeab798..96ba2bb12 100644
--- a/crates/screenpipe-redact/src/image/worker.rs
+++ b/crates/screenpipe-redact/src/image/worker.rs
@@ -291,7 +291,12 @@ impl ImageWorker {
return self.process_release_image(db).await;
}
}
- let row = sqlx::query(
+ let order = if self.release_oldest.fetch_xor(true, Ordering::SeqCst) {
+ "ASC"
+ } else {
+ "DESC"
+ };
+ let row = sqlx::query(sqlx::AssertSqlSafe(format!(
r#"
SELECT f.id, f.name,
CASE
@@ -309,10 +314,10 @@ impl ImageWorker {
WHERE f.name IS NOT NULL
AND f.image_redacted_at IS NULL
AND ( strftime('%s','now') - CAST(strftime('%s', f.timestamp) AS INTEGER) ) >= ?1
- ORDER BY f.id DESC
+ ORDER BY f.id {order}
LIMIT 1
"#,
- )
+ )))
.bind(self.cfg.min_age_seconds)
.bind(self.cfg.max_a11y_age_seconds)
.fetch_optional(&self.pool)
@@ -534,6 +539,35 @@ mod tests {
pool
}
+ #[tokio::test]
+ async fn background_image_history_progresses_while_new_frames_arrive() {
+ let pool = setup().await;
+ let root = tempfile::tempdir().unwrap();
+ let path = root.path().join("image.png");
+ white_test_image(&path);
+ sqlx::query("INSERT INTO frames(id,timestamp,name) VALUES(1,'2020-01-01',?)")
+ .bind(path.to_str().unwrap())
+ .execute(&pool)
+ .await
+ .unwrap();
+ let worker = ImageWorker::new(pool.clone(), Arc::new(StubRedactor), Default::default());
+ for id in 2..=5 {
+ sqlx::query("INSERT INTO frames(id,timestamp,name) VALUES(?,'2020-01-02',?)")
+ .bind(id)
+ .bind(path.to_str().unwrap())
+ .execute(&pool)
+ .await
+ .unwrap();
+ assert!(worker.process_one().await.unwrap().is_some());
+ }
+ let done: bool =
+ sqlx::query_scalar("SELECT image_redacted_at IS NOT NULL FROM frames WHERE id=1")
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert!(done, "new images starved historical background processing");
+ }
+
#[tokio::test]
async fn empty_image_queue_releases_cpu_lane_before_idle_poll() {
let pool = setup().await;
diff --git a/crates/screenpipe-redact/src/worker/backlog_tests.rs b/crates/screenpipe-redact/src/worker/backlog_tests.rs
new file mode 100644
index 000000000..ef3ec463a
--- /dev/null
+++ b/crates/screenpipe-redact/src/worker/backlog_tests.rs
@@ -0,0 +1,56 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+use super::*;
+
+#[tokio::test]
+async fn background_surfaces_make_independent_history_progress() {
+ let root = tempfile::tempdir().unwrap();
+ let db = screenpipe_db::DatabaseManager::new(
+ root.path().join("db.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let worker = Worker::new_with_writer(
+ db.pool.clone(),
+ db.coordinated_writer(),
+ Arc::new(Pipeline::regex_only()),
+ WorkerConfig::default(),
+ );
+ // Interleave surfaces: one global alternating bit would permanently give
+ // some tables only newest-first turns when an even number are enabled.
+ for id in 1..=5 {
+ db.execute_raw_sql_write(&format!(
+ "INSERT INTO frames(id,timestamp,full_text) VALUES({id},'2020-01-01','[email protected]');
+ INSERT INTO frames(id,timestamp,accessibility_text) VALUES(1000+{id},'2020-01-01','[email protected]');
+ INSERT INTO ui_events(id,timestamp,event_type,text_content) VALUES({id},'2020-01-01','text','[email protected]');
+ INSERT INTO elements(id,frame_id,source,role,text) VALUES({id},{id},'accessibility','AXTextField','[email protected]');"
+ )).await.unwrap();
+ if id > 1 {
+ for table in [
+ TargetTable::FullText,
+ TargetTable::Accessibility,
+ TargetTable::UiEvents,
+ TargetTable::Elements,
+ ] {
+ assert_eq!(worker.process_one(table, 1).await.unwrap(), 1);
+ }
+ }
+ }
+ for query in [
+ "SELECT full_text_redacted_at IS NOT NULL FROM frames WHERE id=1",
+ "SELECT accessibility_redacted_at IS NOT NULL FROM frames WHERE id=1001",
+ "SELECT redacted_at IS NOT NULL FROM ui_events WHERE id=1",
+ "SELECT redacted_at IS NOT NULL FROM elements WHERE id=1",
+ ] {
+ assert!(
+ sqlx::query_scalar::<_, bool>(sqlx::AssertSqlSafe(query))
+ .fetch_one(&db.pool)
+ .await
+ .unwrap(),
+ "history starved: {query}"
+ );
+ }
+ db.close().await;
+}
diff --git a/crates/screenpipe-redact/src/worker/hybrid.rs b/crates/screenpipe-redact/src/worker/hybrid.rs
index 1929beceb..20362eec6 100644
--- a/crates/screenpipe-redact/src/worker/hybrid.rs
+++ b/crates/screenpipe-redact/src/worker/hybrid.rs
@@ -53,11 +53,19 @@ impl Worker {
required_surfaces: required,
})
.await?;
- let ids:Vec<i64>=sqlx::query_scalar("SELECT p.frame_id FROM frame_payloads p CROSS JOIN storage_metadata m WHERE (p.completed_surfaces & m.required_surfaces)!=m.required_surfaces AND (p.retry_at IS NULL OR p.retry_at<=strftime('%s','now')) ORDER BY p.frame_id DESC LIMIT ?")
+ let order = if self.background_oldest(super::TargetTable::FullText).await {
+ "ASC"
+ } else {
+ "DESC"
+ };
+ let ids:Vec<i64>=sqlx::query_scalar(sqlx::AssertSqlSafe(format!("SELECT p.frame_id FROM frame_payloads p CROSS JOIN storage_metadata m WHERE (p.completed_surfaces & m.required_surfaces)!=m.required_surfaces AND (p.retry_at IS NULL OR p.retry_at<=strftime('%s','now')) ORDER BY p.frame_id {order} LIMIT ?")))
.bind(limit).fetch_all(&db.pool).await?;
let mut count = 0;
for id in ids {
- let token = db.storage_read_token().await?;
+ // Ordinary captures and archival do not revoke an older payload.
+ // Its read pins its own files; deletion/privacy still revoke this token,
+ // and replacement below compares both generation and policy.
+ let token = db.storage_export_token().await?;
let Some(mut payload) = db.frame_payloads(&[id], Projection::All).await?.remove(&id)
else {
continue;
diff --git a/crates/screenpipe-redact/src/worker/mod.rs b/crates/screenpipe-redact/src/worker/mod.rs
index 0b48ed87d..15541a592 100644
--- a/crates/screenpipe-redact/src/worker/mod.rs
+++ b/crates/screenpipe-redact/src/worker/mod.rs
@@ -12,10 +12,11 @@
//! / migration backfill workers in shape — pause / resume / status,
//! idle-aware scheduling knobs, retry-with-backoff on transient errors.
//!
-//! Deliberately newest-first. Users search recent activity; redacting
-//! oldest-first means the most-likely-to-be-queried rows have stale
-//! redactions until the worker catches up.
+//! Alternate recent and historical batches independently per surface so
+//! recent activity stays responsive without starving history during capture.
+#[cfg(test)]
+mod backlog_tests;
mod columns;
mod hybrid;
mod release;
@@ -131,6 +132,7 @@ pub struct WorkerStatus {
pub struct Worker {
release_db: Option<Arc<screenpipe_db::DatabaseManager>>,
release_scheduler: Arc<Mutex<release::ReleaseScheduler>>,
+ background_order: Arc<Mutex<HashMap<TargetTable, bool>>>,
frame_storage: Option<Arc<screenpipe_db::DatabaseManager>>,
pool: SqlitePool,
writer: SqliteWritePool,
@@ -157,6 +159,7 @@ impl Worker {
frame_storage: None,
release_db: None,
release_scheduler: Arc::new(Mutex::new(Default::default())),
+ background_order: Arc::new(Mutex::new(HashMap::new())),
pool,
writer,
redactor,
@@ -167,6 +170,14 @@ impl Worker {
}
}
+ async fn background_oldest(&self, table: TargetTable) -> bool {
+ let mut order = self.background_order.lock().await;
+ let next = order.entry(table).or_default();
+ let oldest = *next;
+ *next = !*next;
+ oldest
+ }
+
/// Route typed SQLx failures to the database owner. Non-database errors
/// never invoke this hook.
pub fn with_database_error_hook(mut self, hook: DatabaseErrorHook) -> Self {
@@ -563,7 +574,12 @@ impl Worker {
return Ok(0);
}
let fields = cols.a11y_json_fields();
- let rows = tables::fetch_unredacted_elements(&self.pool, batch_size).await?;
+ let rows = tables::fetch_unredacted_elements(
+ &self.pool,
+ batch_size,
+ self.background_oldest(TargetTable::Elements).await,
+ )
+ .await?;
if rows.is_empty() {
return Ok(0);
}
@@ -704,7 +720,13 @@ impl Worker {
if active.is_empty() {
return Ok(0);
}
- let rows = tables::fetch_unredacted_ui_events(&self.pool, &active, batch_size).await?;
+ let rows = tables::fetch_unredacted_ui_events(
+ &self.pool,
+ &active,
+ batch_size,
+ self.background_oldest(TargetTable::UiEvents).await,
+ )
+ .await?;
if rows.is_empty() {
return Ok(0);
}
@@ -811,7 +833,12 @@ impl Worker {
/// yield a value map (the span-less enclave). Returns the number of
/// column writes performed.
async fn process_frames_fulltext(&self, batch_size: u32) -> Result<u32, anyhow::Error> {
- let rows = tables::fetch_unredacted_frames_fulltext(&self.pool, batch_size).await?;
+ let rows = tables::fetch_unredacted_frames_fulltext(
+ &self.pool,
+ batch_size,
+ self.background_oldest(TargetTable::FullText).await,
+ )
+ .await?;
if rows.is_empty() {
return Ok(0);
}
@@ -1148,7 +1175,13 @@ impl Worker {
table: TargetTable,
batch_size: u32,
) -> Result<u32, anyhow::Error> {
- let rows = tables::fetch_unredacted(&self.pool, table, batch_size).await?;
+ let rows = tables::fetch_unredacted(
+ &self.pool,
+ table,
+ batch_size,
+ self.background_oldest(table).await,
+ )
+ .await?;
if rows.is_empty() {
return Ok(0);
}
diff --git a/crates/screenpipe-redact/src/worker/tables.rs b/crates/screenpipe-redact/src/worker/tables.rs
index fce7c362b..30c6e72bf 100644
--- a/crates/screenpipe-redact/src/worker/tables.rs
+++ b/crates/screenpipe-redact/src/worker/tables.rs
@@ -50,7 +50,7 @@
use sqlx::{Row, SqlitePool};
-#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TargetTable {
/// Speech-to-text (`audio_transcriptions.transcription`).
@@ -241,7 +241,9 @@ pub async fn fetch_unredacted(
pool: &SqlitePool,
table: TargetTable,
limit: u32,
+ oldest: bool,
) -> Result<Vec<UnredactedRow>, sqlx::Error> {
+ let order = if oldest { "ASC" } else { "DESC" };
debug_assert!(
table != TargetTable::UiEvents,
"UiEvents is multi-column; call fetch_unredacted_ui_events"
@@ -256,7 +258,7 @@ pub async fn fetch_unredacted(
WHERE {src} IS NOT NULL AND {src} != '' \
AND {redacted_at} IS NULL\
{extra} \
- ORDER BY {pk} DESC \
+ ORDER BY {pk} {order} \
LIMIT ?",
pk = table.pk_col(),
src = table.source_col(),
@@ -329,13 +331,16 @@ pub struct FrameTextRow {
}
/// Fetch up to `limit` frames whose `full_text` needs redaction
-/// (newest-first), carrying the sibling derived copies + their watermarks
+/// (alternating order chosen by the worker), carrying the sibling derived copies + their watermarks
/// so the caller can scrub them all from one detection pass.
pub async fn fetch_unredacted_frames_fulltext(
pool: &SqlitePool,
limit: u32,
+ oldest: bool,
) -> Result<Vec<FrameTextRow>, sqlx::Error> {
- let q = "SELECT id, full_text, accessibility_text, accessibility_redacted_at, \
+ let order = if oldest { "ASC" } else { "DESC" };
+ let q = format!(
+ "SELECT id, full_text, accessibility_text, accessibility_redacted_at, \
accessibility_tree_json, accessibility_tree_redacted_at, \
window_name, window_name_redacted_at, \
browser_url, browser_url_redacted_at, \
@@ -343,9 +348,13 @@ pub async fn fetch_unredacted_frames_fulltext(
FROM frames \
WHERE full_text IS NOT NULL AND full_text != '' \
AND full_text_redacted_at IS NULL \
- ORDER BY id DESC \
- LIMIT ?";
- let rows = sqlx::query(q).bind(limit as i64).fetch_all(pool).await?;
+ ORDER BY id {order} \
+ LIMIT ?"
+ );
+ let rows = sqlx::query(sqlx::AssertSqlSafe(q))
+ .bind(limit as i64)
+ .fetch_all(pool)
+ .await?;
let out = rows
.into_iter()
.map(|r| FrameTextRow {
@@ -490,17 +499,20 @@ pub struct ElementRow {
/// Fetch up to `limit` `elements` rows that still need redaction
/// (`redacted_at IS NULL`) and carry at least one non-empty free-text
/// surface — `text` OR a `properties` JSON that may hold redactable fields.
-/// Newest-first. Container nodes with neither are never fetched (nothing to
+/// Caller-selected order. Container nodes with neither are never fetched (nothing to
/// scrub, and they'd just churn the watermark).
pub async fn fetch_unredacted_elements(
pool: &SqlitePool,
limit: u32,
+ oldest: bool,
) -> Result<Vec<ElementRow>, sqlx::Error> {
+ let order = if oldest { "ASC" } else { "DESC" };
// `properties` is JSON; cheap LIKE pre-filters to rows that actually
// carry one of the redactable string fields, so structural-only nodes
// (is_enabled/role_description-less) never reach the model or even the
// fetch. The `redacted_at IS NULL` index predicate runs first.
- let q = "SELECT id, text, properties \
+ let q = format!(
+ "SELECT id, text, properties \
FROM elements \
WHERE redacted_at IS NULL \
AND ( (text IS NOT NULL AND text != '') \
@@ -510,9 +522,13 @@ pub async fn fetch_unredacted_elements(
OR properties LIKE '%\"help_text\"%' \
OR properties LIKE '%\"role_description\"%' \
OR properties LIKE '%\"url\"%' )) ) \
- ORDER BY id DESC \
- LIMIT ?";
- let rows = sqlx::query(q).bind(limit as i64).fetch_all(pool).await?;
+ ORDER BY id {order} \
+ LIMIT ?"
+ );
+ let rows = sqlx::query(sqlx::AssertSqlSafe(q))
+ .bind(limit as i64)
+ .fetch_all(pool)
+ .await?;
let out = rows
.into_iter()
.map(|r| ElementRow {
@@ -647,7 +663,7 @@ pub struct UiEventTextRow {
/// Fetch up to `limit` `ui_events` rows that still need redaction
/// (`redacted_at IS NULL`) and carry at least one non-empty cell among the
/// caller-supplied `cols` (the configured free-text columns, a subset of
-/// [`UI_EVENT_TEXT_COLS`]). Newest-first. NOT filtered by `event_type`:
+/// [`UI_EVENT_TEXT_COLS`]). Caller-selected order. NOT filtered by `event_type`:
/// clicks and focus events carry element PII (`element_value` of a focused
/// form field) and must be redacted too. The returned `cols` are parallel
/// to the `cols` argument, in the same order.
@@ -655,7 +671,9 @@ pub async fn fetch_unredacted_ui_events(
pool: &SqlitePool,
cols: &[&str],
limit: u32,
+ oldest: bool,
) -> Result<Vec<UiEventTextRow>, sqlx::Error> {
+ let order = if oldest { "ASC" } else { "DESC" };
if cols.is_empty() {
return Err(sqlx::Error::Protocol(
"caller must pass at least one ui_events text column".to_string(),
@@ -677,7 +695,7 @@ pub async fn fetch_unredacted_ui_events(
"SELECT id, {select_cols} \
FROM ui_events \
WHERE redacted_at IS NULL AND ({any_nonempty}) \
- ORDER BY id DESC \
+ ORDER BY id {order} \
LIMIT ?"
);
let rows = sqlx::query(sqlx::AssertSqlSafe(q))
@@ -840,7 +858,7 @@ mod tests {
.await
.unwrap();
- let rows = fetch_unredacted(&pool, TargetTable::FullText, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::FullText, 10, false)
.await
.unwrap();
assert_eq!(rows.len(), 1);
@@ -854,7 +872,7 @@ mod tests {
.execute(&pool)
.await
.unwrap();
- let rows = fetch_unredacted(&pool, TargetTable::FullText, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::FullText, 10, false)
.await
.unwrap();
assert!(rows.is_empty());
@@ -997,7 +1015,7 @@ mod tests {
.await
.unwrap();
}
- let rows = fetch_unredacted(&pool, TargetTable::FullText, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::FullText, 10, false)
.await
.unwrap();
let ids: Vec<i64> = rows.iter().map(|r| r.id).collect();
@@ -1056,7 +1074,7 @@ mod tests {
.await
.unwrap();
- let rows = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10)
+ let rows = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10, false)
.await
.unwrap();
// The click (1), keyboard (2), clipboard (3), and the name/desc row
@@ -1101,7 +1119,7 @@ mod tests {
.execute(&pool)
.await
.unwrap();
- let rows = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10)
+ let rows = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10, false)
.await
.unwrap();
assert!(rows.is_empty());
@@ -1166,7 +1184,7 @@ mod tests {
.await
.unwrap();
- let pending = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10)
+ let pending = fetch_unredacted_ui_events(&pool, UI_EVENT_TEXT_COLS, 10, false)
.await
.unwrap();
assert!(pending.is_empty(), "clean row must be marked done");
@@ -1181,7 +1199,7 @@ mod tests {
.execute(&pool)
.await
.unwrap();
- let rows = fetch_unredacted(&pool, TargetTable::Accessibility, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::Accessibility, 10, false)
.await
.unwrap();
assert_eq!(rows.len(), 1);
@@ -1205,7 +1223,7 @@ mod tests {
.await
.unwrap();
- let rows = fetch_unredacted(&pool, TargetTable::Elements, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::Elements, 10, false)
.await
.unwrap();
assert_eq!(rows.len(), 1);
@@ -1261,7 +1279,7 @@ mod tests {
.execute(&pool)
.await
.unwrap();
- let rows = fetch_unredacted(&pool, TargetTable::FullText, 10)
+ let rows = fetch_unredacted(&pool, TargetTable::FullText, 10, false)
.await
.unwrap();
assert_eq!(rows.len(), 1);
@@ -1310,14 +1328,14 @@ mod tests {
// accessibility_text is still raw and still pending — its
// watermark must be untouched, so the worker still picks it up.
- let pending_a11y = fetch_unredacted(&pool, TargetTable::Accessibility, 10)
+ let pending_a11y = fetch_unredacted(&pool, TargetTable::Accessibility, 10, false)
.await
.unwrap();
assert_eq!(pending_a11y.len(), 1, "accessibility row must stay pending");
assert_eq!(pending_a11y[0].text, "a11y [email protected]");
// full_text is done and must not be re-fetched.
- let pending_full = fetch_unredacted(&pool, TargetTable::FullText, 10)
+ let pending_full = fetch_unredacted(&pool, TargetTable::FullText, 10, false)
.await
.unwrap();
assert!(pending_full.is_empty(), "full_text must be marked done");
@@ -1338,7 +1356,9 @@ mod tests {
.await
.unwrap();
- let rows = fetch_unredacted_frames_fulltext(&pool, 10).await.unwrap();
+ let rows = fetch_unredacted_frames_fulltext(&pool, 10, false)
+ .await
+ .unwrap();
assert_eq!(rows.len(), 1);
let r = &rows[0];
assert_eq!(
@@ -1462,7 +1482,7 @@ mod tests {
.await
.unwrap();
- let rows = fetch_unredacted_elements(&pool, 10).await.unwrap();
+ let rows = fetch_unredacted_elements(&pool, 10, false).await.unwrap();
let ids: Vec<i64> = rows.iter().map(|r| r.id).collect();
assert_eq!(ids, vec![2, 1], "only text(1) + value(2), newest-first");
}
@@ -1508,7 +1528,7 @@ mod tests {
.await
.unwrap();
write_redacted_element(&pool, 1, None, None).await.unwrap();
- let pending = fetch_unredacted_elements(&pool, 10).await.unwrap();
+ let pending = fetch_unredacted_elements(&pool, 10, false).await.unwrap();
assert!(pending.is_empty(), "clean row must be marked done");
}
}
diff --git a/crates/screenpipe-redact/tests/hybrid_frames.rs b/crates/screenpipe-redact/tests/hybrid_frames.rs
index 1ed284d41..cdcc8191f 100644
--- a/crates/screenpipe-redact/tests/hybrid_frames.rs
+++ b/crates/screenpipe-redact/tests/hybrid_frames.rs
@@ -11,6 +11,50 @@ use screenpipe_redact::{
};
use std::sync::Arc;
+#[tokio::test]
+async fn background_history_progresses_while_new_captures_arrive() {
+ let root = tempfile::tempdir().unwrap();
+ let db = Arc::new(
+ DatabaseManager::new_hybrid(root.path(), Default::default(), Default::default())
+ .await
+ .unwrap(),
+ );
+ db.execute_raw_sql_write(
+ "INSERT INTO frames(id,timestamp,full_text) VALUES(1,'2026-09-11','[email protected]')",
+ )
+ .await
+ .unwrap();
+ db.seal_frame_payloads().await.unwrap();
+ let worker = Worker::new_with_writer(
+ db.pool.clone(),
+ db.coordinated_writer(),
+ Arc::new(Pipeline::regex_only_with_policy(
+ TextRedactionPolicy::from_labels(&["email".into()]),
+ )),
+ WorkerConfig::default(),
+ )
+ .with_frame_storage(Arc::clone(&db));
+ for id in 2..=5 {
+ db.execute_raw_sql_write(&format!("INSERT INTO frames(id,timestamp,full_text) VALUES({id},'2026-10-26','[email protected]')")).await.unwrap();
+ assert_eq!(worker.process_hybrid_frames(1).await.unwrap(), 1);
+ }
+ let payload = db.frame_payloads(&[1], Projection::All).await.unwrap();
+ assert!(
+ !payload[&1]
+ .full_text
+ .as_deref()
+ .unwrap()
+ .contains("[email protected]"),
+ "new captures starved archived background privacy work"
+ );
+ let captures: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM frames")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(captures, 5, "background work must retain every capture");
+ db.close().await;
+}
+
#[tokio::test]
async fn archived_history_and_malformed_json_use_generation_completion() {
let root = tempfile::tempdir().unwrap();
@@ -108,7 +152,7 @@ async fn detector_fallback_does_not_complete_archive_processing() {
}
#[tokio::test]
-async fn archived_elements_audio_and_ui_use_the_existing_privacy_worker() {
+async fn archived_elements_and_ui_are_redacted_while_audio_stays_unchanged() {
let root = tempfile::tempdir().unwrap();
let db = Arc::new(
DatabaseManager::new_hybrid(root.path(), Default::default(), Default::default())
@@ -117,10 +161,12 @@ async fn archived_elements_audio_and_ui_use_the_existing_privacy_worker() {
);
db.execute_raw_sql_write("INSERT INTO frames(id,timestamp,full_text) VALUES(1,'2026-09-11T12:00:00Z','capture'); INSERT INTO elements(id,frame_id,source,role,text,properties) VALUES(1,1,'accessibility','AXTextField','[email protected]','{\"value\":\"[email protected]\"}'); INSERT INTO audio_chunks(id,file_path) VALUES(1,'test.wav'); INSERT INTO audio_transcriptions(id,audio_chunk_id,offset_index,timestamp,transcription) VALUES(1,1,0,'2026-09-11T12:00:00Z','[email protected]'); INSERT INTO ui_events(id,timestamp,event_type,text_content,element_value,window_title) VALUES(1,'2026-09-11T12:00:00Z','text','[email protected]','[email protected]','[email protected]');").await.unwrap();
while db.seal_payloads().await.unwrap() != 0 {}
- let old_files: Vec<String> = sqlx::query_scalar("SELECT path FROM _bulk_files")
- .fetch_all(&db.pool)
- .await
- .unwrap();
+ let old_files: Vec<String> = sqlx::query_scalar(
+ "SELECT path FROM _bulk_files WHERE table_name IN ('elements','ui_events')",
+ )
+ .fetch_all(&db.pool)
+ .await
+ .unwrap();
let shutdown = Arc::new(tokio::sync::Notify::new());
let worker = Worker::new_with_writer(
db.pool.clone(),
@@ -140,8 +186,8 @@ async fn archived_elements_audio_and_ui_use_the_existing_privacy_worker() {
.spawn_with_shutdown(Arc::clone(&shutdown));
let mut completed = false;
for _ in 0..200 {
- let count:i64=sqlx::query_scalar("SELECT (SELECT count(*) FROM elements WHERE redacted_at IS NOT NULL)+(SELECT count(*) FROM audio_transcriptions WHERE redacted_at IS NOT NULL)+(SELECT count(*) FROM ui_events WHERE redacted_at IS NOT NULL)").fetch_one(&db.pool).await.unwrap();
- if count == 3 {
+ let count:i64=sqlx::query_scalar("SELECT (SELECT count(*) FROM elements WHERE redacted_at IS NOT NULL)+(SELECT count(*) FROM ui_events WHERE redacted_at IS NOT NULL)").fetch_one(&db.pool).await.unwrap();
+ if count == 2 {
completed = true;
break;
}
@@ -150,8 +196,14 @@ async fn archived_elements_audio_and_ui_use_the_existing_privacy_worker() {
shutdown.notify_one();
worker.await.unwrap();
assert!(completed);
- let output=db.query_raw_sql("SELECT e.text,e.properties,a.transcription,u.text_content,u.element_value,u.window_title FROM elements e CROSS JOIN audio_transcriptions a CROSS JOIN ui_events u").await.unwrap();
+ let output=db.query_raw_sql("SELECT e.text,e.properties,u.text_content,u.element_value,u.window_title FROM elements e CROSS JOIN ui_events u").await.unwrap();
assert!(!output.to_string().contains("[email protected]"));
+ let audio = db
+ .query_raw_sql("SELECT transcription,redacted_at FROM audio_transcriptions WHERE id=1")
+ .await
+ .unwrap();
+ assert_eq!(audio[0]["transcription"], "[email protected]");
+ assert!(audio[0]["redacted_at"].is_null());
while db.seal_payloads().await.unwrap() != 0 {}
for _ in 0..16 {
db.reclaim_frame_payloads().await.unwrap();