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(meetings): heal the meeting pid after a capture restart so mic-follow re-engages
Ezra Elletted5db735d9f00
diff --git a/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs b/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rsindex 35bb82d56..b3cec2bad 100644--- a/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs+++ b/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs@@ -1601,6 +1601,36 @@ mod tests {)));}+ #[test]+ fn switch_to_suspended_mic_recovers_in_one_tick() {+ // The meeting app switches TO a mic this sweep previously suspended+ // (D1 displaced it while another resolved mic streamed). The device is+ // suspended AND stopped: not running, not a session, not streaming.+ // The decider must both open it (StartSessionInput — session starts+ // are NOT blocked by the suspension guard, which only gates+ // `start_device`) and lift the suspension (Resume — no resolved mic is+ // streaming this tick), so capture follows the switch within a tick+ // instead of wedging on a suspended-but-wanted device.+ let mut obs = base();+ obs.resolved_inputs = vec!["MacBook Pro Microphone (input)".to_string()];+ obs.suspended = ["MacBook Pro Microphone (input)".to_string()].into();+ // The previously resolved session mic was just torn down; nothing else+ // is running or streaming.+ let actions = decide_piggyback(&obs);+ assert!(+ actions.contains(&PiggybackAction::StartSessionInput(+ "MacBook Pro Microphone (input)".to_string()+ )),+ "the newly-resolved mic must get a session stream: {actions:?}"+ );+ assert!(+ actions.contains(&PiggybackAction::Resume(+ "MacBook Pro Microphone (input)".to_string()+ )),+ "its suspension must lift in the same tick: {actions:?}"+ );+ }+// --- Mic capture-health decider (Task 9) --------------------------------fn mic_obs(now: u64) -> MicHealthObservation {diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rsindex e40e1b6be..b260532b5 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/mod.rs@@ -137,6 +137,12 @@ pub async fn run_audio_process_meeting_detection_loop(// (which publishes ActiveMeeting{manual: true} for manual meetings —// see recording.rs), and hardcoding `manual: false` here clobbered// that, stripping a restored manual meeting of its manual piggyback.+ // `pid: None` here is TRANSIENT for detected meetings: the loop keeps+ // resolution running for the reattached key (`needs_ax_resolution`)+ // and republishes the pid from the first live candidate that resolves+ // to this platform (see the heal before the end-of-tick resync), so+ // the piggyback sweep re-engages instead of riding the stable path+ // for the rest of the meeting.sync_meeting_flag(true,Some(screenpipe_audio::meeting_detector::ActiveMeeting {@@ -328,7 +334,38 @@ pub async fn run_audio_process_meeting_detection_loop(// 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());+ let mut current_active_meeting = detector.as_ref().and_then(|d| d.active_meeting());+ // Heal a pid-less DETECTED meeting from this tick's live candidates.+ // A post-restart reattach publishes `ActiveMeeting { pid: None }`, and+ // only `StartMeeting` ever published a pid — so without this the+ // piggyback sweep (per-process tap + mic-follow) stayed disengaged for+ // the rest of the meeting and in-meeting mic switches were never+ // followed. Only a candidate resolved to the meeting's own platform is+ // adopted (see `resolved_platform_identity`); manual meetings derive+ // their pids from the live mic-holder enumeration and are left alone.+ if active_now {+ if let (AudioProcessMeetingState::Active { platform, .. }, Some(published)) =+ (&state, current_active_meeting.as_ref())+ {+ if !published.manual && published.pid.is_none() {+ if let Some((pid, bundle_id)) =+ resolved_platform_identity(&live_candidates, platform)+ {+ info!(+ "audio-process meeting detector: re-resolved meeting process \+ (pid={}, app={}) — per-process capture re-engages",+ pid, platform+ );+ current_active_meeting =+ Some(screenpipe_audio::meeting_detector::ActiveMeeting {+ pid: Some(pid),+ bundle_id,+ manual: false,+ });+ }+ }+ }+ }sync_meeting_flag(active_now, current_active_meeting, &in_meeting_flag, &detector);interval = if processes.is_empty() {IDLE_POLL_INTERVALdiff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rsindex bff299f49..30b9e7b6e 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/resolve.rs@@ -44,11 +44,40 @@ pub(crate) async fn resolve_tracked_candidates(/// meeting platform. Once a meeting is `Active` — or already winding down in/// `Ending` — the platform is settled, so re-walking the tree every/// `ACTIVE_POLL_INTERVAL` for the rest of the call is pure overhead.+///+/// EXCEPTION: a meeting reattached after a capture restart carries a synthetic+/// `reattached:` key and a published `ActiveMeeting { pid: None }` — the+/// platform is settled but the PROCESS identity isn't, and the piggyback+/// sweep (per-process tap + mic-follow) stays disengaged until it heals. A+/// browser meeting on a static call screen produces no fresh frame evidence,+/// so the active-tab probe / AX sweep is the only thing that can re-attribute+/// it. Keep resolving until the state adopts a real key (see the reattached+/// branch of `matching_session_key`); the extra per-poll cost is exactly the+/// pre-meeting cost and stops as soon as the identity heals.pub(crate) fn needs_ax_resolution(state: &AudioProcessMeetingState) -> bool {- !matches!(- state,- AudioProcessMeetingState::Active { .. } | AudioProcessMeetingState::Ending { .. }- )+ match state {+ AudioProcessMeetingState::Active { session_key, .. }+ | AudioProcessMeetingState::Ending { session_key, .. } => session_key.is_reattached(),+ _ => true,+ }+}++/// Live process identity for the given platform, from this tick's resolved+/// candidates. The detection loop uses this to heal a pid-less published+/// `ActiveMeeting` (post-restart reattach) so the piggyback sweep re-engages:+/// only a candidate RESOLVED to the meeting's own platform counts — an+/// unresolved browser merely holding the mic could be any WebRTC page, and+/// tapping the wrong process would replace the stable capture with the wrong+/// app's audio.+pub(crate) fn resolved_platform_identity(+ candidates: &[ResolvedMeetingCandidate],+ platform: &str,+) -> Option<(i32, Option<String>)> {+ candidates+ .iter()+ .filter_map(ResolvedMeetingCandidate::resolved_session)+ .find(|session| session.platform == platform && session.pid.is_some())+ .and_then(|session| session.pid.map(|pid| (pid, session.bundle_id)))}pub(crate) async fn should_use_ax_fallback(diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/suppress.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/suppress.rsindex 36598c4a8..82adf60d8 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/suppress.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/suppress.rs@@ -34,7 +34,23 @@ pub(crate) fn matching_session_key(// platform after restart, surfacing as an `UnresolvedBrowser` in the gap.// Keep it alive while *any* live meeting session is present; genuine// disappearance still flows through the normal ending grace.+ //+ // The moment a candidate RESOLVES to this meeting's own platform, ADOPT its+ // real key (mirroring the native re-key adoption below): the state stops+ // being keyed to a synthetic string that matches any mic holder,+ // end-of-meeting suppression targets the live session, the per-poll AX /+ // active-tab probing gated on `is_reattached` stops, and the detection+ // loop can republish the candidate's pid so the piggyback sweep+ // (per-process tap + mic-follow) re-engages after a capture restart.if session_key.is_reattached() {+ if let Some(adopted) = candidates+ .iter()+ .filter_map(ResolvedMeetingCandidate::resolved_session)+ .find(|session| session.platform == platform)+ .map(|session| session.session_key)+ {+ return Some(adopted);+ }return candidates.iter().any(|candidate| {diff --git a/crates/screenpipe-engine/src/meeting_watcher/audio_process/tests.rs b/crates/screenpipe-engine/src/meeting_watcher/audio_process/tests.rsindex a3f42086a..df90b07ae 100644--- a/crates/screenpipe-engine/src/meeting_watcher/audio_process/tests.rs+++ b/crates/screenpipe-engine/src/meeting_watcher/audio_process/tests.rs@@ -1840,3 +1840,179 @@ fn end_after_mic_switch_rekey_suppresses_adopted_session_key() {"the live re-keyed session must stay suppressed after the meeting ends");}++// --- Post-restart reattach: the meeting must re-acquire its process identity ---+//+// Regression (2026-07-07, live Google Meet in Arc): a mid-meeting capture+// restart reattaches the meeting with a synthetic `reattached:` key and a+// published `ActiveMeeting { pid: None }`. Nothing ever healed that identity:+// `matching_session_key` kept the synthetic key forever, `needs_ax_resolution`+// stopped the active-tab/AX probes the moment the state was Active, and the+// detection loop only publishes a pid on `StartMeeting`. With `pid: None` the+// piggyback sweep computes an empty pid set and disengages entirely — no+// Meeting Tap, no `resolve_meeting_inputs`, so in-meeting mic switches are+// never followed for the rest of the call.++#[test]+fn ax_resolution_keeps_running_for_reattached_meeting() {+ // A reattached meeting has a synthetic identity: the platform is known+ // (from the DB row) but the PROCESS isn't. Resolution must keep running+ // until a live candidate re-attributes it — otherwise a browser meeting+ // (evidence-starved on a static call screen) can never heal its pid.+ let now = Instant::now();+ assert!(+ needs_ax_resolution(&AudioProcessMeetingState::Active {+ meeting_id: 73,+ platform: "Google Meet".to_string(),+ session_key: ProcessKey::reattached("Google Meet"),+ meeting_url: None,+ first_seen_at: now,+ last_seen_at: now,+ is_browser: false,+ }),+ "an Active meeting with a synthetic reattached key must keep resolving"+ );+ assert!(+ needs_ax_resolution(&AudioProcessMeetingState::Ending {+ meeting_id: 73,+ platform: "Google Meet".to_string(),+ session_key: ProcessKey::reattached("Google Meet"),+ meeting_url: None,+ first_seen_at: now,+ since: now,+ is_browser: false,+ }),+ "an Ending meeting with a synthetic reattached key must keep resolving"+ );+}++#[test]+fn reattached_meeting_adopts_resolved_platform_session_key() {+ // Once a live candidate RESOLVES to the reattached meeting's platform, the+ // state must adopt that candidate's real key (mirroring the native+ // mic-switch re-key adoption): end-of-meeting suppression then targets the+ // live session, and the meeting stops being keyed to a synthetic string+ // that matches any mic holder.+ let process = chrome_process();+ let live_key = ProcessKey::from_process(&process).unwrap();+ let start = Instant::now();+ let reattached = AudioProcessMeetingState::Active {+ meeting_id: 73,+ platform: "Google Meet".to_string(),+ session_key: ProcessKey::reattached("Google Meet"),+ meeting_url: None,+ first_seen_at: start,+ last_seen_at: start,+ is_browser: false,+ };+ let resolved = ResolvedMeetingCandidate::Browser {+ platform: "Google Meet".to_string(),+ meeting_url: "https://meet.google.com/abc-defg-hij".to_string(),+ browser_app: "Google Chrome".to_string(),+ session_key: live_key.clone(),+ first_seen_at: start,+ process,+ live_evidence: true,+ };+ let (state, action) = advance_audio_process_state(+ reattached,+ &[],+ std::slice::from_ref(&resolved),+ start + Duration::from_secs(2),+ Duration::from_secs(1),+ Duration::from_secs(20),+ );+ assert!(action.is_none(), "expected no action, got {action:?}");+ match state {+ AudioProcessMeetingState::Active {+ meeting_id: 73,+ session_key,+ ..+ } => assert_eq!(+ session_key, live_key,+ "reattached state must adopt the resolved same-platform candidate's key"+ ),+ other => panic!("meeting must stay active, got {other:?}"),+ }+}++#[test]+fn reattached_meeting_keeps_synthetic_key_when_resolution_is_other_platform() {+ // A resolved candidate for a DIFFERENT platform (say a Zoom call in+ // another window) must not be adopted as the reattached meeting's+ // identity — the synthetic keep-alive stays in force instead.+ let start = Instant::now();+ let reattached_key = ProcessKey::reattached("Google Meet");+ let reattached = AudioProcessMeetingState::Active {+ meeting_id: 73,+ platform: "Google Meet".to_string(),+ session_key: reattached_key.clone(),+ meeting_url: None,+ first_seen_at: start,+ last_seen_at: start,+ is_browser: false,+ };+ let zoom = ResolvedMeetingCandidate::Native {+ platform: "Zoom".to_string(),+ session_key: ProcessKey::from_process(&zoom_process()).unwrap(),+ first_seen_at: start,+ process: zoom_process(),+ };+ let (state, _) = advance_audio_process_state(+ reattached,+ &[],+ std::slice::from_ref(&zoom),+ start + Duration::from_secs(2),+ Duration::from_secs(1),+ Duration::from_secs(20),+ );+ match state {+ AudioProcessMeetingState::Active { session_key, .. } => assert_eq!(+ session_key, reattached_key,+ "an other-platform candidate must not hijack the meeting's identity"+ ),+ other => panic!("meeting must stay active on the keep-alive, got {other:?}"),+ }+}++#[test]+fn resolved_platform_identity_heals_pid_from_matching_candidate() {+ // The pure helper the detection loop uses to republish a healed+ // `ActiveMeeting`: a live candidate resolved to the meeting's platform+ // yields its pid + bundle id; unresolved or other-platform candidates+ // yield nothing.+ let start = Instant::now();+ let process = chrome_process();+ let candidates = vec![+ ResolvedMeetingCandidate::UnresolvedBrowser {+ browser_app: "Arc".to_string(),+ session_key: ProcessKey::from_process(&arc_process()).unwrap(),+ first_seen_at: start,+ process: arc_process(),+ },+ ResolvedMeetingCandidate::Browser {+ platform: "Google Meet".to_string(),+ meeting_url: "https://meet.google.com/abc-defg-hij".to_string(),+ browser_app: "Google Chrome".to_string(),+ session_key: ProcessKey::from_process(&process).unwrap(),+ first_seen_at: start,+ process: process.clone(),+ live_evidence: true,+ },+ ];+ assert_eq!(+ resolved_platform_identity(&candidates, "Google Meet"),+ Some((42, Some("com.google.Chrome.helper".to_string()))),+ "the matching resolved candidate's pid/bundle must be surfaced"+ );+ assert_eq!(+ resolved_platform_identity(&candidates, "Zoom"),+ None,+ "an other-platform meeting must not adopt this candidate's pid"+ );+ assert_eq!(+ resolved_platform_identity(&candidates[..1], "Google Meet"),+ None,+ "an unresolved browser alone must not be adopted (could be any WebRTC page)"+ );+}