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
feat(meeting): publish ActiveMeeting{pid,bundle} from watcher to MeetingDetector
Ezra Ellettee1be15eed5eb
diff --git a/crates/screenpipe-audio/src/core/process_tap/macos.rs b/crates/screenpipe-audio/src/core/process_tap/macos.rsindex 9da1b71d6..cc9df6585 100644--- a/crates/screenpipe-audio/src/core/process_tap/macos.rs+++ b/crates/screenpipe-audio/src/core/process_tap/macos.rs@@ -1391,7 +1391,7 @@ mod tests {print_states("before-tap");let (tx, _rx) = broadcast::channel(16);let is_disconnected = Arc::new(AtomicBool::new(false));- if let Ok((_capture, _config, uid)) =+ if let Ok((_capture, _config, uid, _watchdog)) =build_inclusion_capture(&[std::process::id() as i32], tx, is_disconnected){std::thread::sleep(std::time::Duration::from_millis(1500));diff --git a/crates/screenpipe-audio/src/meeting_detector.rs b/crates/screenpipe-audio/src/meeting_detector.rsindex 2dfcd2bc4..68d356c23 100644--- a/crates/screenpipe-audio/src/meeting_detector.rs+++ b/crates/screenpipe-audio/src/meeting_detector.rs@@ -29,6 +29,24 @@ fn now_ms() -> u64 {.unwrap_or(0)}+/// Identity of the currently-detected meeting process, published by the+/// watcher alongside the `set_v2_in_meeting(true)` boolean.+///+/// `pid: None` is a legal published state meaning "a meeting is active but+/// the sensor that detected it can't identify the process" (ui_scan, a+/// post-restart reattach, or a `BlockedByActive` outcome where a different,+/// already-active meeting owns the mic). Consumers must fall back to the+/// stable (non-per-process) capture path in that case — this is not an+/// error condition.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct ActiveMeeting {+ /// Detected meeting process. None when the sensor can't know one+ /// (ui_scan, post-restart reattach) — the piggyback layer must fall+ /// back to the stable capture path in that case.+ pub pid: Option<i32>,+ pub bundle_id: Option<String>,+}+/// Lightweight meeting state holder for the audio pipeline.////// The v2 meeting detection system (UI scanning in `screenpipe-engine`) owns@@ -55,6 +73,9 @@ pub struct MeetingDetector {/// detection loop can wake immediately and scan instead of waiting out a/// slow idle interval.audio_onset: Notify,+ /// Identity of the currently-detected meeting process, published by the+ /// v2 watcher alongside `v2_override`. See [`ActiveMeeting`].+ active_meeting: std::sync::Mutex<Option<ActiveMeeting>>,}impl Default for MeetingDetector {@@ -71,6 +92,7 @@ impl MeetingDetector {last_output_chunk_ms: AtomicU64::new(0),last_input_chunk_ms: AtomicU64::new(0),audio_onset: Notify::new(),+ active_meeting: std::sync::Mutex::new(None),}}@@ -79,6 +101,16 @@ impl MeetingDetector {self.v2_override.store(in_meeting, Ordering::Relaxed);}+ /// Publish which meeting is active (pid/bundle when the sensor knows it).+ /// Set alongside `set_v2_in_meeting(true)`; cleared on every end path.+ pub fn set_active_meeting(&self, meeting: Option<ActiveMeeting>) {+ *self.active_meeting.lock().unwrap() = meeting;+ }++ pub fn active_meeting(&self) -> Option<ActiveMeeting> {+ self.active_meeting.lock().unwrap().clone()+ }+/// Get the v2 override flag reference (AtomicBool) for direct access.pub fn v2_override_flag(&self) -> &AtomicBool {&self.v2_override@@ -261,4 +293,17 @@ mod tests {detector.set_v2_in_meeting(false);assert!(detector.audio_active_within(45_000));}++ #[test]+ fn active_meeting_set_get_clear() {+ let d = MeetingDetector::new();+ assert!(d.active_meeting().is_none());+ d.set_active_meeting(Some(ActiveMeeting {+ pid: Some(4242),+ bundle_id: Some("us.zoom.xos".into()),+ }));+ assert_eq!(d.active_meeting().unwrap().pid, Some(4242));+ d.set_active_meeting(None);+ assert!(d.active_meeting().is_none());+ }}diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/events.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/events.rsindex 18c7821d3..84b7eb52d 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/events.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/events.rs@@ -76,7 +76,7 @@ pub(crate) fn handle_stop_signal();*state = AudioProcessMeetingState::Idle;*last_explicit_stop_id = Some(stop_signal.meeting_id);- sync_meeting_flag(false, in_meeting_flag, detector);+ sync_meeting_flag(false, None, in_meeting_flag, detector);}}@@ -127,7 +127,7 @@ pub(crate) async fn handle_auto_end_request(}*state = AudioProcessMeetingState::Idle;}- sync_meeting_flag(false, in_meeting_flag, detector);+ sync_meeting_flag(false, None, in_meeting_flag, detector);emit_ended_and_status(db, manual_meeting, request.meeting_id).await;}Err(e) => warn!(diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/lifecycle.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/lifecycle.rsindex 42598e461..a4c746191 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/lifecycle.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/lifecycle.rs@@ -174,12 +174,14 @@ pub(crate) async fn capture_meeting_outcome(pub(crate) fn sync_meeting_flag(in_meeting: bool,+ active: Option<screenpipe_audio::meeting_detector::ActiveMeeting>,flag: &AtomicBool,detector: &Option<Arc<MeetingDetector>>,) {flag.store(in_meeting, Ordering::Relaxed);if let Some(detector) = detector {detector.set_v2_in_meeting(in_meeting);+ detector.set_active_meeting(if in_meeting { active } else { None });}}@@ -225,6 +227,8 @@ pub(crate) async fn apply_state_action(meeting_url,first_seen_at,is_browser,+ pid,+ bundle_id,} => {let (cal_title, cal_attendees) = find_overlapping_calendar_event(calendar_events);let attendees_str = cal_attendees.as_ref().map(|a| a.join(", "));@@ -249,7 +253,12 @@ pub(crate) async fn apply_state_action(last_seen_at: now,is_browser,};- sync_meeting_flag(true, in_meeting_flag, detector);+ sync_meeting_flag(+ true,+ Some(screenpipe_audio::meeting_detector::ActiveMeeting { pid, bundle_id }),+ in_meeting_flag,+ detector,+ );if let Ok(status) = resolve_meeting_status_from(db, manual_meeting).await {emit_meeting_status_changed(&status);}@@ -260,7 +269,9 @@ pub(crate) async fn apply_state_action(meeting_id);*state = AudioProcessMeetingState::Idle;- sync_meeting_flag(true, in_meeting_flag, detector);+ // A different meeting already owns the active slot; we+ // don't know its process identity from here.+ sync_meeting_flag(true, None, in_meeting_flag, detector);if let Ok(status) = resolve_meeting_status_from(db, manual_meeting).await {emit_meeting_status_changed(&status);}@@ -295,7 +306,7 @@ pub(crate) async fn apply_state_action();}}- sync_meeting_flag(false, in_meeting_flag, detector);+ sync_meeting_flag(false, None, in_meeting_flag, detector);}}}diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rsindex 0ef5782e5..579dc728e 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs@@ -130,7 +130,17 @@ pub async fn run_audio_process_meeting_detection_loop(last_seen_at: now,is_browser: false,};- sync_meeting_flag(true, &in_meeting_flag, &detector);+ // Reattaching after a restart: the DB knows a meeting was active but+ // the sensor has no live process snapshot to attribute it to yet.+ sync_meeting_flag(+ true,+ Some(screenpipe_audio::meeting_detector::ActiveMeeting {+ pid: None,+ bundle_id: None,+ }),+ &in_meeting_flag,+ &detector,+ );info!("audio-process meeting detector: reattached active meeting (id={}, app={})",meeting.id, meeting.meeting_app@@ -155,7 +165,7 @@ pub async fn run_audio_process_meeting_detection_loop(_ = shutdown_rx.recv() => {info!("audio-process meeting detector: shutdown received");end_active_meeting_on_shutdown(&db, &state).await;- sync_meeting_flag(false, &in_meeting_flag, &detector);+ sync_meeting_flag(false, None, &in_meeting_flag, &detector);return;}}@@ -194,7 +204,10 @@ pub async fn run_audio_process_meeting_detection_loop(debug!("audio-process meeting detector: manual meeting active, skipping auto detection");- sync_meeting_flag(true, &in_meeting_flag, &detector);+ // A manually-started meeting owns the active slot; this+ // detector has no process identity for it from here (mirrors+ // the BlockedByActive case in `apply_state_action`).+ sync_meeting_flag(true, None, &in_meeting_flag, &detector);interval = IDLE_POLL_INTERVAL;continue;}@@ -291,7 +304,14 @@ pub async fn run_audio_process_meeting_detection_loop(}let active_now = matches!(state, AudioProcessMeetingState::Active { .. });- sync_meeting_flag(active_now, &in_meeting_flag, &detector);+ // This end-of-tick call is a flag resync, not a transition:+ // `apply_state_action` above already published the identity for a+ // fresh `StartMeeting` this tick, and on every other tick nothing+ // changed. Read back whatever is currently published and pass it+ // through so this resync doesn't clobber it with `None` on every+ // single loop iteration while a meeting stays active.+ let current_active_meeting = detector.as_ref().and_then(|d| d.active_meeting());+ sync_meeting_flag(active_now, current_active_meeting, &in_meeting_flag, &detector);interval = if processes.is_empty() {IDLE_POLL_INTERVAL} else {diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/model.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/model.rsindex 2c4d9ad00..c5488034a 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/model.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/model.rs@@ -153,6 +153,7 @@ impl ResolvedMeetingCandidate {platform,session_key,first_seen_at,+ process,..} => Some(ResolvedSession {platform: platform.clone(),@@ -163,6 +164,8 @@ impl ResolvedMeetingCandidate {// A native app holding the mic is by definition a live// observation of the current snapshot.live_evidence: true,+ pid: process.pid,+ bundle_id: process.bundle_id.clone(),}),Self::Browser {platform,@@ -170,6 +173,7 @@ impl ResolvedMeetingCandidate {session_key,first_seen_at,live_evidence,+ process,..} => Some(ResolvedSession {platform: platform.clone(),@@ -178,6 +182,8 @@ impl ResolvedMeetingCandidate {first_seen_at: *first_seen_at,is_browser: true,live_evidence: *live_evidence,+ pid: process.pid,+ bundle_id: process.bundle_id.clone(),}),_ => None,}@@ -213,6 +219,10 @@ pub(crate) struct ResolvedSession {/// See [`ResolvedMeetingCandidate::Browser::live_evidence`]. Always true/// for native candidates.pub(crate) live_evidence: bool,+ /// Meeting process identity, threaded from the resolved candidate's+ /// `AudioInputProcess` through to the published `ActiveMeeting`.+ pub(crate) pid: Option<i32>,+ pub(crate) bundle_id: Option<String>,}/// Result of scanning a messaging app's AX tree for call UI evidence.diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rsindex e8c37cc3c..62e656f6a 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs@@ -631,8 +631,13 @@ pub(crate) fn acquire_input_processes();*unsupported_logged = true;}+ // This is a flag resync, not a fresh transition — preserve whatever+ // identity is already published rather than clobbering it with+ // `None` on every idle tick while the platform sensor is unsupported.+ let current_active_meeting = detector.as_ref().and_then(|d| d.active_meeting());sync_meeting_flag(matches!(state, AudioProcessMeetingState::Active { .. }),+ current_active_meeting,in_meeting_flag,detector,);diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/state.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/state.rsindex 9f533906f..ec1967644 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/state.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/state.rs@@ -50,6 +50,8 @@ pub(crate) enum AudioProcessStateAction {meeting_url: Option<String>,first_seen_at: Instant,is_browser: bool,+ pid: Option<i32>,+ bundle_id: Option<String>,},EndMeeting {meeting_id: i64,@@ -103,6 +105,8 @@ pub(crate) fn advance_audio_process_state(meeting_url: session.meeting_url,first_seen_at: session.first_seen_at,is_browser: session.is_browser,+ pid: session.pid,+ bundle_id: session.bundle_id,}),);}@@ -242,6 +246,8 @@ fn advance_from_candidate(meeting_url,first_seen_at,is_browser,+ pid: session.pid,+ bundle_id: session.bundle_id,}),);}@@ -492,3 +498,57 @@ pub(crate) fn is_active_ending_flap(let now_ending = matches!(next, AudioProcessMeetingState::Ending { .. });(was_active && now_ending) || (was_ending && now_active)}++#[cfg(test)]+mod tests {+ use super::*;++ fn zoom_process() -> AudioInputProcess {+ AudioInputProcess {+ audio_session_id: None,+ audio_object_id: None,+ pid: Some(4242),+ bundle_id: Some("us.zoom.xos".to_string()),+ process_name: Some("zoom.us".to_string()),+ owner_app_name: Some("zoom.us".to_string()),+ owner_bundle_id: Some("us.zoom.xos".to_string()),+ first_seen_at_ms: None,+ }+ }++ #[test]+ fn start_meeting_action_carries_pid_and_bundle() {+ // Build a ResolvedSession as the sensors do, run advance_from_candidate+ // past its confirm window, and assert the action carries the identity.+ let process = zoom_process();+ let session_key = ProcessKey::from_process(&process).unwrap();+ let session = ResolvedSession {+ platform: "zoom".into(),+ session_key: session_key.clone(),+ meeting_url: None,+ first_seen_at: Instant::now() - Duration::from_secs(60),+ is_browser: false,+ live_evidence: false,+ pid: Some(4242),+ bundle_id: Some("us.zoom.xos".into()),+ };+ let (_state, action) = advance_from_candidate(+ "zoom".into(),+ session.session_key.clone(),+ None,+ session.first_seen_at,+ false,+ Some(session),+ None,+ Instant::now(),+ Duration::from_secs(10),+ );+ match action {+ Some(AudioProcessStateAction::StartMeeting { pid, bundle_id, .. }) => {+ assert_eq!(pid, Some(4242));+ assert_eq!(bundle_id.as_deref(), Some("us.zoom.xos"));+ }+ other => panic!("expected StartMeeting, got {other:?}"),+ }+ }+}diff --git a/crates/screenpipe-engine/src/meeting_watcher/ui_scan/lifecycle.rs b/crates/screenpipe-engine/src/meeting_watcher/ui_scan/lifecycle.rsindex 9728e4058..81998f60f 100644--- a/crates/screenpipe-engine/src/meeting_watcher/ui_scan/lifecycle.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/ui_scan/lifecycle.rs@@ -17,6 +17,18 @@ pub(crate) fn sync_meeting_flag(flag.store(in_meeting, Ordering::Relaxed);if let Some(ref det) = detector {det.set_v2_in_meeting(in_meeting);+ // The UI-scan sensor detects meeting *apps*, not audio-input+ // processes, so it never has a pid to publish. `pid: None` here is+ // a legal, expected state — the piggyback layer falls back to the+ // stable capture path for it.+ det.set_active_meeting(if in_meeting {+ Some(screenpipe_audio::meeting_detector::ActiveMeeting {+ pid: None,+ bundle_id: None,+ })+ } else {+ None+ });}}