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: cover windows live audio recovery

louis03019581a3b9ad8402
diff --git a/.github/workflows/windows-integration-test.yml b/.github/workflows/windows-integration-test.yml
index 63fe55390..292aeba78 100644
--- a/.github/workflows/windows-integration-test.yml
+++ b/.github/workflows/windows-integration-test.yml
@@ -122,7 +122,7 @@ jobs:
AWS_LC_SYS_PREBUILT_NASM: "1"
run: cargo build --release -p screenpipe-engine --bin screenpipe --target x86_64-pc-windows-msvc
- - name: Run Windows live meeting audio regression
+ - name: Run Windows live meeting audio regressions
shell: pwsh
timeout-minutes: 10
env:
@@ -131,7 +131,11 @@ jobs:
ORT_LIB_LOCATION: ${{ github.workspace }}/apps/screenpipe-app-tauri/src-tauri/onnxruntime-win-x64-1.22.0
OPENBLAS_PATH: ${{ github.workspace }}/apps/screenpipe-app-tauri/src-tauri/openblas
AWS_LC_SYS_PREBUILT_NASM: "1"
- run: cargo test --release -p screenpipe-audio --lib windows_live_meeting_audio_tap_e2e --target x86_64-pc-windows-msvc -- --nocapture
+ run: |
+ cargo test --release -p screenpipe-audio --lib core::run_record_and_transcribe::tests --target x86_64-pc-windows-msvc -- --nocapture
+ cargo test --release -p screenpipe-audio --lib detects_windows_builtin_mics_as_wired --target x86_64-pc-windows-msvc -- --nocapture
+ cargo test --release -p screenpipe-audio --lib live_ready_session_suppresses_background_recording --target x86_64-pc-windows-msvc -- --nocapture
+ cargo test --release -p screenpipe-audio --lib live_not_ready_session_keeps_background_recording_enabled --target x86_64-pc-windows-msvc -- --nocapture
- name: Run CLI and generate activity
shell: pwsh
diff --git a/crates/screenpipe-audio/src/core/device_detection.rs b/crates/screenpipe-audio/src/core/device_detection.rs
index 602afb825..f3f3ccc4a 100644
--- a/crates/screenpipe-audio/src/core/device_detection.rs
+++ b/crates/screenpipe-audio/src/core/device_detection.rs
@@ -98,10 +98,16 @@ impl InputDeviceKind {
let wired = [
"built-in",
"internal",
+ "integrated microphone",
+ "microphone array",
"macbook",
"imac",
"hdmi",
"displayport",
+ "realtek",
+ "intel",
+ "smart sound",
+ "high definition audio",
"usb",
];
if wired.iter().any(|p| lower.contains(p)) {
@@ -211,6 +217,20 @@ mod tests {
);
}
+ #[test]
+ fn detects_windows_builtin_mics_as_wired() {
+ assert_eq!(
+ InputDeviceKind::detect(
+ "Microphone Array (Intel® Smart Sound Technology for Digital Microphones)"
+ ),
+ InputDeviceKind::Wired
+ );
+ assert_eq!(
+ InputDeviceKind::detect("Microphone (Realtek(R) Audio)"),
+ InputDeviceKind::Wired
+ );
+ }
+
#[test]
fn unknown_is_conservative() {
let kind = InputDeviceKind::detect("Some Unknown Mic 3000");
diff --git a/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs b/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs
index f2c3f6cdc..5c5c14b36 100644
--- a/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs
+++ b/crates/screenpipe-audio/src/core/run_record_and_transcribe.rs
@@ -85,6 +85,41 @@ fn is_silent_buffer(chunk: &[f32]) -> bool {
!chunk.is_empty() && chunk.iter().all(|s| s.abs() < SILENT_BUFFER_PEAK_THRESHOLD)
}
+#[cfg(target_os = "windows")]
+fn zero_fill_reconnect_enabled_for_platform() -> bool {
+ // WASAPI input devices, especially built-in Intel/Realtek microphone
+ // arrays, can emit exact-zero buffers during ordinary quiet periods.
+ // Treating that as fatal causes reconnect churn and creates avoidable
+ // capture gaps. A real dead Windows stream is still caught by the
+ // receive-timeout path when callbacks stop arriving.
+ false
+}
+
+#[cfg(not(target_os = "windows"))]
+fn zero_fill_reconnect_enabled_for_platform() -> bool {
+ true
+}
+
+fn should_reconnect_after_silent_input(
+ device_type: &DeviceType,
+ stream_elapsed: Duration,
+ last_non_zero_elapsed: Duration,
+) -> bool {
+ if *device_type != DeviceType::Input {
+ return false;
+ }
+
+ if stream_elapsed.as_secs() < STREAM_STARTUP_GRACE_SECS {
+ return false;
+ }
+
+ if last_non_zero_elapsed.as_secs() < INPUT_SILENT_BUFFER_TIMEOUT_SECS {
+ return false;
+ }
+
+ zero_fill_reconnect_enabled_for_platform()
+}
+
fn meeting_frame_from_recorder_output(
samples: Vec<f32>,
audio_stream: &AudioStream,
@@ -325,10 +360,11 @@ async fn recv_audio_chunk(
// and went silent. Input devices only; output devices
// legitimately go silent when nothing is playing.
if let Some(last_seen) = *last_non_zero_at {
- if audio_stream.device.device_type == DeviceType::Input
- && stream_start.elapsed().as_secs() >= STREAM_STARTUP_GRACE_SECS
- && last_seen.elapsed().as_secs() >= INPUT_SILENT_BUFFER_TIMEOUT_SECS
- {
+ if should_reconnect_after_silent_input(
+ &audio_stream.device.device_type,
+ stream_start.elapsed(),
+ last_seen.elapsed(),
+ ) {
warn!(
"no usable audio from {} for {}s — only zero-fill buffers \
(likely OS device hijack by another app), triggering reconnect",
@@ -503,6 +539,44 @@ mod tests {
assert_eq!(frame.samples.as_ref(), &samples);
}
+ #[test]
+ fn output_silent_buffers_do_not_trigger_input_reconnect_watchdog() {
+ assert!(!should_reconnect_after_silent_input(
+ &DeviceType::Output,
+ Duration::from_secs(STREAM_STARTUP_GRACE_SECS + 1),
+ Duration::from_secs(INPUT_SILENT_BUFFER_TIMEOUT_SECS + 1)
+ ));
+ }
+
+ #[test]
+ fn startup_grace_blocks_silent_input_reconnect_watchdog() {
+ assert!(!should_reconnect_after_silent_input(
+ &DeviceType::Input,
+ Duration::from_secs(STREAM_STARTUP_GRACE_SECS - 1),
+ Duration::from_secs(INPUT_SILENT_BUFFER_TIMEOUT_SECS + 1)
+ ));
+ }
+
+ #[cfg(target_os = "windows")]
+ #[test]
+ fn windows_sustained_zero_fill_is_treated_as_silence_not_disconnect() {
+ assert!(!should_reconnect_after_silent_input(
+ &DeviceType::Input,
+ Duration::from_secs(STREAM_STARTUP_GRACE_SECS + 1),
+ Duration::from_secs(INPUT_SILENT_BUFFER_TIMEOUT_SECS + 1)
+ ));
+ }
+
+ #[cfg(not(target_os = "windows"))]
+ #[test]
+ fn non_windows_sustained_zero_fill_still_triggers_reconnect() {
+ assert!(should_reconnect_after_silent_input(
+ &DeviceType::Input,
+ Duration::from_secs(STREAM_STARTUP_GRACE_SECS + 1),
+ Duration::from_secs(INPUT_SILENT_BUFFER_TIMEOUT_SECS + 1)
+ ));
+ }
+
#[cfg(target_os = "windows")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn windows_live_meeting_audio_tap_e2e_uses_background_recorder_shape() {
@@ -589,4 +663,96 @@ mod tests {
.expect("pipeline task");
pipeline_result.expect("pipeline result");
}
+
+ #[cfg(target_os = "windows")]
+ #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+ async fn windows_recorder_e2e_keeps_running_after_zero_fill_input() {
+ let sample_rate = 16_000_u32;
+ let chunk_samples = 320_usize;
+ let device = Arc::new(AudioDevice::new(
+ "Microphone Array (Intel Smart Sound Technology for Digital Microphones)".to_string(),
+ DeviceType::Input,
+ ));
+ let (audio_stream, tx) = AudioStream::from_sender_for_test(device, sample_rate, 2);
+ let audio_stream = Arc::new(audio_stream);
+ let (whisper_tx, whisper_rx) = crossbeam::channel::bounded::<AudioInput>(8);
+ let is_running = Arc::new(AtomicBool::new(true));
+ let metrics = Arc::new(AudioPipelineMetrics::new());
+
+ let pipeline = tokio::spawn({
+ let audio_stream = audio_stream.clone();
+ let whisper_tx = Arc::new(whisper_tx);
+ let is_running = is_running.clone();
+ let metrics = metrics.clone();
+ async move {
+ run_record_and_transcribe(
+ audio_stream,
+ Duration::from_secs(1),
+ whisper_tx,
+ is_running,
+ metrics,
+ None,
+ )
+ .await
+ }
+ });
+
+ tokio::time::sleep(Duration::from_millis(50)).await;
+ for chunk_index in 0..170 {
+ let chunk = (0..chunk_samples)
+ .map(|sample_index| {
+ let n = chunk_index * chunk_samples + sample_index;
+ ((n as f32 / sample_rate as f32) * 440.0 * std::f32::consts::TAU).sin() * 0.2
+ })
+ .collect::<Vec<f32>>();
+ tx.send(chunk).expect("send simulated speech chunk");
+ }
+
+ let speech_segment = tokio::task::spawn_blocking({
+ let whisper_rx = whisper_rx.clone();
+ move || whisper_rx.recv_timeout(Duration::from_secs(2))
+ })
+ .await
+ .expect("speech receiver task")
+ .expect("speech segment");
+ assert_eq!(speech_segment.channels, 1);
+ assert_eq!(speech_segment.sample_rate, sample_rate);
+ assert!(!speech_segment.data.is_empty());
+
+ for _ in 0..400 {
+ tx.send(vec![0.0; chunk_samples])
+ .expect("send simulated zero-fill chunk");
+ }
+
+ let mut saw_zero_fill_in_segment = false;
+ for _ in 0..5 {
+ let segment = tokio::task::spawn_blocking({
+ let whisper_rx = whisper_rx.clone();
+ move || whisper_rx.recv_timeout(Duration::from_secs(2))
+ })
+ .await
+ .expect("zero-fill receiver task")
+ .expect("zero-fill segment");
+ assert_eq!(segment.channels, 1);
+ assert_eq!(segment.sample_rate, sample_rate);
+ saw_zero_fill_in_segment |= segment
+ .data
+ .iter()
+ .any(|sample| sample.abs() < SILENT_BUFFER_PEAK_THRESHOLD);
+ if saw_zero_fill_in_segment {
+ break;
+ }
+ }
+ assert!(saw_zero_fill_in_segment);
+ assert!(!audio_stream.is_disconnected());
+ assert_eq!(metrics.stream_timeouts.load(Ordering::Relaxed), 0);
+
+ is_running.store(false, Ordering::Relaxed);
+ tx.send(vec![0.1; chunk_samples]).ok();
+ let pipeline_result = tokio::time::timeout(Duration::from_secs(5), pipeline)
+ .await
+ .expect("pipeline shutdown timeout")
+ .expect("pipeline task");
+ pipeline_result.expect("pipeline result");
+ }
}
diff --git a/crates/screenpipe-audio/src/meeting_streaming/controller.rs b/crates/screenpipe-audio/src/meeting_streaming/controller.rs
index bd403c1d0..eec56246c 100644
--- a/crates/screenpipe-audio/src/meeting_streaming/controller.rs
+++ b/crates/screenpipe-audio/src/meeting_streaming/controller.rs
@@ -670,6 +670,67 @@ mod tests {
}
}
+ fn test_audio_tap() -> MeetingAudioTap {
+ let (tx, _) = broadcast::channel(8);
+ MeetingAudioTap::new(tx, Arc::new(std::sync::atomic::AtomicBool::new(false)))
+ }
+
+ #[tokio::test]
+ async fn live_ready_session_suppresses_background_recording() {
+ let audio_tap = test_audio_tap();
+ let transcription_engine = Arc::new(RwLock::new(None));
+ let mut active = None;
+ let config = MeetingStreamingConfig::from_settings(
+ true,
+ "screenpipe-cloud",
+ Some("cloud-token".to_string()),
+ None,
+ None,
+ None,
+ );
+
+ start_streaming_session(
+ &config,
+ &audio_tap,
+ &transcription_engine,
+ &mut active,
+ 7,
+ Some("manual".to_string()),
+ None,
+ )
+ .await;
+
+ let session = active.expect("active live session");
+ assert!(session.live_transcription_enabled);
+ assert!(audio_tap.is_active());
+ assert!(audio_tap.background_suppressed());
+ }
+
+ #[tokio::test]
+ async fn live_not_ready_session_keeps_background_recording_enabled() {
+ let audio_tap = test_audio_tap();
+ let transcription_engine = Arc::new(RwLock::new(None));
+ let mut active = None;
+ let config =
+ MeetingStreamingConfig::from_settings(true, "screenpipe-cloud", None, None, None, None);
+
+ start_streaming_session(
+ &config,
+ &audio_tap,
+ &transcription_engine,
+ &mut active,
+ 8,
+ Some("manual".to_string()),
+ None,
+ )
+ .await;
+
+ let session = active.expect("active fallback session");
+ assert!(!session.live_transcription_enabled);
+ assert!(!audio_tap.is_active());
+ assert!(!audio_tap.background_suppressed());
+ }
+
#[test]
fn inactive_live_session_requests_auto_end_after_timeout() {
let now = Instant::now();