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: resume recording when reopening after Quit
Ezra Elletted9cd47c53087
diff --git a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts b/apps/screenpipe-app-tauri/e2e/search-only.e2e.tsindex cba673e90..52d0fa6fc 100644--- a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts+++ b/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts@@ -60,6 +60,7 @@ const counts = async () => {history,framesWritten: health.pipeline?.frames_db_written,uiEvents: health.ui_recorder?.events_inserted,+ lastFrame: health.last_frame_timestamp,lastAudio: health.last_audio_timestamp,};};@@ -127,20 +128,18 @@ for (let cycle = 0; cycle < 2; cycle++) {async () => (await state()).webviews.includes("home"),"Reopen shows Home",);- const reopened = await state();- assert.equal(reopened.pid, initial.pid);- assert(- !reopened.capture_running && !reopened.capture_intended,- "Reopen must leave capture paused",- );- assert(- (await request(control, "/e2e/search-only/resume", "POST")).resumed,- "Explicit resume works",- );await until(- async () => (await state()).capture_running,- "Recording resumes explicitly",+ async () => {+ const s = await state();+ return s.capture_running && s.capture_intended;+ },+ "Reopening resumes recording without a separate Start action",);+ assert.equal((await state()).pid, initial.pid);+ await until(async () => {+ const resumed = await counts();+ return Date.parse(resumed.lastFrame) > Date.parse(stopped.lastFrame);+ }, "Reopened capture persists new frames");}await request(control, "/e2e/search-only/quit", "POST");@@ -178,6 +177,25 @@ assert.deepEqual(beforeRestart,"Relaunch creates no captures",);+await request(control, "/e2e/search-only/reopen", "POST");+await until(async () => {+ const s = await state();+ return !s.search_only && s.capture_running && s.capture_intended;+}, "Manual reopen after an updater restart resumes capture");+const recordingBeforeUpdate = await state();+await request(control, "/e2e/search-only/restart", "POST");+await until(async () => {+ try {+ const s = await state();+ return (+ s.pid !== recordingBeforeUpdate.pid &&+ s.capture_intended &&+ s.capture_running+ );+ } catch {+ return false;+ }+}, "Updater relaunch while recording restores recording");console.log(- "PASS: two Quit/search/reopen/resume cycles, same PID, stable capture counts, blocked mutations, updater relaunch restores search with recording paused",+ "PASS: two Quit/search/reopen cycles resume and persist frames in the same PID; Quit blocks captures and mutations; updater relaunch preserves paused search or active recording",);diff --git a/apps/screenpipe-app-tauri/src-tauri/src/headless.rs b/apps/screenpipe-app-tauri/src-tauri/src/headless.rsindex 88e1fea38..1e2e4444b 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/headless.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/headless.rs@@ -246,7 +246,7 @@ pub fn wake_from_tray(app: &AppHandle) -> bool {if crate::enterprise_policy::is_app_ui_hidden() || crate::search_only::is_entering() {return false;}- crate::search_only::wake();+ crate::search_only::wake(app);if !UI_DORMANT.swap(false, Ordering::SeqCst) {return false;}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex ec45badfe..c720c3ad8 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1406,7 +1406,7 @@ async fn main() {);std::io::Error::other(e)})?;- let search_only_startup = crate::search_only::initialize();+ let search_only_startup = crate::search_only::initialize(from_autostart);#[cfg(feature = "e2e")]e2e::seeds::apply_settings(app.handle(), &mut store);diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording.rsindex e051d063f..9a405198e 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs@@ -1865,7 +1865,7 @@ async fn spawn_screenpipe_after_migration(////// Lock-first pattern matches `start_capture` so a concurrent `start_capture`/// can't build a parallel session and clobber ours.-async fn start_capture_internal(+pub(crate) async fn start_capture_internal(state: &RecordingState,app: &tauri::AppHandle,) -> Result<(), String> {diff --git a/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs b/apps/screenpipe-app-tauri/src-tauri/src/search_only.rsindex 48dc7db47..23d8bcc99 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs@@ -22,6 +22,7 @@ const SESSION_FILE: &str = "search-session.json";struct Session {capture_paused: bool,resume_search_only: bool,+ restart_pending: bool,}pub fn is_active() -> bool {@@ -59,13 +60,14 @@ fn load_at(root: &Path) -> Result<Session, String> {}}-fn persist(resume_search_only: bool) -> Result<(), String> {+fn persist(restart_pending: bool) -> Result<(), String> {let _guard = SESSION_LOCK.lock().unwrap_or_else(|e| e.into_inner());persist_at(&crate::config::app_data_dir(),&Session {capture_paused: capture_paused(),- resume_search_only,+ resume_search_only: restart_pending && is_active(),+ restart_pending,},)}@@ -74,30 +76,40 @@ fn diagnostic(event: &str, detail: &str) {crate::recording::recovery_log::append(&crate::config::app_data_dir(), event, detail);}-/// Restore stopped capture before any native startup or UI callback can run.-/// Only an updater/relaunch handoff restores hidden UI; a later manual launch-/// after a normal process exit opens the UI with recording still stopped.-pub fn initialize() -> bool {- let session = load_at(&crate::config::app_data_dir()).unwrap_or_else(|error| {- diagnostic(- "search_session_read_failed",- &format!("cause={error}; outcome=capture_paused"),- );- Session {- capture_paused: true,- resume_search_only: false,- }- });+fn restore_at(root: &Path, from_autostart: bool) -> Result<Session, String> {+ let mut session = load_at(root)?;+ // A restart handoff preserves Quit's pause for one launch. A subsequent+ // manual launch is a request to record again; OS login is not.+ if !from_autostart && !session.restart_pending && !session.resume_search_only {+ session.capture_paused = false;+ }+ persist_at(+ root,+ &Session {+ capture_paused: session.capture_paused,+ ..Session::default()+ },+ )?;+ Ok(session)+}++/// Resolve Quit's pause before startup publishes capture intent. Updater+/// handoffs retain search-only mode; manual launches resume normal recording.+pub fn initialize(from_autostart: bool) -> bool {+ let session =+ restore_at(&crate::config::app_data_dir(), from_autostart).unwrap_or_else(|error| {+ diagnostic(+ "search_session_restore_failed",+ &format!("cause={error}; outcome=capture_paused"),+ );+ Session {+ capture_paused: true,+ ..Session::default()+ }+ });CAPTURE_PAUSED.store(session.capture_paused, Ordering::SeqCst);let background = session.capture_paused && session.resume_search_only;screenpipe_core::background_work::set_suspended(background);- if let Err(error) = persist(false) {- diagnostic(- "search_session_restore_failed",- &format!("cause={error}; outcome=capture_paused"),- );- CAPTURE_PAUSED.store(true, Ordering::SeqCst);- }background}@@ -120,18 +132,51 @@ pub fn resume_capture() -> Result<(), String> {Ok(())}-/// Opening a window restores ordinary background work, never capture intent.-pub fn wake() -> bool {+/// An explicit reopen ends Quit's pause, using the existing capture owner.+/// Ordinary window opens while already awake do not undo a recording pause.+pub fn wake(app: &AppHandle) -> bool {if ENTERING.load(Ordering::SeqCst) || !is_active() {return false;}screenpipe_core::background_work::set_suspended(false);- info!("search-only: UI reopened; recording remains paused");+ if let Err(error) = resume_capture() {+ report_reopen_failure(&crate::config::app_data_dir(), &error);+ return true;+ }+ // Publish intent before scheduling work. The capture helper rechecks it+ // under the capture lock, so a later Stop or Quit wins over this request.+ app.state::<crate::recording::RecordingState>()+ .set_capture_intent(true);+ diagnostic(+ "search_reopen_resume_requested",+ "source=manual_reopen; outcome=start_requested",+ );+ let app = app.clone();+ tauri::async_runtime::spawn(async move {+ if let Err(error) = crate::recording::start_capture_internal(+ &app.state::<crate::recording::RecordingState>(),+ &app,+ )+ .await+ {+ report_reopen_failure(&crate::config::app_data_dir(), &error);+ }+ });+ info!("search-only: UI reopened; recording resume requested");true}+fn report_reopen_failure(root: &Path, error: &str) {+ warn!("search-only: recording could not resume after reopening: {error}");+ crate::recording::recovery_log::append(+ root,+ "search_reopen_failed",+ &format!("cause={error}; outcome=resume_failed"),+ );+}+pub fn prepare_restart() -> Result<(), String> {- persist(is_active()).map_err(|error| {+ persist(true).map_err(|error| {diagnostic("search_restart_persist_failed",&format!("cause={error}; outcome=restart_deferred"),@@ -285,7 +330,7 @@ mod tests {use super::*;#[test]- fn restart_snapshot_keeps_capture_off_and_is_consumed_without_clearing_pause() {+ fn updater_preserves_pause_once_then_manual_launch_resumes() {let dir = tempfile::tempdir().unwrap();assert!(!load_at(dir.path()).unwrap().capture_paused);persist_at(@@ -293,31 +338,58 @@ mod tests {&Session {capture_paused: true,resume_search_only: true,+ ..Session::default()},).unwrap();- let restored = load_at(dir.path()).unwrap();+ let restored = restore_at(dir.path(), false).unwrap();assert!(restored.capture_paused && restored.resume_search_only);+ let manual = restore_at(dir.path(), false).unwrap();+ assert!(!manual.capture_paused);+ assert!(!manual.resume_search_only);+ assert!(!load_at(dir.path()).unwrap().capture_paused);+ }++ #[test]+ fn manual_launch_clears_quit_pause_but_login_does_not() {+ let dir = tempfile::tempdir().unwrap();persist_at(dir.path(),&Session {- resume_search_only: false,- ..restored+ capture_paused: true,+ ..Session::default()},).unwrap();- let manual = load_at(dir.path()).unwrap();- assert!(manual.capture_paused);- assert!(!manual.resume_search_only);- persist_at(dir.path(), &Session::default()).unwrap();- assert!(!load_at(dir.path()).unwrap().capture_paused);+ assert!(restore_at(dir.path(), true).unwrap().capture_paused);+ assert!(!restore_at(dir.path(), false).unwrap().capture_paused);+ assert!(!restore_at(dir.path(), false).unwrap().capture_paused);+ }++ #[test]+ fn updater_preserves_pause_even_with_the_ui_open() {+ let dir = tempfile::tempdir().unwrap();+ persist_at(+ dir.path(),+ &Session {+ capture_paused: true,+ restart_pending: true,+ ..Session::default()+ },+ )+ .unwrap();+ let updated = restore_at(dir.path(), false).unwrap();+ assert!(updated.capture_paused);+ assert!(!updated.resume_search_only);+ assert!(!load_at(dir.path()).unwrap().restart_pending);+ assert!(!restore_at(dir.path(), false).unwrap().capture_paused);}#[test]fn damaged_session_is_an_error_not_permission_to_record() {let dir = tempfile::tempdir().unwrap();std::fs::write(dir.path().join(SESSION_FILE), b"{interrupted").unwrap();- assert!(load_at(dir.path()).is_err());+ assert!(restore_at(dir.path(), false).is_err());}#[tokio::test]@@ -330,6 +402,7 @@ mod tests {&Session {capture_paused: true,resume_search_only: true,+ ..Session::default()},).unwrap_err();@@ -357,4 +430,27 @@ mod tests {assert!(report.contains(&cause));assert!(!report.contains("[email protected]"));}++ #[tokio::test]+ async fn reopen_persistence_failure_reaches_collected_redacted_report() {+ let dir = tempfile::tempdir().unwrap();+ std::fs::create_dir(dir.path().join(SESSION_FILE)).unwrap();+ let cause = persist_at(dir.path(), &Session::default()).unwrap_err();+ report_reopen_failure(dir.path(), &cause);+ for day in 1..=7 {+ std::fs::write(+ dir.path()+ .join(format!("screenpipe-app.2026-10-{day:02}.log")),+ "restarted\n",+ )+ .unwrap();+ }+ let report =+ crate::diagnostic_logs::collect_redacted_from_dirs(&[dir.path().to_path_buf()])+ .await+ .unwrap();+ assert!(report.contains("search_reopen_failed"));+ assert!(report.contains("outcome=resume_failed"));+ assert!(report.contains(&cause));+ }}diff --git a/docs/TESTING.md b/docs/TESTING.mdindex a43f24558..e35671a09 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -299,13 +299,13 @@ commits: `d9d43d31`, `620c89a5`, `14acf6f0`commits: `94531265`, `d794176a`, `9070639c`, `0378cab1`, `4a3313d3`, `7ffdd4f1`, `1b36f62d`-- [ ] **Quit keeps search available (default On)** — preserve the existing recording-aware Quit / Minimize to Tray / Cancel dialog for tray, dock, and Cmd+Q. Cancel changes nothing; Minimize retains recording and the tray. Confirmed Quit stops screen/audio/UI capture, destroys webviews, and hides the tray and dock. A saved-history request still succeeds through the same API; attempts to start capture or workflows fail. Reopen into the same PID with capture paused and the tray restored, then explicitly resume. Repeat after sleep/wake and an update restart. Check idle CPU/memory and that recording devices and child agents are released.+- [ ] **Quit keeps search available (default On)** — preserve the existing recording-aware Quit / Minimize to Tray / Cancel dialog for tray, dock, and Cmd+Q. Cancel changes nothing; Minimize retains recording and the tray. Confirmed Quit stops screen/audio/UI capture, destroys webviews, and hides the tray and dock. A saved-history request still succeeds through the same API; attempts to start capture or workflows fail. Manually reopen into the same PID: restore the tray and resume recording without a separate Start action. A later Stop or Quit must win over pending resume. Ordinary window opens must not undo a pause made through recording controls. Repeat after sleep/wake and an update restart. Check idle CPU/memory and that recording devices and child agents are released.- [ ] **clean quit via tray (Keep search available after quitting Off)** — right-click tray → Quit. all processes terminate. no orphaned ffmpeg/bun processes. Explicit Off survives restart; OS logout/shutdown exits regardless of the setting.- [ ] **clean quit via dock** — right-click dock → Quit. same as above.- [ ] **clean quit via Cmd+Q** — same verification.- [ ] **force quit recovery** — force quit app. relaunch. database is intact. recording resumes.- [ ] **sleep/wake** — close laptop lid, wait 10s, open. recording resumes within 5s. no crash (`9070639c`).-- [ ] **restart app** — settings and recording authorization are preserved. A search-only updater restart restores hidden UI and paused capture; reopening does not authorize recording. Failed shutdown defers the update, and the originating cause survives in the collected/redacted support report. If Quit cannot safely retain search, it falls back to a full exit.+- [ ] **restart app** — settings and recording authorization are preserved. A search-only updater restart restores hidden UI and paused capture; a subsequent manual launch or reopen resumes recording. OS login alone must not clear Quit's pause. Failed shutdown defers the update, and the originating cause survives in the collected/redacted support report, as must a failure to resume on reopening. If Quit cannot safely retain search, it falls back to a full exit.- [ ] **Cross-platform autorelease pool** — Verify that Windows and Linux builds compile and run without issues related to macOS-specific autorelease pool calls. (`851b3037c`)- [ ] **Main thread safety (macOS)** — Verify that tray icon operations, space monitoring, and frontmost app restoration are dispatched to the main thread to prevent crashes. (`ac46aa437`, `418826dfa`, `274826dfa`)- [ ] **ObjC memory management (macOS)** — Verify that all ObjC operations are wrapped in scoped autorelease pools and objects are retained in async callbacks to prevent use-after-free or SIGSEGV crashes. (`4cb9850f7`, `c49350df0`, `139500d52`)