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

fix(meetings): refuse manual meeting start while recording is stopped; fix mic resume and mic choice during smart recording (SCR-590) (#7615)

Ezra Ellette5f3514f3e4f7
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/capture_session.rs b/apps/screenpipe-app-tauri/src-tauri/src/capture_session.rs
index 996fd9dac..da697b3f3 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/capture_session.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/capture_session.rs
@@ -326,6 +326,7 @@ impl CaptureSession {
);
}
+ screenpipe_engine::meeting_watcher::set_capture_stopped(false);
info!("Capture session started successfully");
Ok(Self {
@@ -366,6 +367,7 @@ impl CaptureSession {
/// Quit-to-search must report failures before claiming capture is stopped.
pub async fn stop_checked(mut self) -> Result<(), String> {
info!("Stopping capture session");
+ screenpipe_engine::meeting_watcher::set_capture_stopped(true);
let mut failures = Vec::new();
// Signal UI recorder to stop
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands/native_actions.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands/native_actions.rs
index b9d6f10cc..f9694a84f 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands/native_actions.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands/native_actions.rs
@@ -1553,7 +1553,7 @@ fn native_shortcut_action_callback_inner(action_ptr: *const std::os::raw::c_char
.header("Content-Type", "application/json")
.body(r#"{"app":"manual"}"#),
);
- if let Ok(res) = req.send() {
+ if let Ok(res) = req.send().and_then(|r| r.error_for_status()) {
track_native_overlay_event(
&app_clone,
"shortcut_reminder_meeting_toggled",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
index 9a405198e..bf4dd9cf8 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
@@ -563,6 +563,7 @@ pub async fn stop_capture(
// off). Clear the intent so a later engine crash doesn't get auto-respawned
// — which would resurrect capture the user deliberately stopped.
state.set_capture_intent(false);
+ screenpipe_engine::meeting_watcher::set_capture_stopped(true);
remember_active_meeting_for_capture_restart(&state).await;
@@ -924,6 +925,7 @@ pub(crate) async fn stop_screenpipe_inner(state: &RecordingState) -> Result<(),
// the call. The capture-only path (`stop_capture`) has always done this;
// the full restart used by "Apply & Restart", audio shortcuts, updates,
// and the health overlay's RESTART button cleared it instead.
+ screenpipe_engine::meeting_watcher::set_capture_stopped(true);
remember_active_meeting_for_capture_restart(state).await;
let mut capture_guard = state.capture.lock().await;
if let Some(session) = capture_guard.take() {
@@ -1825,7 +1827,9 @@ async fn spawn_screenpipe_after_migration(
// coordinator; without this the full-restart path (unlike the
// capture-only path) left the call transcribing on the delayed
// background chunker only, with no live notes and no way back.
- if let Err(e) = restore_interrupted_meeting_for_capture_restart(&state).await {
+ if state.capture.lock().await.is_none() {
+ *state.interrupted_meeting.lock().await = None;
+ } else if let Err(e) = restore_interrupted_meeting_for_capture_restart(&state).await {
warn!("failed to restore interrupted meeting after restart: {}", e);
}
let spawn_epoch = std::time::SystemTime::now()
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
index 08643e27d..97f9c054f 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
@@ -352,6 +352,7 @@ impl ServerCore {
workflow_catalog_dir: Option<std::path::PathBuf>,
runtime_lifetime: tokio::sync::oneshot::Sender<()>,
) -> Result<Self, String> {
+ screenpipe_engine::meeting_watcher::set_capture_stopped(true);
screenpipe_core::health_diagnostics::begin_startup(&config.data_dir);
screenpipe_core::health_diagnostics::configure_media_required(
!config.disable_audio
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rs
index 97c5cf012..619f3bd9e 100644
--- a/crates/screenpipe-audio/src/audio_manager/manager.rs
+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs
@@ -876,7 +876,13 @@ impl AudioManager {
.write()
.await
.insert(device.to_string());
- self.start_device(&device).await?;
+ if device.device_type == crate::core::device::DeviceType::Input
+ && self.meeting_piggyback_owns_normal_capture().await
+ {
+ self.start_session_device(&device, None).await?;
+ } else {
+ self.start_device(&device).await?;
+ }
if !self.is_device_actively_streaming(&device) {
return Err(anyhow!(
"Device {} did not start: capture is gated or the stream is unavailable",
@@ -3208,6 +3214,39 @@ mod tests {
assert!(manager.session_devices().is_empty());
}
+ #[tokio::test]
+ async fn resume_during_smart_recording_meeting_opens_a_session_stream() {
+ let db = Arc::new(
+ DatabaseManager::new("sqlite::memory:", Default::default())
+ .await
+ .unwrap(),
+ );
+ let detector = Arc::new(MeetingDetector::new());
+ let manager = AudioManager::new(
+ AudioManagerOptions {
+ is_disabled: true, // Construct without models or opening hardware.
+ experimental_meeting_piggyback: true,
+ meeting_detector: Some(detector.clone()),
+ ..Default::default()
+ },
+ db,
+ )
+ .await
+ .unwrap();
+ manager.options.write().await.is_disabled = false;
+ *manager.status.write().await = AudioManagerStatus::Running;
+ detector.set_v2_in_meeting(true);
+ manager.set_piggyback_owns_capture(true);
+ let name = "SCR-590 microphone (input)";
+ manager.pause_device(name).await.ok();
+ let error = manager.resume_device(name).await.unwrap_err().to_string();
+ assert!(
+ !error.contains("did not start"),
+ "resume must try the meeting-session stream, not the gated normal start: {error}"
+ );
+ assert!(!manager.user_disabled_devices().await.contains(name));
+ }
+
#[tokio::test]
async fn bluetooth_gate_distinguishes_explicit_selection_from_automatic_enrollment() {
let db = Arc::new(
diff --git a/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs b/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs
index c9ea4752d..a3710f131 100644
--- a/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs
+++ b/crates/screenpipe-audio/src/audio_manager/meeting_piggyback.rs
@@ -1125,20 +1125,28 @@ fn select_meeting_inputs(
process_inputs: Vec<String>,
follow_default: bool,
configured: HashSet<String>,
+ available: &HashSet<String>,
default_input: Option<String>,
user_disabled: &HashSet<String>,
) -> (Vec<String>, &'static str) {
+ let configured_inputs: Vec<String> = configured
+ .into_iter()
+ .filter(|name| name.ends_with(" (input)"))
+ .collect();
+ let available_configured: Vec<String> = configured_inputs
+ .iter()
+ .filter(|name| available.contains(*name))
+ .cloned()
+ .collect();
// A resolved but explicitly paused microphone must stay paused; do not
// interpret that privacy choice as a resolver failure and open another mic.
- let (mut inputs, source) = if !process_inputs.is_empty() {
+ let (mut inputs, source) = if !follow_default && !available_configured.is_empty() {
+ (available_configured, "configured")
+ } else if !process_inputs.is_empty() {
(process_inputs, "process")
} else if follow_default {
(default_input.into_iter().collect(), "system_default")
} else {
- let configured_inputs: Vec<String> = configured
- .into_iter()
- .filter(|name| name.ends_with(" (input)"))
- .collect();
(configured_inputs, "configured")
};
inputs.retain(|name| !user_disabled.contains(name));
@@ -1255,10 +1263,23 @@ pub(crate) async fn run_meeting_piggyback_sweep(
// in automatic mode. Session capture allows Bluetooth for this meeting.
let mic_capture_active = engaged && meeting.is_some();
let (resolved_inputs, mic_source) = if mic_capture_active {
+ let follow_default = audio_manager.use_system_default_audio().await;
+ let available: HashSet<String> = if follow_default {
+ HashSet::new()
+ } else {
+ audio_manager
+ .devices()
+ .await
+ .unwrap_or_default()
+ .iter()
+ .map(|d| d.to_string())
+ .collect()
+ };
select_meeting_inputs(
process_inputs,
- audio_manager.use_system_default_audio().await,
+ follow_default,
audio_manager.enabled_devices().await,
+ &available,
crate::core::device::default_input_device()
.ok()
.map(|d| d.to_string()),
@@ -1764,6 +1785,7 @@ mod tests {
vec![],
true,
[builtin.clone()].into(),
+ &HashSet::new(),
Some(bt.clone()),
&HashSet::new(),
);
@@ -1773,6 +1795,7 @@ mod tests {
vec![builtin.clone()],
true,
HashSet::new(),
+ &HashSet::new(),
Some(bt),
&HashSet::new(),
);
@@ -1789,6 +1812,7 @@ mod tests {
vec![],
false,
configured,
+ &HashSet::new(),
Some(default.clone()),
&HashSet::new(),
);
@@ -1798,12 +1822,41 @@ mod tests {
vec![default.clone()],
true,
HashSet::new(),
+ &HashSet::new(),
Some("Other (input)".into()),
&[default].into(),
);
assert!(inputs.is_empty());
}
+ #[test]
+ fn explicit_mic_choice_wins_over_the_meeting_apps_mic() {
+ let macbook = "MacBook Pro Microphone (input)".to_string();
+ let airpods = "AirPods Max (input)".to_string();
+ let configured: HashSet<String> = [macbook.clone(), "System Audio (output)".into()].into();
+ let (inputs, source) = select_meeting_inputs(
+ vec![airpods.clone()],
+ false,
+ configured.clone(),
+ &[macbook.clone(), airpods.clone()].into(),
+ Some(airpods.clone()),
+ &HashSet::new(),
+ );
+ assert_eq!(inputs, vec![macbook]);
+ assert_eq!(source, "configured");
+ // Lid closed: the chosen mic is gone, so follow the meeting app's mic.
+ let (inputs, source) = select_meeting_inputs(
+ vec![airpods.clone()],
+ false,
+ configured,
+ &[airpods.clone()].into(),
+ Some(airpods.clone()),
+ &HashSet::new(),
+ );
+ assert_eq!(inputs, vec![airpods]);
+ assert_eq!(source, "process");
+ }
+
#[test]
fn unresolved_meeting_keeps_its_fallback_mic_across_tap_gaps_and_releases_at_end() {
let bt = "soundcore Liberty 4 Pro (input)".to_string();
diff --git a/crates/screenpipe-engine/src/meeting_watcher/mod.rs b/crates/screenpipe-engine/src/meeting_watcher/mod.rs
index a526c0ce9..3d9ed73d8 100644
--- a/crates/screenpipe-engine/src/meeting_watcher/mod.rs
+++ b/crates/screenpipe-engine/src/meeting_watcher/mod.rs
@@ -28,7 +28,19 @@ pub use ui_scan::run_meeting_detection_loop;
use screenpipe_audio::meeting_detector::MeetingDetector;
use screenpipe_db::DatabaseManager;
-use std::sync::atomic::AtomicBool;
+use std::sync::atomic::{AtomicBool, Ordering};
+
+/// Set by the desktop app while no capture session runs (search/UI only).
+/// The CLI always captures and never sets it.
+static CAPTURE_STOPPED: AtomicBool = AtomicBool::new(false);
+
+pub fn set_capture_stopped(stopped: bool) {
+ CAPTURE_STOPPED.store(stopped, Ordering::SeqCst);
+}
+
+pub fn capture_stopped() -> bool {
+ CAPTURE_STOPPED.load(Ordering::SeqCst)
+}
use std::sync::Arc;
use tokio::sync::broadcast;
diff --git a/crates/screenpipe-engine/src/routes/meetings.rs b/crates/screenpipe-engine/src/routes/meetings.rs
index 8f2bec382..4b5d941db 100644
--- a/crates/screenpipe-engine/src/routes/meetings.rs
+++ b/crates/screenpipe-engine/src/routes/meetings.rs
@@ -907,6 +907,15 @@ pub(crate) async fn start_meeting_handler(
State(state): State<Arc<AppState>>,
axum::Json(body): axum::Json<StartMeetingRequest>,
) -> Result<JsonResponse<MeetingRecord>, (StatusCode, JsonResponse<Value>)> {
+ if crate::meeting_watcher::capture_stopped() {
+ return Err((
+ StatusCode::CONFLICT,
+ JsonResponse(json!({
+ "error": "recording_stopped",
+ "message": "Recording is stopped. Start recording to start a meeting.",
+ })),
+ ));
+ }
let app = body.app.as_deref().unwrap_or("manual");
let resumed_existing = body.id.is_some();
diff --git a/crates/screenpipe-engine/tests/endpoint_test.rs b/crates/screenpipe-engine/tests/endpoint_test.rs
index da373f824..2d972ac82 100644
--- a/crates/screenpipe-engine/tests/endpoint_test.rs
+++ b/crates/screenpipe-engine/tests/endpoint_test.rs
@@ -2012,4 +2012,31 @@ mod tests {
"read-only verification must not store OCR boxes"
);
}
+
+ #[tokio::test]
+ async fn manual_meeting_start_is_refused_while_recording_is_stopped() {
+ let (app, db) = setup_test_app().await;
+ let start = || {
+ Request::builder()
+ .method("POST")
+ .uri("/meetings/start")
+ .header("content-type", "application/json")
+ .body(Body::from(r#"{"app":"manual"}"#))
+ .unwrap()
+ };
+
+ screenpipe_engine::meeting_watcher::set_capture_stopped(true);
+ let refused = app.clone().oneshot(start()).await.unwrap();
+ let status = refused.status();
+ let body = to_bytes(refused.into_body(), usize::MAX).await.unwrap();
+ screenpipe_engine::meeting_watcher::set_capture_stopped(false);
+ assert_eq!(status, StatusCode::CONFLICT);
+ let error: TestErrorResponse = serde_json::from_slice(&body).unwrap();
+ assert_eq!(error.error, "recording_stopped");
+ assert!(db.get_most_recent_active_meeting().await.unwrap().is_none());
+
+ let started = app.oneshot(start()).await.unwrap();
+ assert_eq!(started.status(), StatusCode::OK);
+ assert!(db.get_most_recent_active_meeting().await.unwrap().is_some());
+ }
}