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: preserve continuous speech during transcript cleanup (#7556)

Louis Beaumont0d082079f354
diff --git a/crates/screenpipe-audio/src/transcription/handle_new_transcript.rs b/crates/screenpipe-audio/src/transcription/handle_new_transcript.rs
index 2ac473639..6ab2889c9 100644
--- a/crates/screenpipe-audio/src/transcription/handle_new_transcript.rs
+++ b/crates/screenpipe-audio/src/transcription/handle_new_transcript.rs
@@ -9,7 +9,7 @@ use crate::{
transcription::process_transcription_result,
};
use screenpipe_db::{ChunkOutcome, DatabaseManager};
-use tracing::{debug, error, info, warn};
+use tracing::{debug, error, warn};
use super::TranscriptionResult;
@@ -80,8 +80,7 @@ pub async fn handle_new_transcript(
// The overlap cleanup logic compares current transcript against the previous one
// from the SAME device — without per-device tracking, device A's transcript
// could incorrectly trim device B's content.
- let mut prev_transcript_by_device: HashMap<String, String> = HashMap::new();
- let mut prev_id_by_device: HashMap<String, i64> = HashMap::new();
+ let mut previous_by_device: HashMap<String, (String, f64, f64)> = HashMap::new();
// Never block a Tokio worker here: the previous DB write may have just
// woken the shared writer into this worker's non-stealable LIFO slot.
while let Ok(mut transcription) = transcription_receiver.recv_async().await {
@@ -121,47 +120,42 @@ pub async fn handle_new_transcript(
// Insert the new transcript after fetching
let device_key = transcription.input.device.to_string();
- let previous_transcript = prev_transcript_by_device
- .get(&device_key)
- .cloned()
- .unwrap_or_default();
- let previous_transcript_id = prev_id_by_device.get(&device_key).copied();
- let mut current_transcript: Option<String> = transcription.transcription.clone();
- let mut processed_previous: Option<String> = None;
+ let current_start = transcription.timestamp as f64 + transcription.start_time;
+ let current_end = transcription.timestamp as f64 + transcription.end_time;
+ let mut current_transcript = transcription.transcription.clone();
let mut was_trimmed = false;
- if let Some((previous, current)) =
- transcription.cleanup_overlap(previous_transcript.clone())
+ if let Some((previous, previous_start, previous_end)) = previous_by_device.get(&device_key)
{
- // If current is empty after cleanup, the entire transcript was a duplicate - skip it
- if current.is_empty() {
- metrics.record_duplicate_blocked();
- finish_without_text(&db, &transcription.path, ChunkOutcome::Duplicate).await;
- info!(
- "device {} skipping duplicate transcript (entire content overlaps with previous)",
- transcription.input.device
- );
- continue;
- }
-
- // Update previous transcript if it was trimmed
- if !previous.is_empty() && previous != previous_transcript {
- processed_previous = Some(previous);
- }
-
- // Use the cleaned current transcript (with overlap removed)
- if current != current_transcript.clone().unwrap_or_default() {
- current_transcript = Some(current);
- was_trimmed = true;
- metrics.record_overlap_trimmed();
+ // Sharing words is not sharing audio. Require valid intervals in
+ // capture order with a real overlap, even for segments in one file.
+ let overlaps = previous_start.is_finite()
+ && previous_end.is_finite()
+ && previous_end > previous_start
+ && current_start.is_finite()
+ && current_end.is_finite()
+ && current_end > current_start
+ && current_start >= *previous_start
+ && current_start < *previous_end;
+ if overlaps {
+ if let Some((_, current)) = transcription.cleanup_overlap(previous.clone()) {
+ if current.is_empty() {
+ metrics.record_duplicate_blocked();
+ finish_without_text(&db, &transcription.path, ChunkOutcome::Duplicate)
+ .await;
+ continue;
+ }
+ was_trimmed = current_transcript.as_ref() != Some(&current);
+ current_transcript = Some(current);
+ if was_trimmed {
+ metrics.record_overlap_trimmed();
+ }
+ }
}
}
transcription.transcription = current_transcript.clone();
- if current_transcript.is_some() {
- prev_transcript_by_device
- .insert(device_key.clone(), current_transcript.clone().unwrap());
- } else {
+ if current_transcript.is_none() {
continue;
}
@@ -187,8 +181,8 @@ pub async fn handle_new_transcript(
transcription,
transcription_engine.clone(),
diarization_mode,
- processed_previous,
- previous_transcript_id,
+ None,
+ None,
use_pii_removal,
output_path.as_path(),
)
@@ -196,10 +190,13 @@ pub async fn handle_new_transcript(
{
Err(e) => error!("Error processing audio result: {}", e),
Ok(result) => {
- if let Some(ref result) = result {
- prev_id_by_device.insert(device_key.clone(), result.audio_chunk_id);
- } else {
- prev_id_by_device.remove(&device_key);
+ if result.is_some() {
+ // Only persisted text can justify removing words from a
+ // later segment. A failed write must not become evidence.
+ previous_by_device.insert(
+ device_key.clone(),
+ (insert_transcription.clone(), current_start, current_end),
+ );
}
metrics.record_db_insert(word_count as u64);
@@ -392,7 +389,13 @@ mod tests {
for (index, (name, text, _)) in cases.iter().enumerate() {
let path = dir.path().join(format!("{name}.mp4"));
std::fs::write(&path, b"durable recording").unwrap();
- let timestamp = captured + chrono::Duration::seconds(index as i64);
+ // A duplicate is the same captured interval, not a later
+ // repetition of the same words.
+ let timestamp = if *name == "duplicate" {
+ captured
+ } else {
+ captured + chrono::Duration::seconds(index as i64)
+ };
let id = db
.insert_audio_chunk(path.to_str().unwrap(), Some(timestamp))
.await
diff --git a/crates/screenpipe-audio/src/transcription/transcription_result.rs b/crates/screenpipe-audio/src/transcription/transcription_result.rs
index 07ae67581..2ff0f88ea 100644
--- a/crates/screenpipe-audio/src/transcription/transcription_result.rs
+++ b/crates/screenpipe-audio/src/transcription/transcription_result.rs
@@ -15,9 +15,7 @@ use crate::speaker::identify_gate::{
segment_duration_secs, speaker_identify_decision, SpeakerIdentifyDecision,
};
-use super::{
- text_utils::longest_common_word_substring, AudioInput, TranscriptionDiarizationSegment,
-};
+use super::{AudioInput, TranscriptionDiarizationSegment};
#[derive(Debug, Clone)]
pub struct TranscriptionResult {
@@ -34,30 +32,23 @@ pub struct TranscriptionResult {
}
impl TranscriptionResult {
- // TODO --optimize
+ /// Remove only a matching suffix/prefix at a verified audio overlap.
+ /// The caller must establish overlapping capture intervals first. Never
+ /// rewrite the previous transcript: it is the retained copy of these words.
pub fn cleanup_overlap(&mut self, previous_transcript: String) -> Option<(String, String)> {
- if let Some(transcription) = &self.transcription {
- let transcription = transcription.to_string();
- if let Some((prev_idx, cur_idx, match_len)) =
- longest_common_word_substring(previous_transcript.as_str(), transcription.as_str())
- {
- // strip old transcript from prev_idx word pos (keep words before the overlap)
- let prev_words: Vec<&str> = previous_transcript.split_whitespace().collect();
- let new_prev = prev_words[..prev_idx].join(" ");
-
- // strip new transcript AFTER the overlap ends (skip the overlapped portion)
- let curr_words: Vec<&str> = transcription.split_whitespace().collect();
- let skip_until = cur_idx + match_len;
- let new_cur = if skip_until < curr_words.len() {
- curr_words[skip_until..].join(" ")
- } else {
- String::new() // Entire current transcript was overlap
- };
-
- return Some((new_prev, new_cur));
+ let current = self.transcription.as_ref()?;
+ let previous_words: Vec<&str> = previous_transcript.split_whitespace().collect();
+ let current_words: Vec<&str> = current.split_whitespace().collect();
+ // One or two common words are too weak to establish a speech boundary.
+ for count in (3..=previous_words.len().min(current_words.len())).rev() {
+ let matches = previous_words[previous_words.len() - count..]
+ .iter()
+ .zip(&current_words[..count])
+ .all(|(left, right)| left.eq_ignore_ascii_case(right));
+ if matches {
+ return Some((previous_transcript, current_words[count..].join(" ")));
}
}
-
None
}
}
diff --git a/crates/screenpipe-audio/tests/continuous_recall_stress_test.rs b/crates/screenpipe-audio/tests/continuous_recall_stress_test.rs
new file mode 100644
index 000000000..f8996bf34
--- /dev/null
+++ b/crates/screenpipe-audio/tests/continuous_recall_stress_test.rs
@@ -0,0 +1,531 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+//! Seeded, synthetic retention evaluations against the real consumer and SQLite
+//! search. No microphone, credentials or private recordings are used. Large
+//! sweeps are manual so ordinary CI does not pay for thousands of inserts.
+use screenpipe_audio::{
+ core::{
+ device::{AudioDevice, DeviceType},
+ engine::AudioTranscriptionEngine,
+ },
+ metrics::AudioPipelineMetrics,
+ transcription::handle_new_transcript,
+ AudioInput, TranscriptionResult,
+};
+use screenpipe_db::{DatabaseManager, Order};
+use std::{collections::BTreeMap, sync::Arc};
+
+#[derive(Clone)]
+struct Segment {
+ text: String,
+ file: String,
+ device: String,
+ output: bool,
+ at: u64,
+ start: f64,
+ end: f64,
+ error: Option<String>,
+}
+
+fn segment(text: &str, file: &str, at: u64, start: f64, end: f64) -> Segment {
+ Segment {
+ text: text.into(),
+ file: file.into(),
+ device: "duplex".into(),
+ output: false,
+ at,
+ start,
+ end,
+ error: None,
+ }
+}
+
+fn result(s: &Segment, root: &std::path::Path) -> TranscriptionResult {
+ TranscriptionResult {
+ path: root.join(&s.file).to_string_lossy().into_owned(),
+ input: AudioInput {
+ data: Arc::new(vec![]),
+ sample_rate: 16000,
+ channels: 1,
+ device: Arc::new(AudioDevice::new(
+ s.device.clone(),
+ if s.output {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ )),
+ capture_timestamp: s.at,
+ },
+ speaker_embedding: vec![],
+ transcription: Some(s.text.clone()),
+ timestamp: s.at,
+ error: s.error.clone(),
+ start_time: s.start,
+ end_time: s.end,
+ diarization_provider: None,
+ diarization_segments: vec![],
+ }
+}
+
+async fn replay(segments: &[Segment], engine: AudioTranscriptionEngine) -> Vec<String> {
+ let dir = tempfile::tempdir().unwrap();
+ let db = Arc::new(
+ DatabaseManager::new(
+ dir.path().join("eval.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap(),
+ );
+ // Captured chunks already exist independently of recognition success.
+ for s in segments {
+ db.get_or_insert_audio_chunk(
+ &dir.path().join(&s.file).to_string_lossy(),
+ chrono::DateTime::from_timestamp(s.at as i64, 0),
+ )
+ .await
+ .unwrap();
+ }
+ let (tx, rx) = flume::unbounded();
+ for s in segments {
+ tx.send(result(s, dir.path())).unwrap();
+ }
+ drop(tx);
+ handle_new_transcript(
+ db.clone(),
+ Arc::new(rx),
+ Arc::new(engine),
+ "batch",
+ false,
+ Arc::new(AudioPipelineMetrics::new()),
+ None,
+ dir.path().into(),
+ )
+ .await;
+ let mut text = vec![];
+ let mut offset = 0;
+ loop {
+ let rows = db
+ .search_audio_ordered(
+ "",
+ 100,
+ offset,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ &[],
+ Order::Ascending,
+ )
+ .await
+ .unwrap();
+ let count = rows.len();
+ text.extend(rows.into_iter().map(|r| r.transcription));
+ offset += count as u32;
+ if count < 100 {
+ break;
+ }
+ }
+ text
+}
+
+fn counts(texts: &[String]) -> BTreeMap<String, usize> {
+ let mut counts = BTreeMap::new();
+ for text in texts {
+ *counts.entry(text.trim().to_owned()).or_default() += 1;
+ }
+ counts
+}
+
+#[tokio::test]
+async fn separate_cross_device_utterances_with_matching_words_survive() {
+ let text = "Please send the complete proposal tomorrow.";
+ let first = segment(text, "first.wav", 1_700_000_000, 0.0, 5.0);
+ let mut second = segment(text, "second.wav", 1_700_000_000, 15.0, 20.0);
+ second.output = true;
+ assert_eq!(
+ replay(
+ &[first, second],
+ AudioTranscriptionEngine::WhisperLargeV3TurboQuantized
+ )
+ .await,
+ [text, text],
+ "different speech intervals are not an echo even when chunk timestamps match"
+ );
+}
+
+// Each category has independently specified expected transcript rows, rather
+// than reimplementing the dedup algorithm as its own oracle.
+fn corpus(repetitions: usize) -> (Vec<Segment>, Vec<String>) {
+ let mut inputs = vec![];
+ let mut expected = vec![];
+ let mut seed = 0x5eed_u64;
+ for i in 0..repetitions * 12 {
+ seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
+ let at = 1_700_000_000 + i as u64 * 120;
+ let value = 100 + seed % 900;
+ let prior = format!("For case{i} please order {value} chairs tomorrow.");
+ let changed = format!("For case{i} please order {} desks tomorrow.", value + 1);
+ let tail = format!("Include appendix case{i}.");
+ let prefix = format!("{value} chairs tomorrow.");
+ let mut a = segment(&prior, &format!("{i}-a.wav"), at, 0.0, 10.0);
+ let mut b = segment(&changed, &format!("{i}-b.wav"), at + 30, 0.0, 10.0);
+ match i % 12 {
+ 0 => {
+ expected.extend([prior, changed]);
+ }
+ 1 => {
+ b.at = at + 5;
+ expected.extend([prior, changed]);
+ }
+ 2 => {
+ b.at = at + 5;
+ b.text = format!("{prefix} {tail}");
+ expected.extend([prior, tail]);
+ }
+ 3 => {
+ b.at = at + 10;
+ b.text = format!("{prefix} {tail}");
+ expected.extend([prior, b.text.clone()]);
+ }
+ 4 => {
+ b.output = true;
+ b.at = at;
+ b.text = prior.clone();
+ expected.push(prior);
+ }
+ 5 => {
+ b.output = true;
+ b.at = at;
+ b.start = 15.0;
+ b.end = 20.0;
+ b.text = prior.clone();
+ expected.extend([prior.clone(), prior]);
+ }
+ 6 => {
+ b.file = a.file.clone();
+ b.at = at;
+ b.start = 10.0;
+ b.end = 20.0;
+ expected.extend([prior, changed]);
+ }
+ 7 => {
+ b.text = prior.clone();
+ expected.extend([prior.clone(), prior]);
+ }
+ 8 => {
+ b.at = at - 30;
+ expected.extend([prior, changed]);
+ }
+ 9 => {
+ a.error = Some("injected recognition failure".into());
+ b.at = at + 5;
+ b.text = format!("{prefix} {tail}");
+ expected.push(b.text.clone());
+ }
+ 10 => {
+ a.text = " ".into();
+ expected.push(changed);
+ }
+ 11 => {
+ b.device = "second microphone".into();
+ b.at = at + 5;
+ expected.extend([prior, changed]);
+ }
+ _ => unreachable!(),
+ }
+ inputs.extend([a, b]);
+ }
+ (inputs, expected)
+}
+
+#[tokio::test]
+#[ignore = "manual multi-day replay, thousands of actual SQLite writes"]
+async fn seeded_multi_day_retention_eval() {
+ let repetitions = std::env::var("SCREENPIPE_RECALL_REPETITIONS")
+ .ok()
+ .map(|v| v.parse().unwrap())
+ .unwrap_or(128);
+ let (inputs, expected) = corpus(repetitions);
+ let wanted = counts(&expected);
+ let mut reports = vec![];
+ for engine in [
+ AudioTranscriptionEngine::WhisperLargeV3TurboQuantized,
+ AudioTranscriptionEngine::Parakeet,
+ ] {
+ let start = std::time::Instant::now();
+ let actual = counts(&replay(&inputs, engine.clone()).await);
+ let missing: usize = wanted
+ .iter()
+ .map(|(text, count)| count.saturating_sub(*actual.get(text).unwrap_or(&0)))
+ .sum();
+ let unexpected: usize = actual
+ .iter()
+ .map(|(text, count)| count.saturating_sub(*wanted.get(text).unwrap_or(&0)))
+ .sum();
+ reports.push(serde_json::json!({"engine_label":engine.to_string(), "seed":"0x5eed", "cases":repetitions*12, "submitted_segments":inputs.len(), "expected_rows":expected.len(), "missing_occurrences":missing, "unexpected_rows":unexpected, "elapsed_ms":start.elapsed().as_millis()}));
+ }
+ eprintln!("LARGE_RECALL_EVAL {}", serde_json::json!(reports));
+ if let Ok(path) = std::env::var("SCREENPIPE_RECALL_STRESS_RECEIPT") {
+ std::fs::write(path, serde_json::to_vec_pretty(&reports).unwrap()).unwrap();
+ }
+ assert!(
+ reports
+ .iter()
+ .all(|r| r["missing_occurrences"] == 0 && r["unexpected_rows"] == 0),
+ "large replay lost speech or retained an unexpected echo: {reports:?}"
+ );
+}
+
+#[test]
+fn seeded_boundary_cleanup_properties() {
+ let root = std::path::Path::new("/synthetic");
+ for i in 0..10_000 {
+ let suffix = format!("confirm order {i} tomorrow");
+ let prior = format!("Please {suffix}");
+ let novel = format!("Keep detail {}.", i + 1);
+ let mut current = result(
+ &segment(&format!("{suffix} {novel}"), "test", 0, 0.0, 10.0),
+ root,
+ );
+ assert_eq!(
+ current.cleanup_overlap(prior.clone()),
+ Some((prior.clone(), novel))
+ );
+ current.transcription = Some(format!("Do not confirm order {i} tomorrow"));
+ assert!(
+ current.cleanup_overlap(prior).is_none(),
+ "a negation must survive"
+ );
+ }
+ eprintln!("PROPERTY_RECALL_EVAL {{\"seed\":\"enumerated\",\"cases\":20000,\"passed\":20000}}");
+}
+
+#[tokio::test]
+#[ignore = "manual cached Silero/Whisper acoustic eval; requires two synthetic WAVs"]
+async fn acoustic_vad_and_whisper_retention_eval() {
+ use screenpipe_audio::{
+ speaker::{embedding_manager::EmbeddingManager, prepare_segments},
+ transcription::whisper::{
+ batch::process_with_whisper,
+ model::{create_whisper_context_parameters_with_gpu, get_cached_whisper_model_path},
+ },
+ vad::{silero::SileroVad, VadEngine},
+ };
+ use std::sync::Mutex as StdMutex;
+ use tokio::sync::Mutex;
+ fn read_wav(variable: &str) -> Vec<f32> {
+ let mut wav = hound::WavReader::open(std::env::var(variable).unwrap()).unwrap();
+ assert_eq!((wav.spec().sample_rate, wav.spec().channels), (16000, 1));
+ wav.samples::<i16>()
+ .map(|x| x.unwrap() as f32 / 32768.0)
+ .collect()
+ }
+ let sentence = read_wav("SCREENPIPE_RECALL_SENTENCE_WAV");
+ let short = read_wav("SCREENPIPE_RECALL_SHORT_WAV");
+ let vad_cache = dirs::cache_dir()
+ .unwrap()
+ .join("screenpipe/vad/silero_vad_v5.onnx");
+ assert!(
+ vad_cache.exists(),
+ "cached Silero required; do not download"
+ );
+ let engine = Arc::new(AudioTranscriptionEngine::WhisperLargeV3TurboQuantized);
+ let model =
+ get_cached_whisper_model_path(&engine).expect("cached Whisper required; do not download");
+ let context = whisper_rs::WhisperContext::new_with_params(
+ &model,
+ create_whisper_context_parameters_with_gpu(engine, false).unwrap(),
+ )
+ .unwrap();
+ let mut state = context.create_state().unwrap();
+ let mut reports = Vec::new();
+ for (source_name, source) in [
+ ("sentence", &sentence),
+ ("single_word", &short),
+ ("silence", &Vec::new()),
+ ] {
+ for position in [0, 12, 24] {
+ for gain in [1.0_f32, 0.05] {
+ for noise in [0.0_f32, 0.01, 0.05] {
+ for output in [false, true] {
+ let mut pcm = vec![0.0_f32; 30 * 16000];
+ let mut seed = 0x5eed_u64;
+ for sample in &mut pcm {
+ seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
+ *sample = ((seed >> 32) as f32 / u32::MAX as f32 * 2.0 - 1.0) * noise;
+ }
+ for (i, sample) in source.iter().enumerate() {
+ if let Some(dest) = pcm.get_mut(position * 16000 + i) {
+ *dest = (*dest + sample * gain).clamp(-1.0, 1.0);
+ }
+ }
+ let vad: Arc<Mutex<Box<dyn VadEngine + Send>>> =
+ Arc::new(Mutex::new(Box::new(SileroVad::new().await.unwrap())));
+ let (mut segments, admitted, ratio) = prepare_segments(
+ &pcm,
+ vad,
+ None,
+ Arc::new(StdMutex::new(EmbeddingManager::new(1))),
+ None,
+ "synthetic",
+ output,
+ false,
+ )
+ .await
+ .unwrap();
+ // Acoustic recognition is deliberately limited to six
+ // sentence conditions; the full 108-case grid scores VAD.
+ let run_stt =
+ source_name == "sentence" && gain == 1.0 && !output && noise != 0.01;
+ let mut recognized = Vec::new();
+ if run_stt {
+ while let Some(s) = segments.recv().await {
+ recognized.push(
+ process_with_whisper(
+ &s.samples,
+ vec![screenpipe_core::Language::English],
+ &mut state,
+ &[],
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ }
+ let mut stored = Vec::new();
+ if !recognized.is_empty() {
+ let items: Vec<_> = recognized
+ .iter()
+ .enumerate()
+ .map(|(i, t)| {
+ segment(
+ t,
+ &format!("acoustic-{i}.wav"),
+ 1_700_000_000 + i as u64 * 30,
+ 0.0,
+ 30.0,
+ )
+ })
+ .collect();
+ stored = replay(
+ &items,
+ AudioTranscriptionEngine::WhisperLargeV3TurboQuantized,
+ )
+ .await;
+ assert_eq!(
+ counts(&recognized),
+ counts(&stored),
+ "recognized acoustic content must survive storage"
+ );
+ }
+ let report = serde_json::json!({"source":source_name,"position_seconds":position,"gain":gain,"noise_peak":noise,"output_device":output,"vad_admitted":admitted,"speech_ratio":ratio,"stt_ran":run_stt && admitted,"recognized":recognized,"stored":stored});
+ eprintln!("ACOUSTIC_RECALL_EVAL {report}");
+ reports.push(report);
+ }
+ }
+ }
+ }
+ }
+ if let Ok(path) = std::env::var("SCREENPIPE_RECALL_ACOUSTIC_RECEIPT") {
+ std::fs::write(path, serde_json::to_vec_pretty(&reports).unwrap()).unwrap();
+ }
+ assert!(
+ reports
+ .iter()
+ .filter(|r| r["source"] == "sentence" && r["noise_peak"] == 0.0)
+ .all(|r| r["vad_admitted"] == true),
+ "clean full sentences must reach recognition"
+ );
+ assert!(
+ reports
+ .iter()
+ .filter(|r| r["source"] == "silence" && r["noise_peak"] == 0.0)
+ .all(|r| r["vad_admitted"] == false),
+ "true silence must not be recognized as speech"
+ );
+}
+
+#[tokio::test]
+#[ignore = "manual short-speech diagnosis with cached Silero and Whisper"]
+async fn short_speech_padding_diagnosis() {
+ use screenpipe_audio::{
+ speaker::{embedding_manager::EmbeddingManager, prepare_segments},
+ transcription::whisper::{
+ batch::process_with_whisper,
+ model::{create_whisper_context_parameters_with_gpu, get_cached_whisper_model_path},
+ },
+ vad::{silero::SileroVad, VadEngine},
+ };
+ use std::sync::Mutex as StdMutex;
+ use tokio::sync::Mutex;
+ let mut wav =
+ hound::WavReader::open(std::env::var("SCREENPIPE_RECALL_SHORT_WAV").unwrap()).unwrap();
+ assert_eq!((wav.spec().sample_rate, wav.spec().channels), (16000, 1));
+ let samples: Vec<f32> = wav
+ .samples::<i16>()
+ .map(|s| s.unwrap() as f32 / 32768.0)
+ .collect();
+ assert!(dirs::cache_dir()
+ .unwrap()
+ .join("screenpipe/vad/silero_vad_v5.onnx")
+ .exists());
+ let engine = Arc::new(AudioTranscriptionEngine::WhisperLargeV3TurboQuantized);
+ let model = get_cached_whisper_model_path(&engine).expect("cached model required");
+ let context = whisper_rs::WhisperContext::new_with_params(
+ &model,
+ create_whisper_context_parameters_with_gpu(engine, false).unwrap(),
+ )
+ .unwrap();
+ let mut state = context.create_state().unwrap();
+ let mut report = vec![];
+ for seconds in [5, 10, 15, 30, 60] {
+ let mut pcm = vec![0.0; seconds * 16000];
+ pcm[..samples.len()].copy_from_slice(&samples);
+ let vad: Arc<Mutex<Box<dyn VadEngine + Send>>> =
+ Arc::new(Mutex::new(Box::new(SileroVad::new().await.unwrap())));
+ let (_, admitted, ratio) = prepare_segments(
+ &pcm,
+ vad,
+ None,
+ Arc::new(StdMutex::new(EmbeddingManager::new(1))),
+ None,
+ "synthetic",
+ false,
+ false,
+ )
+ .await
+ .unwrap();
+ // Bypass the VAD gate in two explicit controls to separate an admission
+ // miss from the recognition model being unable to recognize the word.
+ let recognized = if seconds == 5 || seconds == 30 {
+ Some(
+ process_with_whisper(
+ &pcm,
+ vec![screenpipe_core::Language::English],
+ &mut state,
+ &[],
+ )
+ .await
+ .unwrap(),
+ )
+ } else {
+ None
+ };
+ report.push(serde_json::json!({"chunk_seconds":seconds,"speech_seconds":samples.len()as f64/16000.0,"speech_ratio":ratio,"vad_admitted":admitted,"whisper_bypassing_vad":recognized}));
+ }
+ eprintln!("SHORT_SPEECH_DIAGNOSIS {}", serde_json::json!(report));
+ std::fs::write(
+ std::env::var("SCREENPIPE_RECALL_PADDING_RECEIPT").unwrap(),
+ serde_json::to_vec_pretty(&report).unwrap(),
+ )
+ .unwrap();
+ // This is a diagnostic receipt, not a test claiming all short speech is
+ // captured. Preserve the unresolved false negatives in the report.
+}
diff --git a/crates/screenpipe-audio/tests/continuous_recall_test.rs b/crates/screenpipe-audio/tests/continuous_recall_test.rs
new file mode 100644
index 000000000..921ef24a7
--- /dev/null
+++ b/crates/screenpipe-audio/tests/continuous_recall_test.rs
@@ -0,0 +1,372 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+use screenpipe_audio::{
+ core::{
+ device::{AudioDevice, DeviceType},
+ engine::AudioTranscriptionEngine,
+ },
+ metrics::AudioPipelineMetrics,
+ transcription::handle_new_transcript,
+ AudioInput, TranscriptionResult,
+};
+use screenpipe_db::{DatabaseManager, Order};
+use std::sync::Arc;
+
+async fn replay(texts: &[&str]) -> Vec<String> {
+ let windows: Vec<_> = (0..texts.len())
+ .map(|i| (i as u64 * 30, 0.0, 30.0))
+ .collect();
+ replay_windows(texts, &windows).await
+}
+
+async fn replay_windows(texts: &[&str], windows: &[(u64, f64, f64)]) -> Vec<String> {
+ let dir = tempfile::tempdir().unwrap();
+ let db = Arc::new(
+ DatabaseManager::new(
+ dir.path().join("recall.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap(),
+ );
+ let (tx, rx) = flume::unbounded();
+ // Old capture timestamps deliberately remove the recent-DB-dedup variable.
+ let base = chrono::Utc::now().timestamp() as u64 - 3600;
+ for (i, text) in texts.iter().enumerate() {
+ let path = dir
+ .path()
+ .join(format!("chunk-{}.mp4", windows[i].0))
+ .to_string_lossy()
+ .into_owned();
+ let timestamp = base + windows[i].0;
+ tx.send(TranscriptionResult {
+ path,
+ input: AudioInput {
+ data: Arc::new(vec![]),
+ sample_rate: 16000,
+ channels: 1,
+ device: Arc::new(AudioDevice::new("Synthetic mic".into(), DeviceType::Input)),
+ capture_timestamp: timestamp,
+ },
+ speaker_embedding: vec![],
+ transcription: Some(text.to_string()),
+ timestamp,
+ error: None,
+ start_time: windows[i].1,
+ end_time: windows[i].2,
+ diarization_provider: None,
+ diarization_segments: vec![],
+ })
+ .unwrap();
+ }
+ drop(tx);
+ handle_new_transcript(
+ db.clone(),
+ Arc::new(rx),
+ Arc::new(AudioTranscriptionEngine::WhisperLargeV3TurboQuantized),
+ "batch",
+ false,
+ Arc::new(AudioPipelineMetrics::new()),
+ None,
+ dir.path().to_path_buf(),
+ )
+ .await;
+ let mut rows = Vec::new();
+ for offset in [0, 20, 40] {
+ rows.extend(
+ db.search_audio_ordered(
+ "",
+ 20,
+ offset,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ &[],
+ Order::Ascending,
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ rows.into_iter().map(|r| r.transcription).collect()
+}
+
+#[tokio::test]
+async fn different_non_overlapping_sentences_survive_real_transcript_handler() {
+ let original = [
+ "Order twelve chairs for the workshop.",
+ "Order twenty desks for the office.",
+ ];
+ let actual = replay(&original).await;
+ eprintln!("original={original:?}; stored={actual:?}");
+ assert_eq!(
+ actual, original,
+ "sharing an ordinary word is not overlapping audio"
+ );
+}
+
+#[tokio::test]
+async fn twenty_five_facts_survive_real_transcript_handler() {
+ let original: Vec<&str> = include_str!("fixtures/continuous-recall-checklist.txt")
+ .lines()
+ .collect();
+ let actual = replay(&original).await;
+ let preserved = original
+ .iter()
+ .filter(|s| actual.iter().any(|a| a == **s))
+ .count();
+ eprintln!("intact facts: {preserved}/25; output={actual:?}");
+ assert_eq!(
+ preserved, 25,
+ "all original facts should survive independent non-overlapping speech chunks"
+ );
+}
+
+#[tokio::test]
+#[ignore = "manual local Whisper check; requires cached model and synthetic WAV"]
+async fn synthetic_audio_through_whisper_and_transcript_handler() {
+ use screenpipe_audio::transcription::whisper::{
+ batch::process_with_whisper,
+ model::{create_whisper_context_parameters_with_gpu, get_cached_whisper_model_path},
+ };
+ let wav_path = std::env::var("SCREENPIPE_RECALL_WAV").unwrap();
+ let receipt_path = std::env::var("SCREENPIPE_RECALL_RECEIPT").unwrap();
+ let engine = Arc::new(AudioTranscriptionEngine::WhisperLargeV3TurboQuantized);
+ let model = get_cached_whisper_model_path(&engine).expect("cached model required; no download");
+ let context = whisper_rs::WhisperContext::new_with_params(
+ &model,
+ create_whisper_context_parameters_with_gpu(engine, false).unwrap(),
+ )
+ .unwrap();
+ let mut state = context.create_state().unwrap();
+ let mut wav = hound::WavReader::open(wav_path).unwrap();
+ assert_eq!(wav.spec().sample_rate, 16000);
+ assert_eq!(wav.spec().channels, 1);
+ let pcm: Vec<f32> = wav
+ .samples::<i16>()
+ .map(|x| x.unwrap() as f32 / 32768.0)
+ .collect();
+ let mut transcripts = Vec::new();
+ for part in pcm.chunks(30 * 16000) {
+ transcripts.push(
+ process_with_whisper(
+ part,
+ vec![screenpipe_core::Language::English],
+ &mut state,
+ &[],
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ let refs: Vec<&str> = transcripts.iter().map(String::as_str).collect();
+ let stored = replay(&refs).await;
+ std::fs::write(receipt_path,serde_json::to_vec_pretty(&serde_json::json!({"engine":"whisper-large-v3-turbo-quantized","backend":"CPU","chunk_seconds":30,"audio_seconds":pcm.len() as f64/16000.0,"recognized_chunks":transcripts,"stored_chunks":stored})).unwrap()).unwrap();
+ assert!(!transcripts.is_empty());
+ assert_eq!(
+ stored.iter().map(|s| s.trim()).collect::<Vec<_>>(),
+ transcripts.iter().map(|s| s.trim()).collect::<Vec<_>>(),
+ "non-overlapping recognized chunks must retain their text"
+ );
+}
+
+#[tokio::test]
+async fn verified_boundary_overlap_keeps_one_complete_copy() {
+ let original = [
+ "We need twelve chairs for the workshop.",
+ "chairs for the workshop. Invite Rowan tomorrow.",
+ ];
+ let actual = replay_windows(&original, &[(0, 0.0, 20.0), (15, 0.0, 20.0)]).await;
+ assert_eq!(actual, [original[0], "Invite Rowan tomorrow."]);
+}
+
+#[tokio::test]
+async fn shared_middle_words_in_overlapping_audio_do_not_delete_a_sentence() {
+ let original = [
+ "Order twelve chairs for the workshop.",
+ "Order twenty desks for the office.",
+ ];
+ let actual = replay_windows(&original, &[(0, 0.0, 20.0), (15, 0.0, 20.0)]).await;
+ assert_eq!(actual, original);
+}
+
+#[tokio::test]
+async fn repeated_sentence_outside_overlap_is_preserved() {
+ let original = [
+ "Please send the complete proposal tomorrow.",
+ "Please send the complete proposal tomorrow.",
+ ];
+ assert_eq!(replay(&original).await, original);
+}
+
+#[tokio::test]
+async fn complete_duplicate_inside_overlap_is_suppressed() {
+ let original = [
+ "Please send the complete proposal tomorrow.",
+ "Please send the complete proposal tomorrow.",
+ ];
+ assert_eq!(
+ replay_windows(&original, &[(0, 0.0, 20.0), (0, 0.0, 20.0)]).await,
+ [original[0]]
+ );
+}
+
+#[tokio::test]
+async fn later_segments_of_one_chunk_do_not_overlap_earlier_segments() {
+ let original = [
+ "Order twelve chairs for the workshop.",
+ "Order twenty desks for the office.",
+ ];
+ assert_eq!(
+ replay_windows(&original, &[(0, 0.0, 5.0), (0, 5.0, 10.0)]).await,
+ original
+ );
+}
+
+// A labeled evaluation against the production handler and paginated DB search.
+// Both retain and suppress controls are needed: keeping everything would pass
+// retention-only tests but regress genuine overlap removal.
+#[tokio::test]
+async fn boundary_retention_and_echo_eval_matrix() {
+ let prior = "Send the complete proposal tomorrow.";
+ let next = "the complete proposal tomorrow. Include the appendix.";
+ let novel = "Include the appendix.";
+ let cases = [
+ ("true_overlap", (0, 0.0, 20.0), (15, 0.0, 20.0), novel),
+ ("adjacent_chunks", (0, 0.0, 20.0), (20, 0.0, 20.0), next),
+ ("separated_chunks", (0, 0.0, 20.0), (60, 0.0, 20.0), next),
+ ("out_of_order", (30, 0.0, 20.0), (0, 0.0, 20.0), next),
+ ("same_file_overlap", (0, 0.0, 20.0), (0, 15.0, 30.0), novel),
+ ("same_file_adjacent", (0, 0.0, 15.0), (0, 15.0, 30.0), next),
+ ("same_file_gap", (0, 0.0, 10.0), (0, 15.0, 30.0), next),
+ ("unknown_current_end", (0, 0.0, 20.0), (15, 0.0, 0.0), next),
+ ("reversed_current", (0, 0.0, 20.0), (15, 5.0, 1.0), next),
+ (
+ "nonfinite_current",
+ (0, 0.0, 20.0),
+ (15, 0.0, f64::INFINITY),
+ next,
+ ),
+ (
+ "nonfinite_previous",
+ (0, 0.0, f64::INFINITY),
+ (60, 0.0, 20.0),
+ next,
+ ),
+ (
+ "negative_infinite_previous_start",
+ (0, f64::NEG_INFINITY, 20.0),
+ (15, 0.0, 20.0),
+ next,
+ ),
+ ];
+ let mut failures = Vec::new();
+ for (name, first_window, second_window, expected_second) in cases {
+ let actual = replay_windows(&[prior, next], &[first_window, second_window]).await;
+ let mut expected = vec![prior, expected_second];
+ if first_window.0 > second_window.0 {
+ expected.reverse();
+ }
+ let passed = actual == expected;
+ eprintln!(
+ "RECALL_EVAL {}",
+ serde_json::json!({
+ "case": name, "passed": passed, "expected": expected, "actual": actual
+ })
+ );
+ if !passed {
+ failures.push(name);
+ }
+ }
+ assert!(failures.is_empty(), "boundary eval failures: {failures:?}");
+}
+
+#[tokio::test]
+async fn vocabulary_retention_and_echo_eval_matrix() {
+ let cases: &[(&str, &str, &str, &str)] = &[
+ (
+ "one_common_word",
+ "Order chairs tomorrow.",
+ "tomorrow. Buy desks.",
+ "tomorrow. Buy desks.",
+ ),
+ (
+ "two_common_words",
+ "Please order chairs tomorrow.",
+ "chairs tomorrow. Buy desks.",
+ "chairs tomorrow. Buy desks.",
+ ),
+ (
+ "three_boundary_words",
+ "Please order chairs tomorrow.",
+ "order chairs tomorrow. Buy desks.",
+ "Buy desks.",
+ ),
+ (
+ "case_only_echo",
+ "Please order chairs tomorrow.",
+ "ORDER CHAIRS TOMORROW. Buy desks.",
+ "Buy desks.",
+ ),
+ (
+ "changed_number",
+ "Order exactly twelve chairs tomorrow.",
+ "Order exactly twenty chairs tomorrow.",
+ "Order exactly twenty chairs tomorrow.",
+ ),
+ (
+ "negation",
+ "Please approve the payment.",
+ "Please do not approve the payment.",
+ "Please do not approve the payment.",
+ ),
+ (
+ "word_order",
+ "Please ship from London to Paris.",
+ "Please ship from Paris to London.",
+ "Please ship from Paris to London.",
+ ),
+ (
+ "interior_phrase",
+ "We need twelve chairs for the workshop.",
+ "We need twenty desks for the office.",
+ "We need twenty desks for the office.",
+ ),
+ (
+ "punctuation_mismatch_kept",
+ "Please order chairs tomorrow.",
+ "order chairs tomorrow! Buy desks.",
+ "order chairs tomorrow! Buy desks.",
+ ),
+ (
+ "non_latin_exact_echo",
+ "明日 会議 の 準備 を お願いします。",
+ "準備 を お願いします。 資料 も 必要です。",
+ "資料 も 必要です。",
+ ),
+ ];
+ let mut failures = Vec::new();
+ for &(name, prior, next, expected_second) in cases {
+ let actual = replay_windows(&[prior, next], &[(0, 0.0, 20.0), (15, 0.0, 20.0)]).await;
+ let passed = actual == [prior, expected_second];
+ eprintln!(
+ "RECALL_EVAL {}",
+ serde_json::json!({
+ "case": name, "passed": passed, "expected": [prior, expected_second], "actual": actual
+ })
+ );
+ if !passed {
+ failures.push(name);
+ }
+ }
+ assert!(
+ failures.is_empty(),
+ "vocabulary eval failures: {failures:?}"
+ );
+}
diff --git a/crates/screenpipe-audio/tests/fixtures/continuous-recall-checklist.txt b/crates/screenpipe-audio/tests/fixtures/continuous-recall-checklist.txt
new file mode 100644
index 000000000..ecbed3662
--- /dev/null
+++ b/crates/screenpipe-audio/tests/fixtures/continuous-recall-checklist.txt
@@ -0,0 +1,25 @@
+Order amber folders for Monday.
+Buy birch pencils for Tuesday.
+Ship cedar boxes before Wednesday.
+Send dahlia flowers by Thursday.
+Plant elm trees on Friday.
+Book falcon transport for Saturday.
+Reserve garnet tickets for Sunday.
+Print hazel labels by noon.
+Collect indigo fabric before lunch.
+Deliver juniper samples after lunch.
+Approve kiwi packaging this afternoon.
+Cancel lemon delivery tomorrow.
+Review maple invoices next week.
+Move nectar supplies upstairs.
+Keep olive receipts downstairs.
+Check peach inventory today.
+Replace quartz batteries tonight.
+Return ruby equipment this morning.
+Clean silver trays before opening.
+Pack tulip bulbs before closing.
+Store umber paint indoors.
+Take violet photographs outdoors.
+Count walnut baskets carefully.
+Inspect yellow cables separately.
+Repair zebra signs immediately.
diff --git a/crates/screenpipe-audio/tests/fixtures/continuous-recall-evals.md b/crates/screenpipe-audio/tests/fixtures/continuous-recall-evals.md
new file mode 100644
index 000000000..acf899578
--- /dev/null
+++ b/crates/screenpipe-audio/tests/fixtures/continuous-recall-evals.md
@@ -0,0 +1,82 @@
+# Continuous transcript recall evaluations
+
+Use disposable databases and synthetic speech to separate post-recognition
+retention from acoustic recognition. These tests do not operate a microphone,
+change the installed recorder, call paid providers, or establish resolution of a
+particular customer's incident.
+
+## Fast regressions
+
+```sh
+cargo test -p screenpipe-audio --test continuous_recall_test --test continuous_recall_stress_test -- --nocapture
+cargo test -p screenpipe-db --test continuous_audio_recall_test --test audio_duplicate_test --test audio_segment_search_test --test chunk_outcome_test --test meeting_transcript_dedup_test --test speaker_identity_eval -- --nocapture
+cargo test -p screenpipe-audio --lib transcription:: -- --nocapture --test-threads=1
+```
+
+The stress target includes 20,000 generated cleanup assertions and a minimal
+cross-device timing regression. DB tests cover both insertion paths and invalid
+or partial intervals. The audio unit subset is sequential because an unchanged
+retry-log assertion has failed under parallel execution.
+
+## Large replay and race probes
+
+```sh
+SCREENPIPE_RECALL_REPETITIONS=1024 SCREENPIPE_RECALL_STRESS_RECEIPT=/tmp/recall-stress.json cargo test -p screenpipe-audio --test continuous_recall_stress_test seeded_multi_day -- --ignored --nocapture
+cargo test -p screenpipe-db --test continuous_audio_recall_test cross_device_interval_eval_sweep -- --ignored --nocapture
+cargo test -p screenpipe-db --test continuous_audio_recall_test concurrent_echo_retention_probe -- --ignored --nocapture
+cargo test -p screenpipe-db --test continuous_audio_recall_test measure_continuous -- --ignored --nocapture
+```
+
+The large replay generates 12,288 cases from 12 scenario families, seed `0x5eed`.
+Two engine labels give 24,576 case runs and 49,152 submitted segments. Both labels
+use the same handler; this does **not** run two recognition models. Cases include
+overlap, adjacent intervals, changed details, repeated speech, multiple devices,
+shared files, out-of-order arrival, silence and recognition failures. The oracle
+compares full transcript occurrence counts after paginated search. The virtual
+timeline spans multiple days; hardware was not recorded for that duration.
+Default repetitions are 128 for a smaller manual run. Generated variations are
+not independent samples of user accuracy.
+
+The 480-case DB sweep varies capture time, segment intervals, device direction
+and insertion method. It checks missing occurrences and surviving echoes. The
+race probe synchronizes eight writers in each of 64 groups. It asserts retention
+and separately reports extra copies; passing does not mean exactly-once dedup.
+This stresses concurrent DB callers. The normal transcript consumer is serial,
+so the probe does not establish this concurrency level in a customer recording.
+
+## Acoustic eval
+
+Requires cached Silero and quantized Whisper Large v3 Turbo models. On macOS:
+
+```sh
+RECALL_DIR=$(mktemp -d)
+say -v Samantha -r 160 'Order twelve amber chairs. Send twenty birch invitations.' -o "$RECALL_DIR/sentence.aiff"
+say -v Samantha -r 160 'Amber.' -o "$RECALL_DIR/short.aiff"
+afconvert -f WAVE -d LEI16@16000 -c 1 "$RECALL_DIR/sentence.aiff" "$RECALL_DIR/sentence.wav"
+afconvert -f WAVE -d LEI16@16000 -c 1 "$RECALL_DIR/short.aiff" "$RECALL_DIR/short.wav"
+SCREENPIPE_RECALL_SENTENCE_WAV="$RECALL_DIR/sentence.wav" SCREENPIPE_RECALL_SHORT_WAV="$RECALL_DIR/short.wav" SCREENPIPE_RECALL_ACOUSTIC_RECEIPT="$RECALL_DIR/acoustic.json" cargo test -p screenpipe-audio --test continuous_recall_stress_test acoustic_vad -- --ignored --nocapture
+SCREENPIPE_RECALL_SHORT_WAV="$RECALL_DIR/short.wav" SCREENPIPE_RECALL_PADDING_RECEIPT="$RECALL_DIR/padding.json" cargo test -p screenpipe-audio --test continuous_recall_stress_test short_speech_padding -- --ignored --nocapture
+```
+
+The 108 conditions vary sentence/single-word/silence, position, gain, seeded
+uniform noise and input/output thresholds. They use production `prepare_segments`
+with Silero and its no-diarization fallback. Six sentence conditions also run
+actual CPU Whisper, then the handler and database. Acoustic assertions validate
+recognized-text retention, not perfect ASR. Score recognized words separately
+against the spoken reference, explicitly handling `twelve`/`12` and `twenty`/`20`.
+
+The padding probe keeps spoken samples constant and changes surrounding silence.
+Two Whisper controls explicitly bypass VAD to separate admission loss from model
+recognition. It is a diagnostic, not a claim that short speech is captured.
+Receipts retain rejected conditions. Keep WAV/model hashes, tool versions and
+commands with results. Do not attach private recordings or account telemetry.
+
+## Limits
+
+Missing offsets retain the legacy capture-time heuristic; invalid/partial offsets
+fail open. Valid intervals must overlap. Concurrent checks are not atomic with
+insertion, and the scan remains capped at 50 candidates. Same-file exact-text
+uniqueness can collapse repetition. VAD can reject sparse speech before cleanup;
+no VAD threshold is tuned here. Hardware capture, device switches, diarization,
+battery and final-answer completeness remain outside these tests. Large probes
+are ignored manual tests using existing infrastructure, with no new CI jobs.
diff --git a/crates/screenpipe-db/src/db/audio.rs b/crates/screenpipe-db/src/db/audio.rs
index 1f24c012c..f93378848 100644
--- a/crates/screenpipe-db/src/db/audio.rs
+++ b/crates/screenpipe-db/src/db/audio.rs
@@ -4,6 +4,31 @@
use super::*;
+// Preserve numbers, signs, contractions and word order. Only sentence-ending
+// punctuation/case differences are harmless for cross-device echo matching.
+fn duplicate_words(text: &str) -> Vec<String> {
+ text.split_whitespace()
+ .map(|word| {
+ word.trim_end_matches(['.', ',', '!', '?', ';', ':'])
+ .to_lowercase()
+ })
+ .collect()
+}
+
+// Segment offsets are relative to the recording's capture timestamp.
+fn speech_interval(
+ timestamp: DateTime<Utc>,
+ start: Option<f64>,
+ end: Option<f64>,
+) -> Option<(f64, f64)> {
+ let (start, end) = (start?, end?);
+ if !start.is_finite() || !end.is_finite() || start < 0.0 || end <= start {
+ return None;
+ }
+ let base = timestamp.timestamp() as f64 + timestamp.timestamp_subsec_nanos() as f64 / 1e9;
+ Some((base + start, base + end))
+}
+
impl DatabaseManager {
pub async fn insert_audio_chunk(
&self,
@@ -359,7 +384,7 @@ impl DatabaseManager {
// sweep even though we DID process it (the other device kept the
// text).
if self
- .has_similar_recent_transcription(trimmed, DEDUP_TIME_WINDOW_SECS)
+ .has_duplicate_from_other_device(trimmed, device, timestamp, start_time, end_time)
.await?
{
debug!(
@@ -459,7 +484,7 @@ impl DatabaseManager {
false
} else {
match self
- .has_similar_recent_transcription(trimmed, DEDUP_TIME_WINDOW_SECS)
+ .has_duplicate_from_other_device(trimmed, device, timestamp, start_time, end_time)
.await
{
Ok(is_duplicate) => is_duplicate,
@@ -504,35 +529,55 @@ impl DatabaseManager {
}
}
- /// Check if a similar transcription exists in the recent time window.
- /// Used for cross-device deduplication.
- async fn has_similar_recent_transcription(
+ /// Deduplicate matching words captured by another device at the same time.
+ /// Similar wording is not evidence of duplicate speech: a new number,
+ /// negation or longer sentence must survive, as must repetition on one mic.
+ async fn has_duplicate_from_other_device(
&self,
transcription: &str,
- time_window_secs: i64,
+ device: &AudioDevice,
+ timestamp: Option<DateTime<Utc>>,
+ start_time: Option<f64>,
+ end_time: Option<f64>,
) -> Result<bool, sqlx::Error> {
- // Fetch recent transcriptions from ALL devices
- let recent: Vec<(String,)> = sqlx::query_as(
- "SELECT transcription FROM audio_transcriptions
- WHERE timestamp > strftime('%Y-%m-%dT%H:%M:%S+00:00', 'now', ?1)
+ let captured = timestamp.unwrap_or_else(Utc::now);
+ let window = chrono::Duration::seconds(DEDUP_TIME_WINDOW_SECS);
+ // Bound by capture time, not processing time, so a deferred recording
+ // cannot be discarded because similar speech happens to be live now.
+ let recent: Vec<(String, DateTime<Utc>, Option<f64>, Option<f64>)> = sqlx::query_as(
+ "SELECT transcription, timestamp, start_time, end_time FROM audio_transcriptions
+ WHERE timestamp >= ?1 AND timestamp <= ?2
+ AND (device != ?3 OR is_input_device != ?4)
ORDER BY timestamp DESC
LIMIT 50",
)
- .bind(format!("-{} seconds", time_window_secs))
+ .bind(captured - window)
+ .bind(captured + window)
+ .bind(&device.name)
+ .bind(device.device_type == DeviceType::Input)
.fetch_all(&self.pool)
.await?;
- // Normalize the incoming transcription once, then reuse it across every
- // recent row instead of re-tokenizing it on each comparison (up to 50x
- // per inserted chunk, 24/7).
- let new_words = normalize_transcription(transcription);
- for (existing,) in recent {
- if is_similar_to_normalized(&new_words, &existing, DEDUP_SIMILARITY_THRESHOLD) {
- return Ok(true);
+ let new_words = duplicate_words(transcription);
+ Ok(recent.into_iter().any(|(existing, at, start, end)| {
+ // Chunk start times can match while two utterances are separate.
+ // Known segment intervals must overlap before words can be an echo.
+ // Legacy rows without either offset keep the capture-time fallback;
+ // partial or invalid offsets are not evidence for deleting speech.
+ let current = speech_interval(captured, start_time, end_time);
+ let previous = speech_interval(at, start, end);
+ if (current.is_none() && (start_time.is_some() || end_time.is_some()))
+ || (previous.is_none() && (start.is_some() || end.is_some()))
+ {
+ return false;
}
- }
-
- Ok(false)
+ if let (Some((a, b)), Some((c, d))) = (current, previous) {
+ if a >= d || c >= b {
+ return false;
+ }
+ }
+ new_words == duplicate_words(&existing)
+ }))
}
pub async fn update_audio_transcription(
diff --git a/crates/screenpipe-db/src/db/mod.rs b/crates/screenpipe-db/src/db/mod.rs
index 28c677003..81960a285 100644
--- a/crates/screenpipe-db/src/db/mod.rs
+++ b/crates/screenpipe-db/src/db/mod.rs
@@ -27,7 +27,6 @@ use std::collections::BTreeMap;
use zerocopy::AsBytes;
use crate::{
- text_similarity::{is_similar_to_normalized, normalize_transcription},
AudioChunkProcessingSnapshot, AudioChunksResponse, AudioDevice, AudioEntry, AudioResult,
AudioResultRaw, ChunkOutcome, ContentType, DeviceType, Element, ElementRow, ElementSource,
FrameData, FrameRow, FrameRowLight, FrameWindowData, InsertUiEvent, MeetingRecord,
@@ -48,9 +47,6 @@ const DEDUP_TIME_WINDOW_SECS: i64 = 45;
/// stall threw away recordings the write path could have stored (CLI-SN).
const PRE_READ_ATTEMPTS: u32 = 3;
-/// Similarity threshold for cross-device deduplication (0.0 to 1.0).
-/// Higher = stricter matching, lower = more aggressive deduplication.
-const DEDUP_SIMILARITY_THRESHOLD: f64 = 0.85;
const FRAMES_FTS_EXTERNAL_CONTENT_MIGRATION_VERSION: i64 = 20260415000000;
/// Migration that retires the ocr_text table: backfills its data onto frames
/// (app/window/focused + per-word text_json) then drops it. Scans the whole
diff --git a/crates/screenpipe-db/tests/audio_duplicate_test.rs b/crates/screenpipe-db/tests/audio_duplicate_test.rs
index 8474e91a6..55188eda1 100644
--- a/crates/screenpipe-db/tests/audio_duplicate_test.rs
+++ b/crates/screenpipe-db/tests/audio_duplicate_test.rs
@@ -141,11 +141,10 @@ mod tests {
.await
.unwrap();
- assert_eq!(
- id2, 0,
- "Transcription containing duplicate content should be rejected"
+ assert!(
+ id2 > 0,
+ "a longer transcript contains new information and must survive"
);
- println!("✓ Short-in-long cross-device duplicate was correctly rejected");
}
/// Test the production case: nearly identical transcriptions with minor Whisper variations
@@ -248,12 +247,11 @@ mod tests {
.await
.unwrap();
- // This MUST be rejected - it was the exact bug
- assert_eq!(
- id2, 0,
- "REGRESSION: This is the exact production bug - must be rejected"
+ // The repeated ending does not cover the additional sentences.
+ assert!(
+ id2 > 0,
+ "preserve the extra speech around the shared phrase"
);
- println!("✓ REGRESSION TEST PASSED: Production duplicate scenario is now fixed");
}
/// Test that legitimately different content from different devices is allowed
@@ -496,7 +494,7 @@ mod tests {
/// Test rapid consecutive inserts (potential race condition scenario)
#[tokio::test]
- async fn test_rapid_inserts_deduplicated() {
+ async fn test_rapid_cross_device_echoes_do_not_erase_same_device_repetition() {
let db = setup_test_db().await;
let text = "This is a test transcription that should only appear once in the database.";
@@ -527,10 +525,9 @@ mod tests {
}
assert_eq!(
- successful, 1,
- "Only first of 5 rapid duplicate inserts should succeed"
+ successful, 3,
+ "retain each output occurrence while suppressing its input echo"
);
- println!("✓ Rapid consecutive duplicates correctly deduplicated (1 of 5 inserted)");
}
// ===========================================================================
diff --git a/crates/screenpipe-db/tests/continuous_audio_recall_test.rs b/crates/screenpipe-db/tests/continuous_audio_recall_test.rs
new file mode 100644
index 000000000..3f1456f12
--- /dev/null
+++ b/crates/screenpipe-db/tests/continuous_audio_recall_test.rs
@@ -0,0 +1,871 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+use chrono::Utc;
+use screenpipe_db::{AudioDevice, DatabaseManager, DeviceType, Order};
+
+// Perfect STT inputs isolate storage/retrieval from recognition and summarization.
+// No meeting, live stream, second device, or model is involved.
+#[tokio::test]
+async fn spoken_checklist_preserves_distinct_details_from_one_microphone() {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ let mic = AudioDevice {
+ name: "Synthetic microphone".into(),
+ device_type: DeviceType::Input,
+ };
+ let captured = Utc::now();
+ let mut expected = Vec::new();
+ for (group, template) in [
+ "For the launch checklist please remember to send a separate invitation to",
+ "For the office order please remember to include a separate box of",
+ "For the travel schedule please remember to book a separate visit to",
+ "For the review meeting please remember to request a separate update from",
+ "For the website release please remember to check the complete page for",
+ ]
+ .iter()
+ .enumerate()
+ {
+ for (item, detail) in ["amber", "birch", "cedar", "dahlia", "elm"]
+ .iter()
+ .enumerate()
+ {
+ let text = format!("{template} {detail}.");
+ let idx = group * 5 + item;
+ db.insert_audio_chunk_and_transcription(
+ &format!("synthetic-checklist-{group}.mp4"),
+ &text,
+ 0,
+ "perfect-stt-fixture",
+ &mic,
+ None,
+ Some(item as f64 * 5.0),
+ Some((item + 1) as f64 * 5.0),
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ expected.push(text);
+ eprintln!("submitted fact {}", idx + 1);
+ }
+ }
+ let stored: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ eprintln!("stored transcript rows: {stored}");
+ let mut actual = Vec::new();
+ for offset in [0, 20, 40] {
+ actual.extend(
+ db.search_audio_ordered(
+ "",
+ 20,
+ offset,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some("Synthetic microphone"),
+ None,
+ &[],
+ Order::Ascending,
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ let found = expected
+ .iter()
+ .filter(|text| actual.iter().any(|r| &r.transcription == *text))
+ .count();
+ eprintln!(
+ "perfect input facts: {}; searchable facts: {}",
+ expected.len(),
+ found
+ );
+ assert_eq!(
+ found, 25,
+ "distinct checklist details must survive continuous audio persistence and paginated search"
+ );
+}
+
+#[tokio::test]
+async fn two_distinct_numbers_from_same_mic_survive() {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ let mic = AudioDevice {
+ name: "Synthetic microphone".into(),
+ device_type: DeviceType::Input,
+ };
+ let captured = Utc::now();
+ for (i, text) in [
+ "Please remember that the number of chairs we need to order is 12.",
+ "Please remember that the number of chairs we need to order is 20.",
+ ]
+ .iter()
+ .enumerate()
+ {
+ db.insert_audio_chunk_and_transcription(
+ "synthetic-correction.mp4",
+ text,
+ 0,
+ "perfect-stt-fixture",
+ &mic,
+ None,
+ Some(i as f64 * 5.0),
+ Some(i as f64 * 5.0 + 5.0),
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ }
+ let stored: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(
+ stored, 2,
+ "a changed number is new information, not a duplicate"
+ );
+}
+
+#[tokio::test]
+async fn all_segments_in_five_recorded_chunks_are_searchable() {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ let mic = AudioDevice {
+ name: "Synthetic microphone".into(),
+ device_type: DeviceType::Input,
+ };
+ let base = Utc::now() - chrono::Duration::hours(1);
+ for chunk in 0..5 {
+ for segment in 0..5 {
+ let text = format!("Checklist fact {}", chunk * 5 + segment + 1);
+ db.insert_audio_chunk_and_transcription(
+ &format!("recorded-{chunk}.mp4"),
+ &text,
+ 0,
+ "perfect-stt-fixture",
+ &mic,
+ None,
+ Some(segment as f64 * 5.0),
+ Some(segment as f64 * 5.0 + 5.0),
+ Some(base + chrono::Duration::seconds(chunk * 30)),
+ )
+ .await
+ .unwrap();
+ }
+ }
+ let stored: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(stored, 25, "setup must preserve all facts before search");
+ let mut found = Vec::new();
+ for offset in [0, 20, 40] {
+ found.extend(
+ db.search_audio_ordered(
+ "",
+ 20,
+ offset,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ &[],
+ Order::Ascending,
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ eprintln!("stored facts: {stored}; searchable facts: {}", found.len());
+ assert_eq!(
+ found.len(),
+ 25,
+ "segments sharing a chunk and offset are distinct speech"
+ );
+}
+
+#[tokio::test]
+async fn other_devices_cannot_erase_numbers_negations_or_extra_details() {
+ for (first, second) in [
+ (
+ "Please order exactly 12 chairs for our workshop.",
+ "Please order exactly 20 chairs for our workshop.",
+ ),
+ (
+ "Approve the payment for the order.",
+ "Do not approve the payment for the order.",
+ ),
+ (
+ "Send the proposal tomorrow.",
+ "Send the proposal tomorrow. Include the security appendix.",
+ ),
+ (
+ "The adjustment is -12.5 dollars.",
+ "The adjustment is 125 dollars.",
+ ),
+ (
+ "Please ship from London to Paris.",
+ "Please ship from Paris to London.",
+ ),
+ ] {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ for (i, text) in [first, second].iter().enumerate() {
+ let device = AudioDevice {
+ name: format!("device-{i}"),
+ device_type: if i == 0 {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ };
+ let chunk = db
+ .insert_audio_chunk(&format!("file-{i}.mp4"), None)
+ .await
+ .unwrap();
+ assert!(
+ db.insert_audio_transcription(
+ chunk,
+ text,
+ 0,
+ "perfect-stt-fixture",
+ &device,
+ None,
+ None,
+ None,
+ None
+ )
+ .await
+ .unwrap()
+ > 0
+ );
+ }
+ }
+}
+
+#[tokio::test]
+async fn delayed_recording_is_not_compared_with_unrelated_live_speech() {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ let text = "Please send the complete proposal tomorrow.";
+ let now = Utc::now();
+ for (i, captured) in [now, now - chrono::Duration::hours(1)].iter().enumerate() {
+ let device = AudioDevice {
+ name: format!("device-{i}"),
+ device_type: if i == 0 {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ };
+ assert!(
+ db.insert_audio_chunk_and_transcription(
+ &format!("file-{i}.mp4"),
+ text,
+ 0,
+ "perfect-stt-fixture",
+ &device,
+ None,
+ None,
+ None,
+ Some(*captured)
+ )
+ .await
+ .unwrap()
+ > 0
+ );
+ }
+}
+
+#[tokio::test]
+async fn delayed_cross_device_echo_still_deduplicates_at_capture_time() {
+ let db = DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap();
+ let captured = Utc::now() - chrono::Duration::hours(1);
+ let mut ids = Vec::new();
+ for i in 0..2 {
+ let device = AudioDevice {
+ name: format!("device-{i}"),
+ device_type: if i == 0 {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ };
+ let chunk = db
+ .insert_audio_chunk(&format!("file-{i}.mp4"), Some(captured))
+ .await
+ .unwrap();
+ ids.push(
+ db.insert_audio_transcription(
+ chunk,
+ "Please send the complete proposal tomorrow.",
+ 0,
+ "perfect-stt-fixture",
+ &device,
+ None,
+ None,
+ None,
+ Some(captured),
+ )
+ .await
+ .unwrap(),
+ );
+ }
+ assert!(ids[0] > 0);
+ assert_eq!(ids[1], 0);
+}
+
+#[tokio::test]
+#[ignore = "manual persistence latency probe; not a CI performance threshold"]
+async fn measure_continuous_transcript_insert_latency() {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new(
+ dir.path().join("latency.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let captured = Utc::now();
+ let output = AudioDevice {
+ name: "Synthetic output".into(),
+ device_type: DeviceType::Output,
+ };
+ let mic = AudioDevice {
+ name: "Synthetic microphone".into(),
+ device_type: DeviceType::Input,
+ };
+ for i in 0..50 {
+ db.insert_audio_chunk_and_transcription(
+ &format!("output-{i}.mp4"),
+ &format!("Independent system output statement number {i}."),
+ 0,
+ "fixture",
+ &output,
+ None,
+ None,
+ None,
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ }
+ let mut micros = Vec::new();
+ let began = std::time::Instant::now();
+ for i in 0..1000 {
+ let start = std::time::Instant::now();
+ db.insert_audio_chunk_and_transcription(
+ &format!("mic-{i}.mp4"),
+ &format!("Remember this distinct microphone fact number {i}."),
+ 0,
+ "fixture",
+ &mic,
+ None,
+ None,
+ None,
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ micros.push(start.elapsed().as_micros());
+ }
+ let elapsed = began.elapsed();
+ let count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(count, 1050);
+ micros.sort_unstable();
+ eprintln!(
+ "1000 persisted microphone facts; wall_ms={}; p50_us={}; p95_us={}; p99_us={}",
+ elapsed.as_millis(),
+ micros[500],
+ micros[950],
+ micros[990]
+ );
+}
+
+#[tokio::test]
+async fn cross_device_retention_and_echo_eval_matrix() {
+ // Both public insertion routes must make the same retention decision.
+ let cases = [
+ (
+ "exact_echo",
+ "Send the complete proposal tomorrow.",
+ "Send the complete proposal tomorrow.",
+ true,
+ 0,
+ 1,
+ ),
+ (
+ "case_punctuation_echo",
+ "Send the complete proposal tomorrow.",
+ "SEND THE COMPLETE PROPOSAL TOMORROW!",
+ true,
+ 0,
+ 1,
+ ),
+ (
+ "whitespace_echo",
+ "Send the complete proposal tomorrow.",
+ "Send the complete proposal tomorrow.",
+ true,
+ 0,
+ 1,
+ ),
+ (
+ "same_device_repetition",
+ "Send the complete proposal tomorrow.",
+ "Send the complete proposal tomorrow.",
+ false,
+ 0,
+ 2,
+ ),
+ (
+ "old_unrelated_speech",
+ "Send the complete proposal tomorrow.",
+ "Send the complete proposal tomorrow.",
+ true,
+ -3600,
+ 2,
+ ),
+ (
+ "future_unrelated_speech",
+ "Send the complete proposal tomorrow.",
+ "Send the complete proposal tomorrow.",
+ true,
+ 3600,
+ 2,
+ ),
+ (
+ "changed_number",
+ "Order exactly 12 chairs tomorrow.",
+ "Order exactly 20 chairs tomorrow.",
+ true,
+ 0,
+ 2,
+ ),
+ (
+ "changed_decimal",
+ "The adjustment is -12.5 dollars.",
+ "The adjustment is -125 dollars.",
+ true,
+ 0,
+ 2,
+ ),
+ (
+ "changed_sign",
+ "The adjustment is -12.5 dollars.",
+ "The adjustment is +12.5 dollars.",
+ true,
+ 0,
+ 2,
+ ),
+ (
+ "added_negation",
+ "Please approve the payment.",
+ "Please do not approve the payment.",
+ true,
+ 0,
+ 2,
+ ),
+ (
+ "extra_detail",
+ "Send the proposal tomorrow.",
+ "Send the proposal tomorrow. Include the appendix.",
+ true,
+ 0,
+ 2,
+ ),
+ (
+ "word_order",
+ "Please ship from London to Paris.",
+ "Please ship from Paris to London.",
+ true,
+ 0,
+ 2,
+ ),
+ ];
+ let mut failures = Vec::new();
+ for combined in [false, true] {
+ for (name, first, second, other_direction, delay, expected) in cases {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new(
+ dir.path().join("eval.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let base = Utc::now() - chrono::Duration::hours(2);
+ for (i, text) in [first, second].iter().enumerate() {
+ // Same hardware name can expose both input and output streams.
+ let device = AudioDevice {
+ name: "Synthetic duplex device".into(),
+ device_type: if i == 1 && other_direction {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ };
+ let at = base + chrono::Duration::seconds(if i == 0 { 0 } else { delay });
+ let file = format!("chunk-{i}.mp4");
+ if combined {
+ db.insert_audio_chunk_and_transcription(
+ &file,
+ text,
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(0.0),
+ Some(5.0),
+ Some(at),
+ )
+ .await
+ .unwrap();
+ } else {
+ let chunk = db.insert_audio_chunk(&file, Some(at)).await.unwrap();
+ db.insert_audio_transcription(
+ chunk,
+ text,
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(0.0),
+ Some(5.0),
+ Some(at),
+ )
+ .await
+ .unwrap();
+ }
+ }
+ let actual: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ let passed = actual == expected;
+ eprintln!("DB_RECALL_EVAL {{\"case\":\"{name}\",\"combined\":{combined},\"passed\":{passed},\"expected_rows\":{expected},\"actual_rows\":{actual}}}");
+ if !passed {
+ failures.push(format!("{name}/combined={combined}"));
+ }
+ }
+ }
+ assert!(
+ failures.is_empty(),
+ "cross-device eval failures: {failures:?}"
+ );
+}
+
+#[tokio::test]
+async fn disjoint_segment_times_survive_both_insert_paths() {
+ for combined in [false, true] {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new(
+ dir.path().join("interval.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let at = Utc::now();
+ for (i, (start, end)) in [(0.0, 5.0), (15.0, 20.0)].into_iter().enumerate() {
+ let device = AudioDevice {
+ name: "duplex".into(),
+ device_type: if i == 0 {
+ DeviceType::Input
+ } else {
+ DeviceType::Output
+ },
+ };
+ let file = format!("interval-{i}.wav");
+ if combined {
+ db.insert_audio_chunk_and_transcription(
+ &file,
+ "Please send the complete proposal tomorrow.",
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(start),
+ Some(end),
+ Some(at),
+ )
+ .await
+ .unwrap();
+ } else {
+ let chunk = db.insert_audio_chunk(&file, Some(at)).await.unwrap();
+ db.insert_audio_transcription(
+ chunk,
+ "Please send the complete proposal tomorrow.",
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(start),
+ Some(end),
+ Some(at),
+ )
+ .await
+ .unwrap();
+ }
+ }
+ let rows: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(
+ rows, 2,
+ "combined={combined}: disjoint speech is not an echo"
+ );
+ }
+}
+
+#[tokio::test]
+#[ignore = "manual 480-case timing/device/insertion-path sweep"]
+async fn cross_device_interval_eval_sweep() {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new(
+ dir.path().join("sweep.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let base = Utc::now() - chrono::Duration::days(7);
+ let mut cases = 0;
+ let mut missed_echoes = 0;
+ let mut lost_utterances = 0;
+ for combined in [false, true] {
+ for direction in 0..3 {
+ for delta in [-30, -5, 0, 5, 30] {
+ for first in [(0.0_f64, 5.0_f64), (5.0, 10.0), (10.0, 30.0), (0.0, 30.0)] {
+ for second in [(0.0_f64, 5.0_f64), (5.0, 10.0), (10.0, 30.0), (0.0, 30.0)] {
+ let text = format!("Please preserve timing scenario {cases} completely.");
+ let at = base + chrono::Duration::seconds(cases * 120);
+ for (i, (start, end)) in [first, second].into_iter().enumerate() {
+ let output = (direction == 0 && i == 0) || (direction == 1 && i == 1);
+ let device = AudioDevice {
+ name: if direction == 2 {
+ format!("microphone-{i}")
+ } else {
+ "duplex".into()
+ },
+ device_type: if output {
+ DeviceType::Output
+ } else {
+ DeviceType::Input
+ },
+ };
+ let captured =
+ at + chrono::Duration::seconds(if i == 0 { 0 } else { delta });
+ let file = format!("{cases}-{i}.wav");
+ if combined {
+ db.insert_audio_chunk_and_transcription(
+ &file,
+ &text,
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(start),
+ Some(end),
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ } else {
+ let chunk =
+ db.insert_audio_chunk(&file, Some(captured)).await.unwrap();
+ db.insert_audio_transcription(
+ chunk,
+ &text,
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(start),
+ Some(end),
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ }
+ }
+ let actual: i64 = sqlx::query_scalar(
+ "SELECT COUNT(*) FROM audio_transcriptions WHERE transcription = ?1",
+ )
+ .bind(&text)
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ let overlap =
+ first.0 < delta as f64 + second.1 && delta as f64 + second.0 < first.1;
+ let expected = if overlap { 1 } else { 2 };
+ lost_utterances += (expected - actual).max(0);
+ missed_echoes += (actual - expected).max(0);
+ cases += 1;
+ }
+ }
+ }
+ }
+ }
+ eprintln!("INTERVAL_RECALL_EVAL {{\"cases\":{cases},\"lost_utterances\":{lost_utterances},\"missed_echoes\":{missed_echoes}}}");
+ assert_eq!((lost_utterances, missed_echoes), (0, 0));
+}
+
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+#[ignore = "manual race probe; reports duplicate survivors rather than promising exactly-once insertion"]
+async fn concurrent_echo_retention_probe() {
+ use std::sync::Arc;
+ let dir = tempfile::tempdir().unwrap();
+ let db = Arc::new(
+ DatabaseManager::new(
+ dir.path().join("race.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap(),
+ );
+ let mut survivors = Vec::new();
+ for group in 0..64 {
+ let text = format!("Preserve the entire concurrent statement number {group}.");
+ let captured =
+ Utc::now() - chrono::Duration::days(1) + chrono::Duration::minutes(group * 2);
+ let barrier = Arc::new(tokio::sync::Barrier::new(8));
+ let mut tasks = Vec::new();
+ for i in 0..8 {
+ let (db, barrier, text) = (db.clone(), barrier.clone(), text.clone());
+ tasks.push(tokio::spawn(async move {
+ let device = AudioDevice {
+ name: format!("device-{i}"),
+ device_type: DeviceType::Input,
+ };
+ barrier.wait().await;
+ db.insert_audio_chunk_and_transcription(
+ &format!("race-{group}-{i}.wav"),
+ &text,
+ 0,
+ "fixture",
+ &device,
+ None,
+ Some(0.0),
+ Some(10.0),
+ Some(captured),
+ )
+ .await
+ .unwrap();
+ }));
+ }
+ for task in tasks {
+ task.await.unwrap();
+ }
+ let actual: i64 = sqlx::query_scalar(
+ "SELECT COUNT(*) FROM audio_transcriptions WHERE transcription = ?1",
+ )
+ .bind(&text)
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert!(
+ (1..=8).contains(&actual),
+ "race must preserve at least one complete copy"
+ );
+ survivors.push(actual);
+ }
+ let duplicated_groups = survivors.iter().filter(|&&n| n > 1).count();
+ let extra_copies: i64 = survivors.iter().map(|n| n - 1).sum();
+ eprintln!("CONCURRENT_RECALL_EVAL {{\"groups\":64,\"submissions\":512,\"lost_groups\":0,\"duplicated_groups\":{duplicated_groups},\"extra_copies\":{extra_copies}}}");
+}
+
+#[tokio::test]
+async fn invalid_or_partial_offsets_cannot_justify_deleting_speech() {
+ let invalid = [
+ (Some(0.0), None),
+ (None, Some(5.0)),
+ (Some(-1.0), Some(5.0)),
+ (Some(5.0), Some(1.0)),
+ (Some(0.0), Some(0.0)),
+ (Some(f64::NEG_INFINITY), Some(5.0)),
+ (Some(0.0), Some(f64::INFINITY)),
+ (Some(f64::NAN), Some(5.0)),
+ (Some(0.0), Some(f64::NAN)),
+ ];
+ for combined in [false, true] {
+ for invalid_first in [false, true] {
+ for offsets in invalid {
+ let dir = tempfile::tempdir().unwrap();
+ let db = DatabaseManager::new(
+ dir.path().join("invalid.sqlite").to_str().unwrap(),
+ Default::default(),
+ )
+ .await
+ .unwrap();
+ let at = Utc::now();
+ for i in 0..2 {
+ let (start, end) = if (i == 0) == invalid_first {
+ offsets
+ } else {
+ (Some(0.0), Some(5.0))
+ };
+ let device = AudioDevice {
+ name: format!("device-{i}"),
+ device_type: DeviceType::Input,
+ };
+ let file = format!("invalid-{i}.wav");
+ if combined {
+ db.insert_audio_chunk_and_transcription(
+ &file,
+ "Preserve this speech with uncertain timing.",
+ 0,
+ "fixture",
+ &device,
+ None,
+ start,
+ end,
+ Some(at),
+ )
+ .await
+ .unwrap();
+ } else {
+ let chunk = db.insert_audio_chunk(&file, Some(at)).await.unwrap();
+ db.insert_audio_transcription(
+ chunk,
+ "Preserve this speech with uncertain timing.",
+ 0,
+ "fixture",
+ &device,
+ None,
+ start,
+ end,
+ Some(at),
+ )
+ .await
+ .unwrap();
+ }
+ }
+ let rows: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM audio_transcriptions")
+ .fetch_one(&db.pool)
+ .await
+ .unwrap();
+ assert_eq!(
+ rows, 2,
+ "combined={combined}, invalid_first={invalid_first}, offsets={offsets:?}"
+ );
+ }
+ }
+ }
+}
diff --git a/docs/COVERAGE.md b/docs/COVERAGE.md
index d999f03a5..13f7528e5 100644
--- a/docs/COVERAGE.md
+++ b/docs/COVERAGE.md
@@ -37,16 +37,16 @@ results and `cargo llvm-cov` data on top when judging release confidence.
### Core Engine
- Mapped suites: 36
-- Mapped Rust files: 384
-- Active test blocks: 3795
-- Ignored/manual test blocks: 170
-- Weighted coverage points: 3130.7
+- Mapped Rust files: 388
+- Active test blocks: 3827
+- Ignored/manual test blocks: 177
+- Weighted coverage points: 3162.7
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 32 | 3649 | 156 | 3064.4 | 21 | 11 | 100% |
-| macos | 31 | 3675 | 131 | 3052.9 | 22 | 11 | 100% |
-| linux | 28 | 3232 | 131 | 2687.8 | 20 | 11 | 100% |
+| windows | 32 | 3681 | 163 | 3096.4 | 21 | 11 | 100% |
+| macos | 31 | 3707 | 138 | 3084.9 | 22 | 11 | 100% |
+| linux | 28 | 3264 | 138 | 2719.8 | 20 | 11 | 100% |
## Refresh
diff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.md
index 71ec85b88..990d764f0 100644
--- a/docs/coverage/CORE.md
+++ b/docs/coverage/CORE.md
@@ -8,11 +8,11 @@ confidence, and criticality.
- Manifest: `docs/coverage/core-engine-map.json`
- Tracked crates: screenpipe-engine, screenpipe-db, screenpipe-sqlite-coordinator, screenpipe-audio, screenpipe-screen, screenpipe-a11y, screenpipe-fs
- Mapped suites: 36
-- Mapped Rust files: 384
-- Active test blocks: 3795
-- Ignored/manual test blocks: 170
-- Declared test blocks: 3965
-- Weighted coverage points: 3130.7
+- Mapped Rust files: 388
+- Active test blocks: 3827
+- Ignored/manual test blocks: 177
+- Declared test blocks: 4004
+- Weighted coverage points: 3162.7
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,18 +23,18 @@ are explicitly enabled in a runtime lane.
| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score |
| --- | --- | --- | --- | --- | --- | --- | --- |
-| windows | 32 | 3649 | 156 | 3064.4 | 21 | 11 | 100% |
-| macos | 31 | 3675 | 131 | 3052.9 | 22 | 11 | 100% |
-| linux | 28 | 3232 | 131 | 2687.8 | 20 | 11 | 100% |
+| windows | 32 | 3681 | 163 | 3096.4 | 21 | 11 | 100% |
+| macos | 31 | 3707 | 138 | 3084.9 | 22 | 11 | 100% |
+| linux | 28 | 3264 | 138 | 2719.8 | 20 | 11 | 100% |
## Crate Summary
| Crate | Suites | Integration files | Source unit files | Active tests | Ignored tests | Weighted points | Flows |
| --- | --- | --- | --- | --- | --- | --- | --- |
| screenpipe-engine | 12 | 21 | 127 | 1834 | 52 | 1412.7 | 10 |
-| screenpipe-db | 5 | 66 | 26 | 596 | 26 | 567.6 | 9 |
+| screenpipe-db | 5 | 67 | 27 | 617 | 29 | 588.6 | 9 |
| screenpipe-sqlite-coordinator | 1 | 0 | 3 | 27 | 0 | 27.0 | 2 |
-| screenpipe-audio | 7 | 26 | 53 | 675 | 49 | 590.3 | 5 |
+| screenpipe-audio | 7 | 28 | 53 | 686 | 53 | 601.3 | 5 |
| screenpipe-screen | 6 | 9 | 19 | 276 | 9 | 245.4 | 4 |
| screenpipe-a11y | 4 | 2 | 31 | 384 | 34 | 284.7 | 3 |
| screenpipe-fs | 1 | 0 | 1 | 3 | 0 | 3.0 | 3 |
@@ -63,25 +63,25 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| Layer | windows | macos | linux |
| --- | --- | --- | --- |
| accessibility | 4 suites / 383 active / 35 ignored / 348.0 pts | 4 suites / 422 active / 10 ignored / 342.9 pts | 4 suites / 341 active / 7 ignored / 313.0 pts |
-| audio | 9 suites / 798 active / 50 ignored / 713.3 pts | 8 suites / 792 active / 50 ignored / 709.0 pts | 7 suites / 713 active / 49 ignored / 653.8 pts |
+| audio | 9 suites / 824 active / 57 ignored / 739.3 pts | 8 suites / 818 active / 57 ignored / 735.0 pts | 7 suites / 739 active / 56 ignored / 679.8 pts |
| audio-device | 2 suites / 234 active / 7 ignored / 210.3 pts | 2 suites / 234 active / 7 ignored / 210.3 pts | 1 suites / 155 active / 6 ignored / 155.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 / 553 active / 22 ignored / 524.6 pts | 7 suites / 553 active / 22 ignored / 524.6 pts | 7 suites / 553 active / 22 ignored / 524.6 pts |
+| database | 7 suites / 574 active / 25 ignored / 545.6 pts | 7 suites / 574 active / 25 ignored / 545.6 pts | 7 suites / 574 active / 25 ignored / 545.6 pts |
| db-search | 2 suites / 118 active / 9 ignored / 118.0 pts | 2 suites / 118 active / 9 ignored / 118.0 pts | 2 suites / 118 active / 9 ignored / 118.0 pts |
| engine-lifecycle | 6 suites / 265 active / 1 ignored / 238.5 pts | 6 suites / 265 active / 1 ignored / 238.5 pts | 6 suites / 261 active / 9 ignored / 237.6 pts |
| local-api | 3 suites / 478 active / 11 ignored / 338.2 pts | 3 suites / 478 active / 11 ignored / 338.2 pts | 3 suites / 478 active / 11 ignored / 338.2 pts |
-| meeting | 6 suites / 1708 active / 24 ignored / 1393.3 pts | 6 suites / 1708 active / 24 ignored / 1393.3 pts | 4 suites / 1359 active / 20 ignored / 1068.0 pts |
+| meeting | 6 suites / 1734 active / 31 ignored / 1419.3 pts | 6 suites / 1734 active / 31 ignored / 1419.3 pts | 4 suites / 1385 active / 27 ignored / 1094.0 pts |
| ocr | 4 suites / 140 active / 7 ignored / 129.8 pts | 4 suites / 133 active / 7 ignored / 127.6 pts | 3 suites / 124 active / 6 ignored / 118.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 / 1655 active / 80 ignored / 1463.6 pts | 14 suites / 1763 active / 84 ignored / 1506.8 pts | 13 suites / 1655 active / 80 ignored / 1463.6 pts |
+| performance | 13 suites / 1661 active / 80 ignored / 1469.6 pts | 14 suites / 1769 active / 84 ignored / 1512.8 pts | 13 suites / 1661 active / 80 ignored / 1469.6 pts |
| pipes | 1 suites / 540 active / 3 ignored / 378.0 pts | 1 suites / 540 active / 3 ignored / 378.0 pts | 1 suites / 540 active / 3 ignored / 378.0 pts |
| privacy | 5 suites / 1002 active / 42 ignored / 809.1 pts | 5 suites / 1041 active / 17 ignored / 804.0 pts | 5 suites / 960 active / 14 ignored / 774.0 pts |
| real-app | - | 1 suites / 108 active / 4 ignored / 43.2 pts | - |
-| speaker | 2 suites / 389 active / 11 ignored / 389.0 pts | 2 suites / 389 active / 11 ignored / 389.0 pts | 2 suites / 389 active / 11 ignored / 389.0 pts |
-| storage | 4 suites / 676 active / 39 ignored / 561.7 pts | 4 suites / 676 active / 39 ignored / 561.7 pts | 4 suites / 676 active / 39 ignored / 561.7 pts |
+| speaker | 2 suites / 415 active / 18 ignored / 415.0 pts | 2 suites / 415 active / 18 ignored / 415.0 pts | 2 suites / 415 active / 18 ignored / 415.0 pts |
+| storage | 4 suites / 682 active / 39 ignored / 567.7 pts | 4 suites / 682 active / 39 ignored / 567.7 pts | 4 suites / 682 active / 39 ignored / 567.7 pts |
| sync | 1 suites / 540 active / 3 ignored / 378.0 pts | 1 suites / 540 active / 3 ignored / 378.0 pts | 1 suites / 540 active / 3 ignored / 378.0 pts |
-| timeline | 4 suites / 1224 active / 45 ignored / 1003.2 pts | 4 suites / 1224 active / 45 ignored / 1003.2 pts | 4 suites / 1224 active / 45 ignored / 1003.2 pts |
-| transcription | 6 suites / 871 active / 48 ignored / 680.9 pts | 5 suites / 865 active / 48 ignored / 676.8 pts | 5 suites / 865 active / 48 ignored / 676.8 pts |
+| timeline | 4 suites / 1230 active / 45 ignored / 1009.2 pts | 4 suites / 1230 active / 45 ignored / 1009.2 pts | 4 suites / 1230 active / 45 ignored / 1009.2 pts |
+| transcription | 6 suites / 882 active / 52 ignored / 691.9 pts | 5 suites / 876 active / 52 ignored / 687.8 pts | 5 suites / 876 active / 52 ignored / 687.8 pts |
| ui-events | 4 suites / 817 active / 34 ignored / 620.0 pts | 3 suites / 748 active / 5 ignored / 571.7 pts | 3 suites / 748 active / 5 ignored / 571.7 pts |
| vision-capture | 6 suites / 576 active / 32 ignored / 453.6 pts | 6 suites / 569 active / 32 ignored / 451.4 pts | 5 suites / 560 active / 31 ignored / 442.4 pts |
@@ -124,17 +124,17 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| a11y-macos-tree | screenpipe-a11y | macos | accessibility, privacy, real-app, performance | accessibility-ui-events, privacy-and-redaction, performance-liveness | high | conditional | mixed | 8 | 108 | 4 | macOS AX unit coverage, a scored 100-case click-attribution policy eval, and real TextEdit/Finder/Obsidian probes. Click attribution and Obsidian live tests are ignored by default when they require a logged-in desktop, app install, or AX permission. |
| a11y-windows-tree | screenpipe-a11y | windows | accessibility, privacy, ui-events | accessibility-ui-events, privacy-and-redaction | high | partial | unit | 7 | 69 | 29 | Windows UIA/accessibility parsing and privacy matching; some UIA tests are ignored where they require a live desktop. |
| audio-device-stream-health | screenpipe-audio | windows, macos, linux | audio-device, audio, performance | audio-device-health, audio-record-transcribe, performance-liveness | high | strong | mixed | 14 | 155 | 6 | Device monitor, device manager, stream buffering, source lag, audio metrics, Bluetooth gap/hallucination regressions, and cross-platform process-tap watchdog counters (process_tap.rs split into src/core/process_tap/ modules). |
-| audio-meetings-speakers-dedup | screenpipe-audio | windows, macos, linux | audio, meeting, speaker, transcription | audio-record-transcribe, meeting-live-notes, performance-liveness | high | strong | mixed | 26 | 269 | 10 | Meeting streaming config/controller logic, speaker embedding state, cross-device dedupe simulations, and overlap cleanup coverage. |
+| audio-meetings-speakers-dedup | screenpipe-audio | windows, macos, linux | audio, meeting, speaker, transcription | audio-record-transcribe, meeting-live-notes, performance-liveness | high | strong | mixed | 28 | 280 | 14 | Meeting streaming config/controller logic, speaker embedding state, cross-device dedupe simulations, and overlap cleanup coverage. |
| audio-models-filtering | screenpipe-audio | windows, macos, linux | audio, transcription, privacy | audio-record-transcribe, privacy-and-redaction | medium | partial | mixed | 6 | 20 | 10 | Model-download/TLS guards, ONNX startup smoke, and music-versus-speech filtering. |
| audio-pipeline-benchmarks | screenpipe-audio | windows, macos, linux | audio, transcription, performance | audio-record-transcribe, meeting-live-notes, performance-liveness | medium | partial | benchmark | 9 | 25 | 13 | Benchmark-backed regression probes for VAD, smart mode, meeting audio, quality, cross-device, and end-to-end pipeline timing. Native-window continuity, valid 16 kHz fallback frames and partial-tail regression tests; optional real-model speech-fixture timing is ignored by default. |
| audio-platform-output-capture | screenpipe-audio | windows, macos | audio-device, audio, meeting | audio-device-health, audio-record-transcribe, meeting-live-notes | high | partial | unit | 7 | 79 | 1 | OS-specific output/system-audio capture: CoreAudio process tap and SCK output watchdog plus VPIO health policy on macOS, per-process meeting audio taps on both platforms, and the Windows follow-the-audio output watchdog. Platform impl files are cfg-gated to their target OS. |
| audio-transcription-pipeline | screenpipe-audio | windows, macos, linux | audio, transcription, performance | audio-record-transcribe, meeting-live-notes, performance-liveness | high | partial | mixed | 16 | 121 | 9 | Batch deferral, cleanup, language detection, result normalization, and real recording/transcription tests. Hardware/model-heavy tests are ignored by default. Also covers ffmpeg encode child reaping on error paths. |
| 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 | 18 | 120 | 1 | Audio transcript dedupe, live meeting mirroring, end-generation and open-meeting invariants, liveness, and speaker reassignment coverage. |
+| 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 | 47 | 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 | 37 | 295 | 13 | 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. |
+| db-timeline-frames | screenpipe-db | windows, macos, linux | database, timeline, storage, performance | timeline-streaming, performance-liveness | high | strong | mixed | 38 | 301 | 13 | 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 | 44 | 430 | 6 | 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 | 306 | 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. |
@@ -258,6 +258,8 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| audio-transcription-pipeline | screenpipe-audio | tests/batch_deferral_test.rs | integration | 21 | 0 | 21 |
| audio-device-stream-health | screenpipe-audio | tests/bluetooth_gap_hallucination_test.rs | integration | 1 | 2 | 3 |
| audio-device-stream-health | screenpipe-audio | tests/channel_lag_test.rs | integration | 3 | 0 | 3 |
+| audio-meetings-speakers-dedup | screenpipe-audio | tests/continuous_recall_stress_test.rs | integration | 2 | 3 | 5 |
+| audio-meetings-speakers-dedup | screenpipe-audio | tests/continuous_recall_test.rs | integration | 9 | 1 | 10 |
| audio-transcription-pipeline | screenpipe-audio | tests/core_tests.rs | integration | 1 | 6 | 7 |
| audio-meetings-speakers-dedup | screenpipe-audio | tests/dedup_benchmark/fixtures.rs | integration | 3 | 0 | 3 |
| audio-meetings-speakers-dedup | screenpipe-audio | tests/dedup_benchmark/integration.rs | integration | 12 | 0 | 12 |
@@ -277,6 +279,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-accessibility-ui-events | screenpipe-db | src/db/elements.rs | source | 5 | 0 | 5 |
| db-timeline-frames | screenpipe-db | src/db/feedback.rs | source | 2 | 0 | 2 |
| db-timeline-frames | screenpipe-db | src/db/maintenance.rs | source | 5 | 1 | 6 |
+| db-timeline-frames | screenpipe-db | src/db/planner_stats_tests.rs | source | 6 | 0 | 6 |
| db-timeline-frames | screenpipe-db | src/db/setup.rs | source | 7 | 0 | 7 |
| db-timeline-frames | screenpipe-db | src/db/source_identity.rs | source | 3 | 0 | 3 |
| db-search-indexing | screenpipe-db | src/db/starred.rs | source | 1 | 0 | 1 |
@@ -307,6 +310,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-runtime-reliability | screenpipe-db | tests/cancellation_performance_bench.rs | integration | 0 | 1 | 1 |
| db-audio-meetings-speakers | screenpipe-db | tests/chunk_outcome_test.rs | integration | 14 | 0 | 14 |
| db-runtime-reliability | screenpipe-db | tests/close_severs_connections_test.rs | integration | 5 | 0 | 5 |
+| db-audio-meetings-speakers | screenpipe-db | tests/continuous_audio_recall_test.rs | integration | 9 | 3 | 12 |
| db-accessibility-ui-events | screenpipe-db | tests/db_config_test.rs | integration | 5 | 0 | 5 |
| db-timeline-frames | screenpipe-db | tests/db.rs | integration | 42 | 0 | 42 |
| db-accessibility-ui-events | screenpipe-db | tests/display_layout_test.rs | integration | 4 | 0 | 4 |
@@ -326,7 +330,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su
| db-audio-meetings-speakers | screenpipe-db | tests/meeting_end_generation_test.rs | integration | 1 | 0 | 1 |
| db-audio-meetings-speakers | screenpipe-db | tests/meeting_end_reason_test.rs | integration | 11 | 0 | 11 |
| db-audio-meetings-speakers | screenpipe-db | tests/meeting_playback_regression_test.rs | integration | 2 | 0 | 2 |
-| db-audio-meetings-speakers | screenpipe-db | tests/meeting_transcript_dedup_test.rs | integration | 1 | 0 | 1 |
+| db-audio-meetings-speakers | screenpipe-db | tests/meeting_transcript_dedup_test.rs | integration | 7 | 0 | 7 |
| db-runtime-reliability | screenpipe-db | tests/memory_pressure_test.rs | integration | 0 | 2 | 2 |
| db-timeline-frames | screenpipe-db | tests/migration_foreign_keys.rs | integration | 2 | 0 | 2 |
| db-timeline-frames | screenpipe-db | tests/migration_source_recovery.rs | integration | 11 | 0 | 11 |
diff --git a/docs/coverage/core-engine-map.json b/docs/coverage/core-engine-map.json
index e84eae384..76f9917bd 100644
--- a/docs/coverage/core-engine-map.json
+++ b/docs/coverage/core-engine-map.json
@@ -678,6 +678,7 @@
"src/db/activity_ledger.rs",
"src/db/feedback.rs",
"src/db/maintenance.rs",
+ "src/db/planner_stats_tests.rs",
"src/db/setup.rs",
"src/db/source_identity.rs",
"src/db/tests.rs",
@@ -778,6 +779,7 @@
"crate": "screenpipe-db",
"files": [
"tests/audio_duplicate_test.rs",
+ "tests/continuous_audio_recall_test.rs",
"tests/audio_search_speaker_join_test.rs",
"tests/audio_segment_search_test.rs",
"tests/chunk_outcome_test.rs",
@@ -1016,6 +1018,8 @@
"tests/dedup_benchmark/scenarios.rs",
"tests/dedup_benchmark/simulation.rs",
"tests/overlap_dedup_test.rs",
+ "tests/continuous_recall_test.rs",
+ "tests/continuous_recall_stress_test.rs",
"tests/speaker_identification.rs",
"tests/speaker_identity_gate_real_audio_test.rs",
"tests/speaker_identity_gate_test.rs"