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: use normal recording startup when reopening search-only app (#7575)
Ezra Ellette5e229d01841a
diff --git a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts b/apps/screenpipe-app-tauri/e2e/search-only.e2e.tsindex 52d0fa6fc..91ad3aa8d 100644--- a/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts+++ b/apps/screenpipe-app-tauri/e2e/search-only.e2e.ts@@ -142,6 +142,28 @@ for (let cycle = 0; cycle < 2; cycle++) {}, "Reopened capture persists new frames");}+await request(control, "/e2e/search-only/quit", "POST");+await until(async () => {+ const s = await state();+ return s.search_only && !s.entering && !s.capture_running;+}, "Quit before retained-server failure");+const beforeServerStop = await counts();+assert.equal(+ (await request(control, "/e2e/search-only/stop-server", "POST")).stopped,+ true,+ "Stop the retained server through the normal lifecycle owner",+);+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;+}, "Reopen starts the server and capture when the retained server is absent");+assert.equal((await state()).pid, initial.pid);+await until(async () => {+ const resumed = await counts();+ return Date.parse(resumed.lastFrame) > Date.parse(beforeServerStop.lastFrame);+}, "Reopen after server loss persists new frames");+await request(control, "/e2e/search-only/quit", "POST");await until(async () => {const s = await state();@@ -197,5 +219,5 @@ await until(async () => {}}, "Updater relaunch while recording restores recording");console.log(- "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",+ "PASS: Quit/search/reopen resumes and persists frames in the same PID, including after retained-server loss; Quit blocks captures and mutations; updater relaunch preserves paused search or active recording",);diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex 6f513cb9f..f9a3659a9 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1136,7 +1136,7 @@ async fn main() {return;}if !crate::enterprise_policy::is_app_ui_hidden() && !login_duplicate {- if crate::search_only::is_active() {+ if crate::search_only::needs_wake() {crate::headless::wake_from_tray(&app_for_closure);}match deep_link::handoff_window(deep_link_url.as_deref()) {@@ -2688,7 +2688,7 @@ async fn main() {#[cfg(target_os = "macos")]fn manual_reopen(app: &tauri::AppHandle) {- if crate::search_only::is_active() {+ if crate::search_only::needs_wake() {crate::headless::wake_from_tray(app);}if crate::enterprise_policy::is_app_ui_hidden() || crate::headless::is_dormant() {diff --git a/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs b/apps/screenpipe-app-tauri/src-tauri/src/search_only.rsindex 8606d4800..b0fbe2037 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/search_only.rs@@ -22,7 +22,6 @@ const SESSION_FILE: &str = "search-session.json";struct Session {capture_paused: bool,resume_search_only: bool,- restart_pending: bool,}pub fn is_active() -> bool {@@ -33,6 +32,11 @@ pub fn capture_paused() -> bool {CAPTURE_PAUSED.load(Ordering::SeqCst)}+/// Quit state may outlive the hidden UI after an older updater handoff.+pub fn needs_wake() -> bool {+ is_active() || capture_paused()+}+pub fn is_entering() -> bool {ENTERING.load(Ordering::SeqCst)}@@ -67,7 +71,6 @@ fn persist(restart_pending: bool) -> Result<(), String> {&Session {capture_paused: capture_paused(),resume_search_only: restart_pending && is_active(),- restart_pending,},)}@@ -78,11 +81,13 @@ fn diagnostic(event: &str, detail: &str) {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;- }+ let was_paused = session.capture_paused;+ // Only a launch that stays in search-only mode retains Quit's pause.+ // A normal UI launch, including an updater handoff, starts recording just+ // like a fresh launch. OS login keeps a previously quit app in the background.+ session.resume_search_only =+ session.capture_paused && (from_autostart || session.resume_search_only);+ session.capture_paused = session.resume_search_only;persist_at(root,&Session {@@ -90,11 +95,25 @@ fn restore_at(root: &Path, from_autostart: bool) -> Result<Session, String> {..Session::default()},)?;+ if was_paused {+ crate::recording::recovery_log::append(+ root,+ "search_session_restored",+ &format!(+ "autostart={from_autostart}; outcome={}",+ if session.resume_search_only {+ "search_only"+ } else {+ "normal_startup"+ },+ ),+ );+ }Ok(session)}-/// Resolve Quit's pause before startup publishes capture intent. Updater-/// handoffs retain search-only mode; manual launches resume normal recording.+/// Resolve Quit's pause before startup publishes capture intent. Only launches+/// that retain search-only mode stay paused; normal launches start recording.pub fn initialize(from_autostart: bool) -> bool {let session =restore_at(&crate::config::app_data_dir(), from_autostart).unwrap_or_else(|error| {@@ -139,7 +158,7 @@ pub fn wake(app: &AppHandle) -> bool {if crate::manual_handoff::pending() {return false;}- if ENTERING.load(Ordering::SeqCst) || !is_active() {+ if ENTERING.load(Ordering::SeqCst) || !needs_wake() {return false;}screenpipe_core::background_work::set_suspended(false);@@ -149,20 +168,35 @@ pub fn wake(app: &AppHandle) -> bool {}// Publish intent before scheduling work. The capture helper rechecks it// under the capture lock, so a later Stop or Quit wins over this request.+ let store = crate::store::SettingsStore::get(app)+ .ok()+ .flatten()+ .unwrap_or_default();+ let capture_allowed = crate::recording::recording_access_allowed(app, &store);app.state::<crate::recording::RecordingState>()- .set_capture_intent(true);+ .set_capture_intent(capture_allowed);diagnostic("search_reopen_resume_requested",- "source=manual_reopen; outcome=start_requested",+ if capture_allowed {+ "source=manual_reopen; outcome=start_requested"+ } else {+ "source=manual_reopen; outcome=recording_access_required"+ },);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- {+ let state = app.state::<crate::recording::RecordingState>();+ let _lifecycle = state.server_lifecycle.lock().await;+ if !state.capture_intended() {+ return;+ }+ // Use normal startup so an absent or unhealthy retained server can+ // recover too. Do not publish intent again after a later Stop or Quit.+ // Reopening is a fresh user start, not another automated restart.+ // Otherwise the restart cooldown can accept a healthy search server+ // without ever starting its stopped capture session.+ state.last_spawn_epoch.store(0, Ordering::SeqCst);+ if let Err(error) = crate::recording::spawn_screenpipe_inner(&state, app.clone()).await {report_reopen_failure(&crate::config::app_data_dir(), &error);}});@@ -348,7 +382,6 @@ mod tests {&Session {capture_paused: true,resume_search_only: true,- ..Session::default()},).unwrap();@@ -371,28 +404,52 @@ mod tests {},).unwrap();- assert!(restore_at(dir.path(), true).unwrap().capture_paused);+ let login = restore_at(dir.path(), true).unwrap();+ assert!(login.capture_paused);+ assert!(+ login.resume_search_only,+ "login must not open a normal but paused app"+ );assert!(!restore_at(dir.path(), false).unwrap().capture_paused);assert!(!restore_at(dir.path(), false).unwrap().capture_paused);}+ #[tokio::test]+ async fn normal_updater_launch_clears_legacy_quit_pause() {+ let dir = tempfile::tempdir().unwrap();+ // The previous version wrote this exact state after updating with the+ // normal UI open. Its restart marker must not strand capture again.+ std::fs::write(+ dir.path().join(SESSION_FILE),+ br#"{"capture_paused":true,"resume_search_only":false,"restart_pending":true}"#,+ )+ .unwrap();+ let updated = restore_at(dir.path(), false).unwrap();+ assert!(!updated.capture_paused);+ assert!(!updated.resume_search_only);+ assert!(!load_at(dir.path()).unwrap().capture_paused);+ assert!(!restore_at(dir.path(), false).unwrap().capture_paused);+ let report = crate::diagnostic_logs::collect_redacted_from_dirs(&[dir.path().into()])+ .await+ .unwrap();+ assert!(report.contains("search_session_restored"));+ assert!(report.contains("autostart=false; outcome=normal_startup"));+ }+#[test]- fn updater_preserves_pause_even_with_the_ui_open() {+ fn stale_search_restart_marker_does_not_pause_a_normal_launch() {let dir = tempfile::tempdir().unwrap();persist_at(dir.path(),&Session {- capture_paused: true,- restart_pending: true,- ..Session::default()+ capture_paused: false,+ resume_search_only: true,},).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);+ let launched = restore_at(dir.path(), false).unwrap();+ assert!(!launched.capture_paused);+ assert!(!launched.resume_search_only);}#[test]@@ -412,7 +469,6 @@ mod tests {&Session {capture_paused: true,resume_search_only: true,- ..Session::default()},).unwrap_err();diff --git a/apps/screenpipe-app-tauri/src-tauri/src/server.rs b/apps/screenpipe-app-tauri/src-tauri/src/server.rsindex 1aef1ca8b..d254e7667 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/server.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/server.rs@@ -177,7 +177,7 @@ async fn handle_focus(payload.deep_link_url.as_deref(),payload.target.as_deref(),);- if !startup_handoff && crate::search_only::is_active() {+ if !startup_handoff && crate::search_only::needs_wake() {crate::headless::wake_from_tray(&state.app_handle);}if startup_handoff {@@ -379,6 +379,7 @@ pub async fn run_server(app_handle: tauri::AppHandle, port: u16) {.route("/e2e/search-only/quit", axum::routing::post(e2e_search_only_quit)).route("/e2e/search-only/reopen", axum::routing::post(e2e_search_only_reopen)).route("/e2e/search-only/resume", axum::routing::post(e2e_search_only_resume))+ .route("/e2e/search-only/stop-server", axum::routing::post(e2e_search_only_stop_server)).route("/e2e/search-only/restart", axum::routing::post(e2e_search_only_restart)).route("/e2e/updates/state", axum::routing::get(e2e_updates_state)).route("/e2e/updates/click", axum::routing::post(e2e_updates_click))@@ -724,6 +725,13 @@ async fn e2e_search_only_resume(State(state): State<ServerState>) -> impl IntoReJson(serde_json::json!({"resumed": result.is_ok(), "error": result.err()}))}+#[cfg(feature = "e2e")]+async fn e2e_search_only_stop_server(State(state): State<ServerState>) -> impl IntoResponse {+ use tauri::Manager;+ let result = crate::recording::stop_screenpipe(state.app_handle.state(), state.app_handle.clone()).await;+ Json(serde_json::json!({"stopped": result.is_ok(), "error": result.err()}))+}+#[cfg(feature = "e2e")]async fn e2e_search_only_restart(State(state): State<ServerState>) -> impl IntoResponse {let result = crate::updates::restart_for_update(state.app_handle, Some(10)).await;diff --git a/docs/TESTING.md b/docs/TESTING.mdindex e35671a09..761fa1ace 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -305,7 +305,7 @@ commits: `94531265`, `d794176a`, `9070639c`, `0378cab1`, `4a3313d3`, `7ffdd4f1`,- [ ] **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; 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.+- [ ] **restart app** — settings and recording authorization are preserved. A search-only updater restart restores hidden UI and paused capture; every transition to the normal app uses normal recording startup. An updater launch with the UI open must clear a legacy Quit pause, including persisted `restart_pending: true`. Reopening also recovers a missing or unhealthy retained server. OS login after Quit stays in background search mode until the app is opened. 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`)