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(app): keep closed Home hidden after recovery restarts (#7408)

Ezra Ellette7bdc36596ee0
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
index 53e6efb7b..895431d6c 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs
@@ -1411,6 +1411,7 @@ mod tests {
"target=99.0.0",
"relaunch_observed",
"running=1.0.0",
+ "home_visible=Some(false)",
"outcome=Failed",
] {
assert!(bundle.contains(expected), "missing {expected}: {bundle}");
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 1b62d26fe..865eefd1d 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -467,6 +467,7 @@ macro_rules! define_specta_builder {
#[tokio::main]
async fn main() {
+ let relaunch_home_visible = process_exit::take_relaunch_home_visibility();
// Handle private ACP subprocess modes before Tauri initializes. The
// protocol host lives in core; desktop contributes only schedule projection.
if let Some(exit_code) = screenpipe_core::agents::acp::run_hidden_mode(Arc::new(
@@ -1679,18 +1680,27 @@ async fn main() {
info!("launched from OS startup enrollment; starting in background");
}
- // Show onboarding/home unless managed background agent, or login
- // autostart (tray + server only; UI via tray/dock/shortcut).
+ // Recovery and update restarts preserve Home visibility; explicit
+ // restarts show Home, and login-autostart defaults to background.
// Incomplete onboarding still shows so required enterprise access
// can finish; an authenticated login launch skips Home below.
+ let restart_home_visible = relaunch_home_visible
+ .or_else(|| updates::update_startup_home_visibility(&app_handle));
if app_ui_hidden {
info!("enterprise: hidden UI mode active, skipping startup app windows");
} else if headless_startup {
info!("headless: starting with UI dormant; use the tray to open screenpipe");
} else if !onboarding_store.is_completed {
let _ = ShowRewindWindow::Onboarding.show(&app.handle());
- } else if from_autostart {
- info!("autostart: skipping Home window (background login launch)");
+ } else if !restart_home_visible.unwrap_or(!from_autostart) {
+ info!("background launch: skipping Home window (restart_home_visible={restart_home_visible:?}, autostart={from_autostart})");
+ if restart_home_visible == Some(false) {
+ recording::recovery_log::append(
+ &db_relaunch::active_data_dir(),
+ "startup_window_restore",
+ "outcome=home_kept_closed",
+ );
+ }
} else {
let _ = ShowRewindWindow::Home { page: None }.show(&app.handle());
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs b/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs
index 7261189dd..96b5c6c70 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs
@@ -274,6 +274,42 @@ fn relaunch_binary(app: &AppHandle) -> Option<PathBuf> {
Some(current_binary)
}
+const RELAUNCH_HOME_VISIBLE: &str = "SCREENPIPE_RELAUNCH_HOME_VISIBLE";
+
+pub(crate) fn home_window_visible(app: &AppHandle) -> Option<bool> {
+ match app.get_webview_window("home") {
+ Some(window) => window
+ .is_visible()
+ .and_then(|visible| window.is_minimized().map(|minimized| visible && !minimized))
+ .ok(),
+ None => Some(false),
+ }
+}
+
+/// Consume before spawning any children, so a later ordinary launch cannot
+/// inherit the previous recovery's window preference.
+pub(crate) fn take_relaunch_home_visibility() -> Option<bool> {
+ let value = std::env::var(RELAUNCH_HOME_VISIBLE).ok();
+ std::env::remove_var(RELAUNCH_HOME_VISIBLE);
+ value.and_then(|value| value.parse().ok())
+}
+
+pub(crate) fn configure_relaunch_home(
+ command: &mut Command,
+ visible: Option<bool>,
+ data_dir: &std::path::Path,
+) {
+ command.env_remove(RELAUNCH_HOME_VISIBLE);
+ if let Some(visible) = visible {
+ command.env(RELAUNCH_HOME_VISIBLE, visible.to_string());
+ }
+ crate::recording::recovery_log::append(
+ data_dir,
+ "relaunch_window_state",
+ &format!("home_visible={visible:?}"),
+ );
+}
+
/// Spawn a replacement app process, then terminate the current process without
/// running C/C++ atexit handlers. Tauri's built-in restart uses
/// `std::process::exit`, which can abort in ORT/ggml teardown after the new app
@@ -282,6 +318,10 @@ fn relaunch_binary(app: &AppHandle) -> Option<PathBuf> {
/// The replacement gets its own process group: launchd kills a job's whole
/// process group when the job exits, so an inherited group dies with us.
pub fn force_app_relaunch(app: AppHandle, status: i32) -> ! {
+ force_app_relaunch_with_home(app, status, Some(true))
+}
+
+fn force_app_relaunch_with_home(app: AppHandle, status: i32, home_visible: Option<bool>) -> ! {
// Apply a staged update now, at the last moment before this process goes
// away — installing any earlier orphans the running bundle and kills TCC
// attribution (see staged_update.rs). Idempotent with the RunEvent::Exit
@@ -326,6 +366,11 @@ pub fn force_app_relaunch(app: AppHandle, status: i32) -> ! {
// Startup repoints this variable at recordings. A replacement app must
// reopen the original settings store before selecting recordings again.
command.env("SCREENPIPE_DATA_DIR", crate::config::app_data_dir());
+ configure_relaunch_home(
+ &mut command,
+ home_visible,
+ &crate::db_relaunch::active_data_dir(),
+ );
#[cfg(unix)]
{
use std::os::unix::process::CommandExt;
@@ -365,7 +410,18 @@ pub fn request_app_relaunch(app: AppHandle, reason: &'static str, delay: Duratio
warn!("relaunch deferred: could not preserve recording mode: {error}");
return;
}
- request_prepared_app_relaunch(app, reason, delay);
+ request_prepared_relaunch_with_home(app, reason, delay, Some(true));
+}
+
+/// Automatic recovery must not bring back a window the user closed. Explicit
+/// restarts continue through request_app_relaunch with normal startup behavior.
+pub(crate) fn request_recovery_relaunch(app: AppHandle, reason: &'static str, delay: Duration) {
+ if let Err(error) = crate::search_only::prepare_restart() {
+ warn!("relaunch deferred: could not preserve recording mode: {error}");
+ return;
+ }
+ let home_visible = home_window_visible(&app);
+ request_prepared_relaunch_with_home(app, reason, delay, home_visible);
}
/// Updater callers already persisted the session before draining the server.
@@ -374,13 +430,27 @@ pub(crate) fn request_prepared_app_relaunch(
app: AppHandle,
reason: &'static str,
delay: Duration,
+) {
+ request_prepared_relaunch_with_home(app, reason, delay, None);
+}
+
+fn request_prepared_relaunch_with_home(
+ app: AppHandle,
+ reason: &'static str,
+ delay: Duration,
+ home_visible: Option<bool>,
) {
QUIT_REQUESTED.store(true, Ordering::SeqCst);
std::thread::spawn(move || {
std::thread::sleep(delay);
info!("safe relaunch requested: {reason}");
- force_app_relaunch(app, 0);
+ crate::recording::recovery_log::append(
+ &crate::db_relaunch::active_data_dir(),
+ "app_relaunch_requested",
+ reason,
+ );
+ force_app_relaunch_with_home(app, 0, home_visible);
});
}
@@ -772,6 +842,52 @@ pub(crate) fn request_full_app_quit(app: AppHandle) {
mod tests {
use super::{extract_cf_bundle_executable, macos_updater_relaunch_command};
+ #[test]
+ fn relaunch_home_visibility_child() {
+ let Ok(expected) = std::env::var("SCREENPIPE_TEST_RELAUNCH_HOME") else {
+ return;
+ };
+ assert_eq!(super::take_relaunch_home_visibility(), expected.parse().ok());
+ assert_eq!(super::take_relaunch_home_visibility(), None);
+ assert!(std::env::var_os(super::RELAUNCH_HOME_VISIBLE).is_none());
+ }
+
+ #[test]
+ fn recovery_relaunch_home_visibility_crosses_process_boundary_once() {
+ let root = tempfile::tempdir().unwrap();
+ for (scenario, visible) in [
+ ("closed recovery", Some(false)),
+ ("visible recovery", Some(true)),
+ ("explicit restart", Some(true)),
+ ("ordinary quit and reopen", None),
+ ] {
+ let mut command = std::process::Command::new(std::env::current_exe().unwrap());
+ command
+ .args(["--exact", "process_exit::tests::relaunch_home_visibility_child"])
+ .env(
+ "SCREENPIPE_TEST_RELAUNCH_HOME",
+ visible.map_or("none", |v| if v { "true" } else { "false" }),
+ )
+ // A fresh snapshot must replace any stale inherited preference.
+ .env(super::RELAUNCH_HOME_VISIBLE, (!visible.unwrap_or(false)).to_string());
+ super::configure_relaunch_home(&mut command, visible, root.path());
+ let output = command.output().unwrap();
+ assert!(
+ output.status.success(),
+ "{scenario}: {}\n{}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr),
+ );
+ }
+ let output = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["--exact", "process_exit::tests::relaunch_home_visibility_child"])
+ .env("SCREENPIPE_TEST_RELAUNCH_HOME", "none")
+ .env(super::RELAUNCH_HOME_VISIBLE, "invalid")
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ }
+
#[test]
fn extracts_bundle_executable_from_xml_plist() {
let plist = r#"
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
index 22418c419..77b2beeaf 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs
@@ -1999,6 +1999,11 @@ mod shutdown_storage_tests {
"engine_started",
"old and new recording payloads verified after database reopen",
);
+ crate::process_exit::configure_relaunch_home(
+ &mut std::process::Command::new("unused-test-replacement"),
+ Some(false),
+ root.path(),
+ );
// Simulate app-log rotation/restart and enough noisy logs to fill
// the normal five-file support limit. Lifecycle evidence persists.
for day in 1..=7 {
@@ -2017,6 +2022,7 @@ mod shutdown_storage_tests {
assert!(report.contains("cleanup continues and database reopen must wait"));
assert!(report.contains("shutdown_completed"));
assert!(report.contains("engine_started"));
+ assert!(report.contains("relaunch_window_state: home_visible=Some(false)"));
assert!(!report.contains("hunter2"));
}
}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording/db_wedge.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording/db_wedge.rs
index 62e03de78..236806a9a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/recording/db_wedge.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording/db_wedge.rs
@@ -284,7 +284,7 @@ async fn recover_from_db_wedge(
}
recording_state.is_starting.store(false, Ordering::SeqCst);
recording_state.last_spawn_epoch.store(0, Ordering::SeqCst);
- crate::process_exit::request_app_relaunch(
+ crate::process_exit::request_recovery_relaunch(
app.clone(),
"DB owner shutdown incomplete; relaunch into verification",
Duration::from_millis(250),
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
index a26681e64..3dff8c8da 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -670,6 +670,9 @@ pub struct UpdateAttempt {
pub from_version: String,
pub to_version: String,
pub ts_epoch_secs: u64,
+ /// None for markers written by older builds or if visibility was unavailable.
+ #[serde(default)]
+ pub home_visible: Option<bool>,
}
#[derive(Debug, PartialEq, Eq)]
@@ -715,14 +718,16 @@ fn record_update_attempt(app: &tauri::AppHandle, to_version: &str) {
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0),
+ home_visible: crate::process_exit::home_window_visible(app),
};
crate::update_diagnostics::record(
"restart_committed",
&format!(
- "from={} target={} attempt_ts={} executable={:?}",
+ "from={} target={} attempt_ts={} home_visible={:?} executable={:?}",
attempt.from_version,
attempt.to_version,
attempt.ts_epoch_secs,
+ attempt.home_visible,
std::env::current_exe()
),
);
@@ -736,6 +741,23 @@ fn record_update_attempt(app: &tauri::AppHandle, to_version: &str) {
}
}
+/// Read before showing startup windows. The updater consumes this same marker
+/// later in setup, preserving failed-install detection and one-launch lifetime.
+pub(crate) fn update_startup_home_visibility(app: &tauri::AppHandle) -> Option<bool> {
+ update_startup_home_visibility_at(
+ &update_attempt_marker_path(app)?,
+ &app.package_info().version.to_string(),
+ )
+}
+
+fn update_startup_home_visibility_at(path: &std::path::Path, current: &str) -> Option<bool> {
+ let attempt: UpdateAttempt = serde_json::from_slice(&std::fs::read(path).ok()?).ok()?;
+ if classify_update_attempt(&attempt, current) == UpdateAttemptOutcome::Unrelated {
+ return None;
+ }
+ attempt.home_visible
+}
+
/// Read + delete the marker left by the previous process. Returns the failed
/// attempt when the install demonstrably did not apply; logs the applied /
/// unrelated cases.
@@ -760,11 +782,12 @@ fn consume_update_attempt_at(path: &std::path::Path, current: &str) -> Option<Up
path.parent()?,
"relaunch_observed",
&format!(
- "from={} target={} attempt_ts={} running={} executable={:?} outcome={:?}",
+ "from={} target={} attempt_ts={} running={} home_visible={:?} executable={:?} outcome={:?}",
attempt.from_version,
attempt.to_version,
attempt.ts_epoch_secs,
current,
+ attempt.home_visible,
std::env::current_exe(),
classify_update_attempt(&attempt, &current)
),
@@ -2063,9 +2086,13 @@ pub(crate) mod tests {
let path = root.join(super::UPDATE_ATTEMPT_MARKER_FILE);
std::fs::write(
&path,
- r#"{"from_version":"1.0.0","to_version":"99.0.0","ts_epoch_secs":1}"#,
+ r#"{"from_version":"1.0.0","to_version":"99.0.0","ts_epoch_secs":1,"home_visible":false}"#,
)
.unwrap();
+ assert_eq!(
+ super::update_startup_home_visibility_at(&path, "1.0.0"),
+ Some(false)
+ );
assert!(super::consume_update_attempt_at(&path, "1.0.0").is_some());
assert!(!path.exists());
assert!(super::consume_update_attempt_at(&path, "1.0.0").is_none());
@@ -2075,6 +2102,48 @@ pub(crate) mod tests {
const HOUR: Duration = Duration::from_secs(3600);
+ #[test]
+ fn update_home_visibility_survives_restart_and_is_consumed_once() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join(UPDATE_ATTEMPT_MARKER_FILE);
+ for visible in [false, true] {
+ for running in ["2.6.6", "2.6.7"] {
+ let attempt = UpdateAttempt {
+ from_version: "2.6.6".into(),
+ to_version: "2.6.7".into(),
+ ts_epoch_secs: 1,
+ home_visible: Some(visible),
+ };
+ std::fs::write(&path, serde_json::to_vec(&attempt).unwrap()).unwrap();
+ assert_eq!(
+ update_startup_home_visibility_at(&path, running),
+ Some(visible)
+ );
+ assert_eq!(
+ consume_update_attempt_at(&path, running).is_some(),
+ running == "2.6.6",
+ "window restoration must preserve failed-install detection"
+ );
+ assert_eq!(update_startup_home_visibility_at(&path, running), None);
+ }
+ }
+ }
+
+ #[test]
+ fn update_home_visibility_keeps_normal_startup_for_old_invalid_or_unrelated_markers() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join(UPDATE_ATTEMPT_MARKER_FILE);
+ assert_eq!(update_startup_home_visibility_at(&path, "2.6.7"), None);
+ for raw in [
+ r#"{"from_version":"2.6.6","to_version":"2.6.7","ts_epoch_secs":1}"#,
+ r#"{"from_version":"2.6.5","to_version":"2.6.6","ts_epoch_secs":1,"home_visible":false}"#,
+ "{truncated",
+ ] {
+ std::fs::write(&path, raw).unwrap();
+ assert_eq!(update_startup_home_visibility_at(&path, "2.6.7"), None);
+ }
+ }
+
#[test]
fn sweep_removes_installer_leftovers_only() {
let dir = tempfile::tempdir().unwrap();
@@ -2232,6 +2301,7 @@ pub(crate) mod tests {
from_version: "2.6.77".into(),
to_version: "2.6.81".into(),
ts_epoch_secs: 0,
+ home_visible: None,
};
let cooldown = cooldown_from_failed_attempt(Some(&attempt));
assert!(failed_version_in_cooldown(
@@ -2530,6 +2600,7 @@ pub(crate) mod tests {
from_version: "2.6.6".into(),
to_version: "2.6.7".into(),
ts_epoch_secs: 0,
+ home_visible: None,
};
// Still on the version we tried to leave → the install didn't apply.
assert_eq!(