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

test(audio): isolate process-wide reconciliation guards

Ezra Ellette86eca0b4d40a
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rs
index a313db1b3..7948579e2 100644
--- a/crates/screenpipe-audio/src/audio_manager/manager.rs
+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs
@@ -2663,6 +2663,9 @@ mod tests {
#[tokio::test]
async fn pending_cloud_audio_recovers_in_both_modes_after_failure_and_restart() {
+ let _reconciliation = super::super::reconciliation::RECONCILIATION_TEST_LOCK
+ .lock()
+ .await;
use crate::transcription::deepgram::DeepgramTranscriptionConfig;
use crate::utils::ffmpeg::write_audio_to_file;
use wiremock::{matchers::method, Mock, MockServer, ResponseTemplate};
@@ -2768,6 +2771,7 @@ mod tests {
.mount(&server).await;
// Restart the worker against the same durable pending records.
let worker = manager.start_reconciliation_handler().await;
+ let cancellation = worker.abort_handle();
*manager.reconciliation_handle.write().await = Some(worker);
manager.reconciliation_wakeup.notify_one();
tokio::time::timeout(Duration::from_secs(10), async {
@@ -2797,6 +2801,13 @@ mod tests {
.await
.unwrap();
manager.stop_internal().await.unwrap();
+ tokio::time::timeout(Duration::from_secs(10), async {
+ while !cancellation.is_finished() {
+ tokio::task::yield_now().await;
+ }
+ })
+ .await
+ .expect("restarted recovery must stop before releasing the test lock");
assert_eq!(db.count_audio_transcriptions(id).await.unwrap(), 1);
assert_eq!(std::fs::read(&path).unwrap(), retained);
assert!(fresh.exists());
diff --git a/crates/screenpipe-audio/src/audio_manager/reconciliation.rs b/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
index e310fdf1f..d57a00114 100644
--- a/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
+++ b/crates/screenpipe-audio/src/audio_manager/reconciliation.rs
@@ -20,6 +20,11 @@ use tracing::{debug, error, info, warn};
/// Global lock to prevent concurrent reconciliation runs (batch mode + background sweep).
/// Two simultaneous Whisper sessions will use 200%+ CPU and starve the system.
static RECONCILIATION_RUNNING: AtomicBool = AtomicBool::new(false);
+// Independent test databases still share the production process-wide guard.
+// Serialize tests that run sweeps so neither can skip the other's recovery.
+#[cfg(test)]
+pub(super) static RECONCILIATION_TEST_LOCK: tokio::sync::Mutex<()> =
+ tokio::sync::Mutex::const_new(());
static BACKFILL_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
static BACKFILL_LAST_TRIGGERED_MS: AtomicU64 = AtomicU64::new(0);
@@ -1842,6 +1847,7 @@ mod tests {
#[tokio::test]
async fn disabled_runtime_keeps_pending_audio_even_when_an_engine_is_configured() {
+ let _reconciliation = RECONCILIATION_TEST_LOCK.lock().await;
let dir = tempfile::tempdir().unwrap();
let db = temp_db(dir.path()).await;
let path = dir.path().join("Mic (input)_2026-09-23_10-00-00.mp4");
@@ -2411,6 +2417,7 @@ mod tests {
#[tokio::test]
async fn completed_batch_is_not_retranscribed_or_remerged_after_save_failure() {
+ let _reconciliation = RECONCILIATION_TEST_LOCK.lock().await;
let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::WARN)
.with_test_writer()
@@ -2990,6 +2997,7 @@ mod tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore = "real-model full reconciliation memory plateau regression"]
async fn cached_parakeet_mlx_post_meeting_backlog_memory_plateaus() {
+ let _reconciliation = RECONCILIATION_TEST_LOCK.lock().await;
const MODEL_REPO: &str = "mlx-community/parakeet-tdt-0.6b-v3";
const WARMUP_CALLS: usize = 4;
// Mirrors the v2.5.151 incident: four immediately-drained capped sweeps