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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(ci): race on Silero VAD download in parallel audio benchmark tests
Louis Beaumontd3a835ea3c96
diff --git a/crates/screenpipe-audio/src/vad/silero.rs b/crates/screenpipe-audio/src/vad/silero.rsindex 4b21102fd..6af26832c 100644--- a/crates/screenpipe-audio/src/vad/silero.rs+++ b/crates/screenpipe-audio/src/vad/silero.rs@@ -25,11 +25,38 @@ pub struct SileroVad {impl SileroVad {/// Pre-download the model file without initializing the VAD engine.- /// Safe to call from anywhere — uses atomic flag to prevent duplicate downloads.+ /// Non-blocking: kicks off the download and returns immediately with an+ /// error if it isn't ready yet. Uses an atomic flag to prevent duplicate+ /// downloads. Intended for the production audio loop, which retries on+ /// every frame anyway.pub async fn ensure_model_downloaded() -> anyhow::Result<PathBuf> {Self::get_or_download_model().await}+ /// Wait until the model is available on disk, downloading if necessary.+ /// Unlike `ensure_model_downloaded`, this blocks until the file is ready+ /// — safe to call from parallel tests or anywhere that needs the model+ /// synchronously. Polls every 200ms while a download is in flight.+ pub async fn ensure_model_available() -> anyhow::Result<PathBuf> {+ loop {+ match Self::get_or_download_model().await {+ Ok(path) => return Ok(path),+ Err(e) => {+ let msg = e.to_string();+ // These two errors mean "a download is in flight, come+ // back later". Any other error is fatal.+ if msg.contains("download already in progress")+ || msg.contains("not available yet")+ {+ tokio::time::sleep(std::time::Duration::from_millis(200)).await;+ continue;+ }+ return Err(e);+ }+ }+ }+ }+pub async fn new() -> anyhow::Result<Self> {debug!("Initializing SileroVad...");let model_path = Self::get_or_download_model().await?;diff --git a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/cross_device_benchmark.rs b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/cross_device_benchmark.rsindex 378a72364..a2fa7fa2b 100644--- a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/cross_device_benchmark.rs+++ b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/cross_device_benchmark.rs@@ -119,7 +119,7 @@ fn analyze_cross_device(async fn cross_device_coverage_synthetic() {println!("\n--- Cross-Device Coverage: Synthetic ---");- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;let duration = 120.0; // 2 minutes// Mic track: local speaker (clear) + silence during remote speech@@ -214,7 +214,7 @@ async fn cross_device_coverage_dataset() {println!("\n--- Cross-Device Coverage: Full Dataset ---");- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;let mut results_current = Vec::new();let mut results_proposed = Vec::new();diff --git a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/main.rs b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/main.rsindex f5d5f4cc5..310912ab3 100644--- a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/main.rs+++ b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/main.rs@@ -34,3 +34,19 @@ mod pipeline_benchmark;mod quality_regression;mod smart_mode_benchmark;mod vad_benchmark;++/// Construct a SileroVad after ensuring the model is fully downloaded.+/// Fixes a race in parallel test runs: `SileroVad::new()` on its own is+/// non-blocking — the first caller spawns the download and returns an+/// error, siblings see DOWNLOADING=true and error too. Here we poll until+/// the file is on disk, then construct. Safe to call from many tests+/// concurrently; only the first pays the download cost.+#[allow(dead_code)]+pub async fn new_test_vad() -> screenpipe_audio::vad::silero::SileroVad {+ screenpipe_audio::vad::silero::SileroVad::ensure_model_available()+ .await+ .expect("silero model prefetch failed");+ screenpipe_audio::vad::silero::SileroVad::new()+ .await+ .expect("failed to init SileroVad")+}diff --git a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/pipeline_benchmark.rs b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/pipeline_benchmark.rsindex 220a32bf9..d761e0ed3 100644--- a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/pipeline_benchmark.rs+++ b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/pipeline_benchmark.rs@@ -135,7 +135,7 @@ fn word_recall(ground_truth: &str, transcription: &str) -> f64 {async fn pipeline_end_to_end_synthetic() {println!("\n--- Pipeline End-to-End: Synthetic ---");- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;// 5-minute audio with varied speech patternslet duration = 300.0;@@ -397,7 +397,7 @@ async fn pipeline_end_to_end_dataset() {println!("\n--- Pipeline End-to-End: Full Dataset (VAD only) ---");- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;let thresholds = [0.01, 0.02, 0.03, 0.05, 0.10];diff --git a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/vad_benchmark.rs b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/vad_benchmark.rsindex b6eabd6e6..2245f1e85 100644--- a/crates/screenpipe-audio/tests/audio_pipeline_benchmark/vad_benchmark.rs+++ b/crates/screenpipe-audio/tests/audio_pipeline_benchmark/vad_benchmark.rs@@ -450,7 +450,7 @@ async fn vad_silero_integration() {println!(" VAD SILERO INTEGRATION TEST");println!("{}", "=".repeat(70));- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;// Test 1: Silence should not be detected as speechlet silence = audio_fixtures::silence(1.0);@@ -665,7 +665,7 @@ async fn chunk_duration_sweep_dataset() {println!(" {}", "─".repeat(62));for &chunk_dur in CHUNK_DURATIONS {- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;// Aggregate across all scenarios and channelslet mut total_speech_passed = 0usize;@@ -769,7 +769,7 @@ async fn vad_threshold_sweep_dataset() {println!(" VAD THRESHOLD SWEEP — FULL DATASET");println!("{}", "=".repeat(70));- let mut vad = SileroVad::new().await.expect("failed to init SileroVad");+ let mut vad = crate::new_test_vad().await;let mut all_results: Vec<VadSweepResult> = Vec::new();// Find all scenario directories