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(updater): preserve failed installer handoffs and support evidence (#7206)
Ezra Ellette0957f57796da
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 00f7916c1..e7cf55029 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -5922,9 +5922,11 @@ dependencies = ["percent-encoding","pin-project-lite","socket2 0.6.3",+ "system-configuration 0.7.0","tokio","tower-service","tracing",+ "windows-registry 0.5.3",][[package]]@@ -10446,7 +10448,7 @@ dependencies = ["serde_json","serde_urlencoded","sync_wrapper 1.0.2",- "system-configuration",+ "system-configuration 0.6.1","tokio","tokio-native-tls","tokio-rustls",@@ -13831,6 +13833,17 @@ dependencies = ["system-configuration-sys",]+[[package]]+name = "system-configuration"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"+dependencies = [+ "bitflags 2.11.0",+ "core-foundation 0.9.4",+ "system-configuration-sys",+]+[[package]]name = "system-configuration-sys"version = "0.6.0"@@ -14398,9 +14411,9 @@ dependencies = [[[package]]name = "tauri-plugin-updater"-version = "2.10.1"+version = "2.11.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "806d9dac662c2e4594ff03c647a552f2c9bd544e7d0f683ec58f872f952ce4af"+checksum = "b28d8cabdeb0564f03ae261963de4bc3d98321cd3d213e76a81b7d344e5df606"dependencies = ["base64 0.22.1","dirs 6.0.0",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 4f439d734..19fdb3d09 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -46,7 +46,7 @@ tauri-utils = { version = "=2.9.3", features = [] }# pluginstauri-plugin-fs = { version = "=2.4.5", features = ["watch"] }tauri-plugin-notification = "=2.3.3"-tauri-plugin-updater = "=2.10.1"+tauri-plugin-updater = "=2.11.0"# version ordering for the updater's newer-version promotion (#5784 double update)semver = "1"# staged-update signature re-verification (same crate/version the updater plugin uses)@@ -200,7 +200,7 @@ tauri-plugin-webdriver = { version = "0.2", optional = true }[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\"))".dependencies]tauri-plugin-single-instance = { version = "2.3.7", features = ["deep-link"] }-tauri-plugin-updater = "2.10.0"+tauri-plugin-updater = "=2.11.0"[target.'cfg(target_os = "macos")'.dependencies]tracing-oslog = "0.3.0"diff --git a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rsindex 23dc4d343..b94520f08 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs@@ -79,6 +79,7 @@ fn owned_log_files(files: Vec<LogFile>) -> Vec<LogFile> {fn is_screenpipe_owned_log_name(name: &str) -> bool {crate::log_files::is_panic_log(name)|| name == crate::recording::recovery_log::LOG_NAME+ || name == crate::update_diagnostics::LOG_NAME|| matches!(name,"screenpipe.log"diff --git a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rsindex 625cadca8..f6d9a8ff9 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/feedback_upload.rs@@ -1135,6 +1135,79 @@ mod tests {assert_eq!(upload.body, redacted.as_bytes());}+ #[cfg(target_os = "macos")]+ #[tokio::test(flavor = "multi_thread")]+ async fn updater_failure_reaches_support_after_restart_and_rotation() {+ let dir = tempfile::tempdir().unwrap();+ crate::staged_update::tests::failed_install_fixture(dir.path()).await;+ // Simulate the next process consuming its marker, then ordinary log rotation.+ crate::updates::tests::consume_failed_update_fixture(dir.path());+ crate::update_diagnostics::append(dir.path(), "redaction_fixture", "password=hunter2");+ for day in 10..22 {+ std::fs::write(+ dir.path().join(format!("screenpipe-app.2026-09-{day}.log")),+ "restarted\n",+ )+ .unwrap();+ }+ let files = crate::log_files::collect_log_files(&[dir.path().to_path_buf()]).await;+ assert_eq!(files[0].name, crate::update_diagnostics::LOG_NAME);+ let raw = collect_log_text_from_files(files).await;+ let redacted = crate::feedback_redact::redact_pii_for_feedback(raw, "{}".into())+ .await+ .unwrap();+ // The unattended collector must preserve the same failure through its+ // separate owned-file allow-list and stricter five-file limit.+ let unattended =+ crate::diagnostic_logs::collect_redacted_from_dirs(&[dir.path().to_path_buf()])+ .await+ .unwrap();+ for bundle in [&redacted, &unattended] {+ for expected in [+ "installer_failed",+ "os error 2",+ "target=99.0.0",+ "relaunch_observed",+ "running=1.0.0",+ "outcome=Failed",+ ] {+ assert!(bundle.contains(expected), "missing {expected}: {bundle}");+ }+ assert!(!bundle.contains("hunter2"));+ }+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path("/api/logs"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({"data": {+ "signedUrl": format!("{}/upload/log", server.uri()), "path": "logs/report.log"+ }})))+ .mount(&server)+ .await;+ Mock::given(method("PUT"))+ .and(path("/upload/log"))+ .respond_with(ResponseTemplate::new(200))+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path("/api/logs/confirm"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({"data": {"id": 42}})))+ .mount(&server)+ .await;+ upload_report(+ &Client::new(),+ &server.uri(),+ &request(),+ redacted.clone(),+ None,+ None,+ )+ .await+ .unwrap();+ let requests = server.received_requests().await.unwrap();+ let upload = requests.iter().find(|r| r.method == "PUT").unwrap();+ assert_eq!(upload.body, redacted.as_bytes());+ }+#[tokio::test]async fn writer_pool_recovery_reaches_support_after_rotation_and_redaction() {use tracing::instrument::WithSubscriber;diff --git a/apps/screenpipe-app-tauri/src-tauri/src/log_files.rs b/apps/screenpipe-app-tauri/src-tauri/src/log_files.rsindex 956e7231a..d779d4db0 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/log_files.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/log_files.rs@@ -79,7 +79,12 @@ pub(crate) async fn read_tail(path: &Path, max_bytes: u64) -> anyhow::Result<Strpub async fn get_log_files(app: AppHandle) -> Result<Vec<LogFile>, String> {let data_dir = get_screenpipe_data_dir(&app).map_err(|e| e.to_string())?;let screenpipe_data_dir = get_data_dir(&app).map_err(|e| e.to_string())?;- Ok(collect_log_files(&[data_dir, screenpipe_data_dir]).await)+ Ok(collect_log_files(&[+ data_dir,+ screenpipe_data_dir,+ crate::config::app_data_dir().to_path_buf(),+ ])+ .await)}/// Absolute path of the data directory used by the running engine. This is@@ -120,7 +125,9 @@ pub(crate) async fn collect_log_files(dirs: &[PathBuf]) -> Vec<LogFile> {.file_name().and_then(|name| name.to_str()).is_some_and(|name| {- is_panic_log(name) || name == crate::recording::recovery_log::LOG_NAME+ is_panic_log(name)+ || name == crate::recording::recovery_log::LOG_NAME+ || name == crate::update_diagnostics::LOG_NAME}),std::cmp::Reverse(metadatadiff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex d73bac0cf..af7701de4 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -137,6 +137,7 @@ mod staged_update;mod stale_tier;mod startup_auth;mod update_restart;+mod update_diagnostics;mod updates;mod voice_training;mod window;diff --git a/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs b/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rsindex 0fb7faed1..2abd90874 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/process_exit.rs@@ -298,6 +298,12 @@ pub fn force_app_relaunch(app: AppHandle, status: i32) -> ! {let env = app.env();if let Some(binary) = relaunch_binary(&app) {+ if update_installed {+ crate::update_diagnostics::record(+ "relaunch_requested",+ &format!("executable={}", binary.display()),+ );+ }#[cfg(target_os = "macos")]let mut command = if update_installed {macos_updater_relaunch_command(@@ -337,7 +343,15 @@ pub fn force_app_relaunch(app: AppHandle, status: i32) -> ! {binary.display(),child.id()),- Err(err) => warn!("safe relaunch: failed to spawn {}: {err}", binary.display()),+ Err(err) => {+ if update_installed {+ crate::update_diagnostics::record(+ "relaunch_spawn_failed",+ &format!("executable={} error={err}", binary.display()),+ );+ }+ warn!("safe relaunch: failed to spawn {}: {err}", binary.display());+ }}}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/staged_update.rs b/apps/screenpipe-app-tauri/src-tauri/src/staged_update.rsindex d87132068..039aecd86 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/staged_update.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/staged_update.rs@@ -163,16 +163,43 @@ pub fn staged_version() -> Option<String> {/// the exit path; a failure only means the app comes back on the current/// version and the checker re-stages later.pub fn install_staged_if_any<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> bool {+ install_staged_with_diagnostics(+ app,+ crate::config::app_data_dir(),+ std::env::current_exe().ok().as_deref(),+ )+}++fn install_staged_with_diagnostics<R: tauri::Runtime>(+ app: &tauri::AppHandle<R>,+ diagnostic_root: &std::path::Path,+ executable: Option<&std::path::Path>,+) -> bool {let staged = STAGED.lock().unwrap().take();let Some(Staged { update, path }) = staged else {return false;};let started = std::time::Instant::now();+ let diagnostic = |event: &str, detail: &str| {+ crate::update_diagnostics::append(+ diagnostic_root,+ event,+ &format!(+ "from={} target={} {detail}",+ update.current_version, update.version+ ),+ );+ };+ diagnostic(+ "install_started",+ &format!("archive={} executable={executable:?}", path.display()),+ );let bytes = match std::fs::read(&path) {Ok(b) => b,Err(e) => {+ diagnostic("archive_read_failed", &e.to_string());warn!("staged update v{}: failed to read {}: {}",update.version,@@ -187,6 +214,7 @@ pub fn install_staged_if_any<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> bo// signature at download time and `install()` trusts its input, but// these bytes sat on disk in the meantime.if let Err(e) = verify_signature(app, &bytes, &update.signature) {+ diagnostic("signature_verification_failed", &e);warn!("staged update v{}: signature re-verification failed ({}); discarding",update.version, e@@ -196,9 +224,33 @@ pub fn install_staged_if_any<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> bo}let result = update.install(&bytes);+ let bundle = executable.and_then(|exe| {+ exe.ancestors()+ .find(|p| p.extension().is_some_and(|ext| ext == "app"))+ });+ if let Some(bundle) = bundle {+ let installed_version = plist::Value::from_file(bundle.join("Contents/Info.plist"))+ .map_err(|error| error.to_string())+ .and_then(|value| {+ value+ .as_dictionary()+ .and_then(|dict| dict.get("CFBundleShortVersionString"))+ .and_then(|value| value.as_string())+ .map(str::to_owned)+ .ok_or_else(|| "CFBundleShortVersionString missing".to_string())+ });+ diagnostic(+ "installed_bundle",+ &format!("path={} version={installed_version:?}", bundle.display()),+ );+ }let _ = std::fs::remove_file(&path);match result {Ok(()) => {+ diagnostic(+ "installer_returned_ok",+ &format!("elapsed_ms={}", started.elapsed().as_millis()),+ );info!("staged update v{} installed in {:?}",update.version,@@ -207,6 +259,7 @@ pub fn install_staged_if_any<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> botrue}Err(e) => {+ diagnostic("installer_failed", &e.to_string());warn!("staged update v{} install failed: {}", update.version, e);false}@@ -253,7 +306,7 @@ fn verify_signature<R: tauri::Runtime>(/// against a throwaway minisign key, a localhost HTTP server, and fake .app/// bundles in a temp dir. No screenpipe process, no real bundle, no network.#[cfg(test)]-mod tests {+pub(crate) mod tests {use super::*;use base64::Engine;use std::io::Read;@@ -288,6 +341,7 @@ mod tests {let mut ctx = tauri::test::mock_context(tauri::test::noop_assets());ctx.config_mut().identifier = "pe.screenpi.staged-update-test".into();ctx.config_mut().version = Some("1.0.0".into());+ ctx.package_info_mut().version = "1.0.0".parse().unwrap();ctx.config_mut().plugins.0.insert("updater".into(),serde_json::json!({@@ -312,6 +366,7 @@ mod tests {let newapp = newdir.join("FakeApp.app");std::fs::create_dir_all(newapp.join("Contents/MacOS")).unwrap();std::fs::write(newapp.join("Contents/MacOS/app"), b"new-binary").unwrap();+ std::fs::write(newapp.join("Contents/Info.plist"), r#"<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleShortVersionString</key><string>99.0.0</string></dict></plist>"#).unwrap();std::fs::write(newapp.join("marker.txt"), marker).unwrap();// A symlink, because real bundles contain them (Frameworks/Versions)// and the updater installer must preserve them.@@ -425,6 +480,26 @@ mod tests {current}+ /// A real signed archive reaches the installer, whose destination vanished.+ /// Reusable by the support-upload test; every filesystem write is isolated.+ pub(crate) async fn failed_install_fixture(root: &Path) {+ let _guard = STAGED_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());+ let (archive, signature, pubkey, _) = build_signed_fake_bundle(root, b"NEW");+ let (port, stop) = serve_update(archive, &signature);+ let app = mock_app_with_updater(&pubkey);+ let exe = root.join("missing/FakeApp.app/Contents/MacOS/app");+ let (update, bytes) = check_and_download(app.handle(), &exe, &pubkey, port).await;+ stage(app.handle(), update, &bytes).unwrap();+ assert!(!install_staged_with_diagnostics(+ app.handle(),+ root,+ Some(&exe)+ ));+ stop.store(true, Ordering::SeqCst);+ let _ = std::net::TcpStream::connect(("127.0.0.1", port));+ clear_stage_dir(app.handle());+ }+#[tokio::test(flavor = "multi_thread")]async fn staged_update_full_cycle_uses_verified_installer() {let _guard = STAGED_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());@@ -457,7 +532,16 @@ mod tests {);// Install at "exit" through tauri-plugin-updater's verified path.- assert!(install_staged_if_any(&handle), "install should succeed");+ assert!(+ install_staged_with_diagnostics(&handle, tmp.path(), Some(&fake_exe)),+ "install should succeed"+ );+ let diagnostic =+ std::fs::read_to_string(tmp.path().join(crate::update_diagnostics::LOG_NAME)).unwrap();+ assert!(+ diagnostic.contains("version=Ok(\"99.0.0\")"),+ "{diagnostic}"+ );assert_eq!(std::fs::read(current.join("marker.txt")).unwrap(),b"NEW",@@ -474,11 +558,14 @@ mod tests {"installed bundle must keep its symlinks");assert!(- !stage_dir(&handle).unwrap().join("replaced/previous.app").exists(),+ !stage_dir(&handle)+ .unwrap()+ .join("replaced/previous.app")+ .exists(),"the TCC-breaking previous.app path must never be created");assert!(- !install_staged_if_any(&handle),+ !install_staged_with_diagnostics(&handle, tmp.path(), Some(&fake_exe)),"second install call must no-op");@@ -516,5 +603,4 @@ mod tests {"tampered staged bytes must fail re-verification");}-}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/update_diagnostics.rs b/apps/screenpipe-app-tauri/src-tauri/src/update_diagnostics.rsnew file mode 100644index 000000000..cb0a0fb74--- /dev/null+++ b/apps/screenpipe-app-tauri/src-tauri/src/update_diagnostics.rs@@ -0,0 +1,62 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com++//! Installer evidence survives the dying process and application-log rotation.+//! Only normal, consented support collection sends these locally redacted bytes.++use std::io::{Read, Seek, SeekFrom, Write};+use std::path::Path;+use std::sync::Mutex;++pub(crate) const LOG_NAME: &str = "update-install.log";+const MAX_BYTES: u64 = 32 * 1024;+static WRITER: Mutex<()> = Mutex::new(());++pub(crate) fn append(root: &Path, event: &str, detail: &str) {+ let _guard = WRITER.lock().unwrap_or_else(|error| error.into_inner());+ let result = (|| -> std::io::Result<()> {+ std::fs::create_dir_all(root)?;+ let path = root.join(LOG_NAME);+ if std::fs::symlink_metadata(&path).is_ok_and(|m| m.file_type().is_symlink()) {+ return Err(std::io::Error::other(+ "updater diagnostic path is a symlink",+ ));+ }+ let mut options = std::fs::OpenOptions::new();+ options.create(true).read(true).write(true).truncate(false);+ #[cfg(unix)]+ {+ use std::os::unix::fs::OpenOptionsExt;+ options.mode(0o600).custom_flags(libc::O_NOFOLLOW);+ }+ let mut file = options.open(path)?;+ if file.metadata()?.len() > MAX_BYTES {+ file.seek(SeekFrom::End(-(MAX_BYTES as i64 / 2)))?;+ let mut tail = Vec::new();+ file.read_to_end(&mut tail)?;+ let start = tail+ .iter()+ .position(|b| *b == b'\n')+ .map_or(tail.len(), |i| i + 1);+ file.set_len(0)?;+ file.rewind()?;+ file.write_all(&tail[start..])?;+ }+ file.seek(SeekFrom::End(0))?;+ let detail: String = detail.chars().take(4096).collect();+ writeln!(+ file,+ "{} {event}: {}",+ chrono::Utc::now().to_rfc3339(),+ detail.replace(['\r', '\n'], " ")+ )?;+ file.sync_data()+ })();+ if let Err(error) = result {+ log::warn!("could not persist updater diagnostic: {error}");+ }+}++pub(crate) fn record(event: &str, detail: &str) {+ append(crate::config::app_data_dir(), event, detail);+}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rsindex 375e77946..659c501a3 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs@@ -109,6 +109,13 @@ async fn install_windows_update(if let Err(error) = update.install(bytes) {UPDATE_RESTART_STARTED.store(false, Ordering::SeqCst);recording.set_capture_intent(wants_recording);+ crate::update_diagnostics::record(+ "installer_handoff_failed",+ &format!(+ "from={} target={} error={error} capture_intent_restored={wants_recording}",+ update.current_version, update.version,+ ),+ );return Err(error);}std::mem::forget(restart);@@ -654,6 +661,16 @@ fn record_update_attempt(app: &tauri::AppHandle, to_version: &str) {.map(|d| d.as_secs()).unwrap_or(0),};+ crate::update_diagnostics::record(+ "restart_committed",+ &format!(+ "from={} target={} attempt_ts={} executable={:?}",+ attempt.from_version,+ attempt.to_version,+ attempt.ts_epoch_secs,+ std::env::current_exe()+ ),+ );match serde_json::to_vec(&attempt).map(|bytes| std::fs::write(&path, bytes)) {Ok(Ok(())) => info!("update attempt recorded: {} → {}",@@ -669,7 +686,11 @@ fn record_update_attempt(app: &tauri::AppHandle, to_version: &str) {/// unrelated cases.fn consume_update_attempt_marker(app: &tauri::AppHandle) -> Option<UpdateAttempt> {let path = update_attempt_marker_path(app)?;- let raw = std::fs::read(&path).ok()?;+ consume_update_attempt_at(&path, &app.package_info().version.to_string())+}++fn consume_update_attempt_at(path: &std::path::Path, current: &str) -> Option<UpdateAttempt> {+ let raw = std::fs::read(path).ok()?;if let Err(e) = std::fs::remove_file(&path) {warn!("failed to remove update-attempt marker: {}", e);}@@ -680,7 +701,19 @@ fn consume_update_attempt_marker(app: &tauri::AppHandle) -> Option<UpdateAttemptreturn None;}};- let current = app.package_info().version.to_string();+ crate::update_diagnostics::append(+ path.parent()?,+ "relaunch_observed",+ &format!(+ "from={} target={} attempt_ts={} running={} executable={:?} outcome={:?}",+ attempt.from_version,+ attempt.to_version,+ attempt.ts_epoch_secs,+ current,+ std::env::current_exe(),+ classify_update_attempt(&attempt, ¤t)+ ),+ );match classify_update_attempt(&attempt, ¤t) {UpdateAttemptOutcome::Applied => {info!(@@ -1932,7 +1965,20 @@ pub fn start_update_check(}#[cfg(test)]-mod tests {+pub(crate) mod tests {+ #[cfg(target_os = "macos")]+ pub(crate) fn consume_failed_update_fixture(root: &std::path::Path) {+ 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}"#,+ )+ .unwrap();+ 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());+ }+use super::*;const HOUR: Duration = Duration::from_secs(3600);