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: meeting detection thrash — 3 fixes to prevent false positives
Louis Beaumonte74ed1c5a01f
diff --git a/Cargo.lock b/Cargo.lockindex e8670689f..9930be515 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5388,7 +5388,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.154"+version = "0.3.155"dependencies = ["anyhow","bytemuck",@@ -5444,7 +5444,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.154"+version = "0.3.155"dependencies = ["accessibility","accessibility-sys",@@ -5485,7 +5485,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.154"+version = "0.3.155"dependencies = ["anyhow","chrono",@@ -5510,7 +5510,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.154"+version = "0.3.155"dependencies = ["anyhow","chrono",@@ -5528,7 +5528,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.154"+version = "0.3.155"dependencies = ["anyhow","chrono",@@ -5548,7 +5548,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.154"+version = "0.3.155"dependencies = ["anyhow","async-trait",@@ -5607,7 +5607,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.154"+version = "0.3.155"dependencies = ["accessibility-sys","anyhow",diff --git a/Cargo.toml b/Cargo.tomlindex e51283bbb..da09f593d 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -6,7 +6,7 @@ exclude = ["apps/screenpipe-app-tauri/src-tauri"]resolver = "2"[workspace.package]-version = "0.3.155"+version = "0.3.156"authors = ["louis030195 <[email protected]>"]description = ""repository = "https://github.com/screenpipe/screenpipe"diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 03e4cd02f..491e2a180 100755--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -8097,7 +8097,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.0.542"+version = "2.0.543"dependencies = ["anyhow","arboard",@@ -8192,7 +8192,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.155"+version = "0.3.156"dependencies = ["anyhow","bytemuck",@@ -8243,7 +8243,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.155"+version = "0.3.156"dependencies = ["accessibility","accessibility-sys",@@ -8284,7 +8284,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.155"+version = "0.3.156"dependencies = ["anyhow","chrono",@@ -8309,7 +8309,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.155"+version = "0.3.156"dependencies = ["anyhow","chrono",@@ -8325,7 +8325,7 @@ dependencies = [[[package]]name = "screenpipe-integrations"-version = "0.3.155"+version = "0.3.156"dependencies = ["anyhow","chrono",@@ -8345,7 +8345,7 @@ dependencies = [[[package]]name = "screenpipe-server"-version = "0.3.155"+version = "0.3.156"dependencies = ["anyhow","async-trait",@@ -8400,7 +8400,7 @@ dependencies = [[[package]]name = "screenpipe-vision"-version = "0.3.155"+version = "0.3.156"dependencies = ["accessibility-sys","anyhow",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 5199eb13f..bfb221c5a 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "2.0.542"+version = "2.0.543"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rsindex a6c07222d..e81c32729 100644--- a/crates/screenpipe-audio/src/audio_manager/manager.rs+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs@@ -417,7 +417,7 @@ impl AudioManager {let sum_sq: f32 = audio.data.iter().map(|&x| x * x).sum();(sum_sq / audio.data.len() as f32).sqrt()};- meeting.on_audio_activity(&audio.device.device_type, rms > 0.01);+ meeting.on_audio_activity(&audio.device.device_type, rms > 0.05);}// Smart mode: defer Whisper during meetings, then check CPU idlediff --git a/crates/screenpipe-audio/src/meeting_detector.rs b/crates/screenpipe-audio/src/meeting_detector.rsindex 6555bcddb..a5e36e3bd 100644--- a/crates/screenpipe-audio/src/meeting_detector.rs+++ b/crates/screenpipe-audio/src/meeting_detector.rs@@ -18,12 +18,26 @@ const MEETING_GRACE_PERIOD: Duration = Duration::from_secs(60);/// have had speech within this window, we consider the user to be on a call.const AUDIO_CALL_DETECTION_WINDOW: Duration = Duration::from_secs(45);+/// Cooldown after an audio-based meeting ends before audio detection can trigger again.+/// Prevents the feedback loop: meeting expires → process one chunk → new audio →+/// meeting re-triggers → repeat every 45s indefinitely.+const AUDIO_MEETING_COOLDOWN: Duration = Duration::from_secs(120);++/// How recently app-based detection must have been active for audio-based detection+/// to also trigger. Audio detection acts as a meeting *extender* (user tabbed away+/// from Google Meet but is still on the call), not a standalone detector.+const APP_CONFIRMATION_WINDOW: Duration = Duration::from_secs(300); // 5 minutes+/// Detects when the user is in a meeting by matching focused app names/// and browser window titles against known meeting apps/URLs.////// Uses a grace period: once a meeting is detected, it stays "in meeting" for/// [`MEETING_GRACE_PERIOD`] after the user switches away from the meeting app./// This handles the common case of briefly alt-tabbing during a call.+///+/// Audio-based detection (bidirectional speech on mic + speakers) only activates+/// when app-based detection has been active recently — it extends a meeting,+/// not starts one. This prevents false positives from YouTube + background noise.pub struct MeetingDetector {/// Lowercase app names that are always considered meetingsmeeting_apps: HashSet<String>,@@ -39,6 +53,14 @@ pub struct MeetingDetector {last_input_speech_ts: AtomicI64,/// Epoch millis of last detected speech on an output (speaker) devicelast_output_speech_ts: AtomicI64,+ /// Epoch millis when the last audio-based meeting ended (for cooldown)+ last_audio_meeting_ended_ts: AtomicI64,+ /// Whether the previous call to is_bidirectional_audio_active() returned true+ /// (used to detect the true→false transition for cooldown)+ was_audio_meeting: AtomicBool,+ /// Epoch millis when an app-based meeting was last detected (lock-free mirror+ /// of MeetingState::last_app_meeting_ts for use in is_in_meeting)+ last_app_meeting_epoch_ms: AtomicI64,}struct MeetingState {@@ -48,6 +70,9 @@ struct MeetingState {last_meeting_focus: Option<Instant>,/// Whether the meeting app is *currently* focused (no grace period)directly_focused: bool,+ /// When an app-based meeting was last active (even after grace period expired).+ /// Used by audio-based detection to decide if it should activate.+ last_app_meeting_ts: Option<Instant>,}impl Default for MeetingDetector {@@ -111,9 +136,13 @@ impl MeetingDetector {current_app: None,last_meeting_focus: None,directly_focused: false,+ last_app_meeting_ts: None,}),last_input_speech_ts: AtomicI64::new(0),last_output_speech_ts: AtomicI64::new(0),+ last_audio_meeting_ended_ts: AtomicI64::new(0),+ was_audio_meeting: AtomicBool::new(false),+ last_app_meeting_epoch_ms: AtomicI64::new(0),}}@@ -130,6 +159,9 @@ impl MeetingDetector {let was_in_meeting = state.directly_focused;state.directly_focused = true;state.last_meeting_focus = Some(Instant::now());+ state.last_app_meeting_ts = Some(Instant::now());+ self.last_app_meeting_epoch_ms+ .store(now_millis(), Ordering::Relaxed);state.current_app = Some(if let Some(pattern) = self.matching_browser_pattern(&app_lower, window_title) {format!("{} ({})", app_name, pattern)@@ -156,6 +188,8 @@ impl MeetingDetector {self.in_meeting.store(false, Ordering::Relaxed);state.current_app = None;state.last_meeting_focus = None;+ // Note: last_app_meeting_ts is NOT cleared — it persists for+ // audio-based detection to use within APP_CONFIRMATION_WINDOW}// else: still within grace period, keep in_meeting=true} else {@@ -200,17 +234,48 @@ impl MeetingDetector {}}- /// Returns whether a meeting is currently detected (atomic, lock-free).- /// Combines app-based detection (window/app matching) with audio-based- /// detection (bidirectional speech on input + output devices).+ /// Returns whether a meeting is currently detected (atomic, lock-free for app path).+ ///+ /// App-based detection always works standalone. Audio-based detection only+ /// activates when app-based detection was active within the last 5 minutes+ /// (it *extends* a meeting, e.g. user tabbed away from Google Meet).+ /// Audio-based detection also has a cooldown to prevent oscillation.pub fn is_in_meeting(&self) -> bool {- self.in_meeting.load(Ordering::Relaxed) || self.is_bidirectional_audio_active()+ let app_meeting = self.in_meeting.load(Ordering::Relaxed);+ if app_meeting {+ return true;+ }++ // Fix 3: audio-based detection requires recent app-based meeting+ let has_recent_app = self.had_recent_app_meeting_atomic();+ let audio_active = has_recent_app && self.is_bidirectional_audio_active();++ // Track transition from active → inactive for cooldown (Fix 2)+ let was_active = self.was_audio_meeting.load(Ordering::Relaxed);+ if was_active && !audio_active {+ // Audio meeting just ended — record cooldown start+ self.last_audio_meeting_ended_ts+ .store(now_millis(), Ordering::Relaxed);+ self.was_audio_meeting.store(false, Ordering::Relaxed);+ } else if audio_active && !was_active {+ self.was_audio_meeting.store(true, Ordering::Relaxed);+ }++ audio_active}/// Returns true if both input and output devices have had speech- /// within the [`AUDIO_CALL_DETECTION_WINDOW`].+ /// within the [`AUDIO_CALL_DETECTION_WINDOW`], AND app-based detection+ /// was recently active, AND we're not in cooldown.fn is_bidirectional_audio_active(&self) -> bool {let now = now_millis();++ // Check cooldown: if an audio-based meeting ended recently, don't re-trigger+ let last_ended = self.last_audio_meeting_ended_ts.load(Ordering::Relaxed);+ if last_ended > 0 && (now - last_ended) < AUDIO_MEETING_COOLDOWN.as_millis() as i64 {+ return false;+ }+let window = AUDIO_CALL_DETECTION_WINDOW.as_millis() as i64;let last_input = self.last_input_speech_ts.load(Ordering::Relaxed);let last_output = self.last_output_speech_ts.load(Ordering::Relaxed);@@ -220,9 +285,39 @@ impl MeetingDetector {&& (now - last_output) < window}+ /// Check if app-based detection was active recently enough to allow+ /// audio-based detection. Lock-free using atomic epoch millis.+ fn had_recent_app_meeting_atomic(&self) -> bool {+ // Currently in an app-based meeting+ if self.in_meeting.load(Ordering::Relaxed) {+ return true;+ }+ // Was in an app-based meeting recently+ let last_app_ms = self.last_app_meeting_epoch_ms.load(Ordering::Relaxed);+ if last_app_ms > 0 {+ let now = now_millis();+ return (now - last_app_ms) < APP_CONFIRMATION_WINDOW.as_millis() as i64;+ }+ false+ }+/// Returns the current meeting app name, if any.+ /// For audio-based detection (when user tabbed away from meeting app),+ /// returns the last known meeting app.pub async fn current_meeting_app(&self) -> Option<String> {- self.state.read().await.current_app.clone()+ let state = self.state.read().await;+ if state.current_app.is_some() {+ return state.current_app.clone();+ }+ // If audio-based detection is active, report what meeting app was last used+ if self.is_bidirectional_audio_active() {+ if let Some(last_ts) = state.last_app_meeting_ts {+ if last_ts.elapsed() < APP_CONFIRMATION_WINDOW {+ return Some("audio (recent meeting app)".to_string());+ }+ }+ }+ None}fn is_meeting_app(&self, app_lower: &str, window_title: Option<&str>) -> bool {@@ -261,6 +356,10 @@ fn now_millis() -> i64 {mod tests {use super::*;+ // ──────────────────────────────────────────────────────────+ // App-based detection (unchanged behavior)+ // ──────────────────────────────────────────────────────────+#[tokio::test]async fn test_direct_app_detection() {let detector = MeetingDetector::new();@@ -405,15 +504,87 @@ mod tests {}#[tokio::test]- async fn test_bidirectional_audio_triggers_meeting() {+ async fn test_app_based_still_works_alone() {let detector = MeetingDetector::new();- // Both input and output have speech → call detected+ // App-based detection should work without any audio activity+ detector.on_app_switch("zoom.us", None).await;+ assert!(+ detector.is_in_meeting(),+ "app-based detection should still work independently"+ );+ // Audio timestamps should remain at 0+ assert_eq!(detector.last_input_speech_ts.load(Ordering::Relaxed), 0);+ assert_eq!(detector.last_output_speech_ts.load(Ordering::Relaxed), 0);+ }++ // ──────────────────────────────────────────────────────────+ // Audio-based detection: requires recent app confirmation (Fix 3)+ // ──────────────────────────────────────────────────────────++ #[tokio::test]+ async fn test_bidirectional_audio_alone_does_not_trigger() {+ // Fix 3: bidirectional audio WITHOUT recent app meeting should NOT trigger+ let detector = MeetingDetector::new();++ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "bidirectional audio alone should NOT trigger without recent app meeting"+ );+ }++ #[tokio::test]+ async fn test_bidirectional_audio_with_recent_app_triggers() {+ // Fix 3: bidirectional audio WITH recent app meeting SHOULD trigger+ let detector = MeetingDetector::new();++ // First: user was in a meeting app+ detector+ .on_app_switch("Arc", Some("call - meet.google.com/abc"))+ .await;+ assert!(detector.is_in_meeting());++ // Then: user tabs away and grace period expires+ detector.on_app_switch("Finder", None).await;+ {+ let mut state = detector.state.write().await;+ state.last_meeting_focus =+ Some(Instant::now() - MEETING_GRACE_PERIOD - Duration::from_secs(1));+ }+ detector.check_grace_period().await;+ // App-based meeting ended, but last_app_meeting_ts is still recent+ assert!(+ !detector.in_meeting.load(Ordering::Relaxed),+ "app-based meeting should have ended"+ );++ // Now bidirectional audio should extend the meetingdetector.on_audio_activity(&DeviceType::Input, true);detector.on_audio_activity(&DeviceType::Output, true);assert!(detector.is_in_meeting(),- "bidirectional audio should trigger meeting detection"+ "bidirectional audio should extend meeting when app was recent"+ );+ }++ #[tokio::test]+ async fn test_bidirectional_audio_with_stale_app_does_not_trigger() {+ // Fix 3: if the app meeting was too long ago, audio should not trigger+ let detector = MeetingDetector::new();++ // Simulate an app meeting that happened a long time ago+ let stale_ts = now_millis() - APP_CONFIRMATION_WINDOW.as_millis() as i64 - 1000;+ detector+ .last_app_meeting_epoch_ms+ .store(stale_ts, Ordering::Relaxed);++ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "bidirectional audio should NOT trigger when app meeting was too long ago");}@@ -460,29 +631,263 @@ mod tests {}#[tokio::test]- async fn test_app_based_still_works_alone() {+ async fn test_has_speech_false_does_not_update() {let detector = MeetingDetector::new();- // App-based detection should work without any audio activity+ // Calling with has_speech=false should NOT update timestamps+ detector.on_audio_activity(&DeviceType::Input, false);+ detector.on_audio_activity(&DeviceType::Output, false);+ assert_eq!(detector.last_input_speech_ts.load(Ordering::Relaxed), 0);+ assert_eq!(detector.last_output_speech_ts.load(Ordering::Relaxed), 0);+ assert!(!detector.is_in_meeting());+ }++ // ──────────────────────────────────────────────────────────+ // Cooldown after audio-based meeting ends (Fix 2)+ // ──────────────────────────────────────────────────────────++ #[tokio::test]+ async fn test_audio_cooldown_prevents_retrigger() {+ // Fix 2: after audio meeting ends, cooldown prevents immediate re-trigger+ let detector = MeetingDetector::new();++ // Set up a recent app meeting so audio detection is allowed (Fix 3)+ detector.last_app_meeting_epoch_ms+ .store(now_millis(), Ordering::Relaxed);++ // Simulate audio meeting start+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(detector.is_in_meeting(), "audio meeting should be active");++ // Simulate audio meeting end (timestamps expire)+ let expired_ts = now_millis() - AUDIO_CALL_DETECTION_WINDOW.as_millis() as i64 - 1000;+ detector+ .last_input_speech_ts+ .store(expired_ts, Ordering::Relaxed);+ detector+ .last_output_speech_ts+ .store(expired_ts, Ordering::Relaxed);++ // This call transitions from active→inactive, starting cooldown+ assert!(+ !detector.is_in_meeting(),+ "audio meeting should have ended"+ );++ // Now new speech arrives — should NOT re-trigger due to cooldown+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "audio meeting should NOT re-trigger during cooldown"+ );+ }++ #[tokio::test]+ async fn test_audio_cooldown_expires_allows_retrigger() {+ // Fix 2: after cooldown expires, audio detection can trigger again+ let detector = MeetingDetector::new();++ // Set up a recent app meeting so audio detection is allowed (Fix 3)+ detector+ .last_app_meeting_epoch_ms+ .store(now_millis(), Ordering::Relaxed);++ // Simulate a cooldown that already expired+ let expired_cooldown =+ now_millis() - AUDIO_MEETING_COOLDOWN.as_millis() as i64 - 1000;+ detector+ .last_audio_meeting_ended_ts+ .store(expired_cooldown, Ordering::Relaxed);++ // New speech should trigger meeting again+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ detector.is_in_meeting(),+ "audio meeting should trigger after cooldown expires"+ );+ }++ #[tokio::test]+ async fn test_app_meeting_not_affected_by_audio_cooldown() {+ // Fix 2: cooldown should NOT affect app-based meeting detection+ let detector = MeetingDetector::new();++ // Simulate active cooldown+ detector+ .last_audio_meeting_ended_ts+ .store(now_millis(), Ordering::Relaxed);++ // App-based meeting should still workdetector.on_app_switch("zoom.us", None).await;assert!(detector.is_in_meeting(),- "app-based detection should still work independently"+ "app-based meeting should work during audio cooldown");- // Audio timestamps should remain at 0- assert_eq!(detector.last_input_speech_ts.load(Ordering::Relaxed), 0);- assert_eq!(detector.last_output_speech_ts.load(Ordering::Relaxed), 0);}+ // ──────────────────────────────────────────────────────────+ // Feedback loop prevention (Fixes 2+3 combined)+ // ──────────────────────────────────────────────────────────+#[tokio::test]- async fn test_has_speech_false_does_not_update() {+ async fn test_youtube_plus_mic_noise_no_meeting() {+ // The main false positive scenario: YouTube playing + mic background noise+ // Should NOT trigger meeting without any meeting app being focusedlet detector = MeetingDetector::new();- // Calling with has_speech=false should NOT update timestamps- detector.on_audio_activity(&DeviceType::Input, false);- detector.on_audio_activity(&DeviceType::Output, false);- assert_eq!(detector.last_input_speech_ts.load(Ordering::Relaxed), 0);- assert_eq!(detector.last_output_speech_ts.load(Ordering::Relaxed), 0);- assert!(!detector.is_in_meeting());+ // No meeting app ever focused — simulate normal desktop usage+ detector.on_app_switch("Arc", Some("YouTube - Watch cool video")).await;++ // Both input and output have "speech" (really just noise)+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);++ assert!(+ !detector.is_in_meeting(),+ "YouTube + mic noise should NOT trigger meeting detection"+ );+ assert_eq!(+ detector.current_meeting_app().await,+ None,+ "should not report any meeting app"+ );+ }++ #[tokio::test]+ async fn test_oscillation_prevented() {+ // Simulate the exact bug scenario: audio meeting oscillates on/off+ let detector = MeetingDetector::new();++ // Set up: user was in a Google Meet call recently+ detector+ .last_app_meeting_epoch_ms+ .store(now_millis(), Ordering::Relaxed);++ // Round 1: audio meeting triggers+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(detector.is_in_meeting(), "round 1: should be in meeting");++ // Round 1: audio meeting expires (45s pass)+ let expired = now_millis() - AUDIO_CALL_DETECTION_WINDOW.as_millis() as i64 - 1000;+ detector.last_input_speech_ts.store(expired, Ordering::Relaxed);+ detector.last_output_speech_ts.store(expired, Ordering::Relaxed);+ assert!(!detector.is_in_meeting(), "round 1: meeting should end");++ // Round 2: new audio arrives immediately — should be blocked by cooldown+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "round 2: should NOT re-trigger due to cooldown (was oscillating before fix)"+ );++ // Round 3: simulate even more audio — still blocked+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "round 3: cooldown should still prevent re-trigger"+ );+ }++ #[tokio::test]+ async fn test_real_meeting_flow_end_to_end() {+ // Full realistic scenario:+ // 1. User joins Google Meet in Arc browser+ // 2. Tabs away to VS Code+ // 3. App grace period expires+ // 4. Audio detection extends meeting (both sides talking)+ // 5. Audio expires → cooldown starts+ // 6. New audio during cooldown → blocked+ let detector = MeetingDetector::new();++ // Step 1: Join Google Meet+ detector+ .on_app_switch("Arc", Some("Team standup - meet.google.com/abc-xyz"))+ .await;+ assert!(detector.is_in_meeting());+ assert!(detector+ .current_meeting_app()+ .await+ .unwrap()+ .contains("meet.google.com"));++ // Step 2: Tab to VS Code+ detector+ .on_app_switch("Visual Studio Code", None)+ .await;+ assert!(+ detector.is_in_meeting(),+ "grace period should keep meeting active"+ );++ // Step 3: Grace period expires+ {+ let mut state = detector.state.write().await;+ state.last_meeting_focus =+ Some(Instant::now() - MEETING_GRACE_PERIOD - Duration::from_secs(1));+ }+ detector.check_grace_period().await;+ assert!(+ !detector.in_meeting.load(Ordering::Relaxed),+ "app-based meeting should have ended"+ );++ // Step 4: Bidirectional audio extends meeting+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ detector.is_in_meeting(),+ "audio should extend meeting (app was recent)"+ );++ // Step 5: Audio expires+ let expired = now_millis() - AUDIO_CALL_DETECTION_WINDOW.as_millis() as i64 - 1000;+ detector.last_input_speech_ts.store(expired, Ordering::Relaxed);+ detector.last_output_speech_ts.store(expired, Ordering::Relaxed);+ assert!(!detector.is_in_meeting(), "audio meeting should end");++ // Step 6: New audio during cooldown+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(+ !detector.is_in_meeting(),+ "cooldown should prevent re-trigger"+ );+ }++ #[tokio::test]+ async fn test_current_meeting_app_during_audio_extension() {+ // When audio-based detection extends a meeting, current_meeting_app+ // should report something useful instead of empty "()"+ let detector = MeetingDetector::new();++ // User was in Google Meet, now tabbed away and grace period expired+ detector+ .on_app_switch("Arc", Some("standup - meet.google.com/abc"))+ .await;+ detector.on_app_switch("Finder", None).await;+ {+ let mut state = detector.state.write().await;+ state.last_meeting_focus =+ Some(Instant::now() - MEETING_GRACE_PERIOD - Duration::from_secs(1));+ }+ detector.check_grace_period().await;++ // Audio extends meeting+ detector.on_audio_activity(&DeviceType::Input, true);+ detector.on_audio_activity(&DeviceType::Output, true);+ assert!(detector.is_in_meeting());++ // Should report something meaningful, not None/empty+ let app = detector.current_meeting_app().await;+ assert!(+ app.is_some(),+ "should report meeting app during audio extension, got None (would show '()' in logs)"+ );}}