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(updater): promote to newer version instead of latching (#5784) (#6002)

Parth Narkar971072916a21
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 50a5ca162..a129ae683 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -11204,6 +11204,7 @@ dependencies = [
"screenpipe-telemetry-wire",
"screenpipe-vault",
"security-framework",
+ "semver",
"sentry 0.42.0",
"serde",
"serde_json",
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index cfa72f375..c3a2193ee 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -46,6 +46,8 @@ tauri-utils = { version = "=2.9.2", features = [] }
tauri-plugin-fs = "=2.4.5"
tauri-plugin-notification = "=2.3.3"
tauri-plugin-updater = "=2.10.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)
minisign-verify = "0.2"
tauri-plugin-dialog = "=2.6.0"
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
index c12def3e6..40f741bce 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -9,6 +9,7 @@ use crate::RecordingState;
use anyhow::Error;
use dark_light::Mode;
use log::{debug, error, info, warn};
+use semver::Version;
use serde_json;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@@ -373,6 +374,51 @@ fn failed_version_in_cooldown(
matches!(last_failed, Some((v, elapsed)) if v == version && elapsed < cooldown)
}
+/// Whether `candidate` is a strictly higher semantic version than `current`.
+/// On parse failure of either string this returns `false` (falls back to the
+/// exact-string semantics of `failed_version_in_cooldown`), so a malformed
+/// candidate can never claim to be newer.
+fn version_is_newer(current: &str, candidate: &str) -> bool {
+ match (Version::parse(current), Version::parse(candidate)) {
+ (Ok(current), Ok(candidate)) => candidate > current,
+ _ => false,
+ }
+}
+
+/// How a freshly-observed update should be treated relative to the currently
+/// pending version and the last version whose download/install failed.
+///
+/// The periodic updater now re-polls every tick (the old `update_available` latch
+/// suppressed re-polls and pinned the app to the first version it saw — #5784).
+/// These outcomes keep each re-poll cheap and correct:
+enum PromoteDecision {
+ /// No pending update, or `found` is strictly newer than the pending one —
+ /// adopt `found`.
+ Adopt,
+ /// The pending version is already as new or newer than `found` — nothing to
+ /// do this tick.
+ Noop,
+ /// `found` equals the version that previously failed to install — route it
+ /// through the cooldown/retry gate so a post-cooldown or forced retry can run.
+ RetryCandidate,
+}
+
+fn classify_update(pending: Option<&str>, last_failed: Option<&str>, found: &str) -> PromoteDecision {
+ match pending {
+ None => PromoteDecision::Adopt,
+ Some(pending) if version_is_newer(pending, found) => PromoteDecision::Adopt,
+ Some(pending) if pending == found => {
+ if last_failed == Some(found) {
+ PromoteDecision::RetryCandidate
+ } else {
+ PromoteDecision::Noop
+ }
+ }
+ // Pending is already newer than `found`; keep the pending version.
+ Some(_) => PromoteDecision::Noop,
+ }
+}
+
fn auto_update_enabled_from_settings(settings: Result<Option<SettingsStore>, String>) -> bool {
settings
.ok()
@@ -655,6 +701,33 @@ impl UpdatesManager {
}
}
if let Ok(Some(update)) = check_result {
+ // Promote/skip decision for the periodic re-poll (#5784). Without this
+ // the app pinned to the first version it saw and never promoted when a
+ // newer one shipped (offered v165 forever once v166 was out).
+ {
+ let pending = self.pending_update.lock().await.clone();
+ let last_failed = self
+ .last_failed_update
+ .lock()
+ .await
+ .as_ref()
+ .map(|(v, _)| v.clone());
+ match classify_update(
+ pending.as_ref().map(|p| p.version.as_str()),
+ last_failed.as_deref(),
+ &update.version,
+ ) {
+ PromoteDecision::Noop => {
+ info!(
+ "update already pending at v{}, skipping re-handling",
+ update.version
+ );
+ return Result::Ok(false);
+ }
+ PromoteDecision::Adopt | PromoteDecision::RetryCandidate => {}
+ }
+ }
+
// Cooldown gate: if this exact version recently failed to
// download/install, don't auto-re-download it every 5 min. A
// user-initiated check (`force`) always bypasses this so "click to
@@ -1154,12 +1227,13 @@ impl UpdatesManager {
loop {
interval.tick().await;
- if !*self.update_available.lock().await {
- // Don't show dialog for periodic checks - only for manual checks
- if let Err(e) = self.check_for_updates(false, false).await {
- // warn, not error — see updater check() note above.
- warn!("Failed to check for updates: {}", e);
- }
+ // Always re-check. The old `update_available` latch stopped re-polling
+ // the moment any update was pending, pinning the app to the first
+ // version it saw even after a newer one shipped (#5784). `check_for_updates`
+ // now dedupes the same version and promotes to a strictly newer one, so an
+ // unconditional re-poll is safe and required to surface vN+1.
+ if let Err(e) = self.check_for_updates(false, false).await {
+ warn!("Failed to check for updates: {}", e);
}
}
}
@@ -1427,6 +1501,79 @@ mod tests {
));
}
+ #[test]
+ fn version_newer_rejects_equal() {
+ assert!(!version_is_newer("2.5.165", "2.5.165"));
+ }
+
+ #[test]
+ fn version_newer_rejects_older_candidate() {
+ assert!(!version_is_newer("2.5.166", "2.5.165"));
+ }
+
+ #[test]
+ fn version_newer_accepts_strictly_newer_candidate() {
+ // The core of #5784: when 166 is observed while 165 is pending, it's newer.
+ assert!(version_is_newer("2.5.165", "2.5.166"));
+ }
+
+ #[test]
+ fn version_newer_mayor_bump_counts_as_newer() {
+ assert!(version_is_newer("2.5.165", "3.0.0"));
+ }
+
+ #[test]
+ fn version_newer_fails_closed_on_malformed_input() {
+ assert!(!version_is_newer("2.5.165", "not-a-version"));
+ assert!(!version_is_newer("not-a-version", "2.5.166"));
+ }
+
+ #[test]
+ fn classify_adopts_when_nothing_pending() {
+ assert!(matches!(
+ classify_update(None, None, "2.5.165"),
+ PromoteDecision::Adopt
+ ));
+ }
+
+ #[test]
+ fn classify_adopts_a_strictly_newer_version() {
+ // 166 shipped while 165 was pending → must supersede it (#5784).
+ assert!(matches!(
+ classify_update(Some("2.5.165"), Some("2.5.165"), "2.5.166"),
+ PromoteDecision::Adopt
+ ));
+ }
+
+ #[test]
+ fn classify_noop_on_same_healthy_version() {
+ // Re-poll sees the same pending version with no prior failure → skip, so we
+ // don't re-notify/re-download every 5-min tick.
+ assert!(matches!(
+ classify_update(Some("2.5.165"), None, "2.5.165"),
+ PromoteDecision::Noop
+ ));
+ }
+
+ #[test]
+ fn classify_noop_when_pending_is_newer() {
+ // Server regressed (found older than pending) — keep pending.
+ assert!(matches!(
+ classify_update(Some("2.5.166"), None, "2.5.165"),
+ PromoteDecision::Noop
+ ));
+ }
+
+ #[test]
+ fn classify_retry_candidate_for_previously_failed_version() {
+ // Same version that previously failed must reach the cooldown gate so a
+ // post-cooldown / forced retry can still run.
+ assert!(matches!(
+ classify_update(Some("2.5.165"), Some("2.5.165"), "2.5.165"),
+ PromoteDecision::RetryCandidate
+ ));
+ }
+
#[test]
fn auto_update_setting_respects_false() {
let mut settings = SettingsStore::default();