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(updates): make failed updates retryable
Louis Beaumonta3a86762b85f
diff --git a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx b/apps/screenpipe-app-tauri/components/settings/general-settings.tsxindex a96d6f1e8..268b39c96 100644--- a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx+++ b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx@@ -16,6 +16,7 @@ import { useToast } from "@/components/ui/use-toast";import { Button } from "@/components/ui/button";import { Settings } from "@/lib/hooks/use-settings";import { getVersion } from "@tauri-apps/api/app";+import { invoke } from "@tauri-apps/api/core";import { commands } from "@/lib/utils/tauri";import { UpdateBanner } from "@/components/update-banner";import { useIsEnterpriseBuild } from "@/lib/hooks/use-is-enterprise-build";@@ -31,6 +32,28 @@ export default function GeneralSettings() {const { settings, updateSettings } = useSettings();const { toast } = useToast();const [currentVersion, setCurrentVersion] = useState<string | null>(null);+ const [isCheckingForUpdate, setIsCheckingForUpdate] = useState(false);++ const handleCheckForUpdates = async () => {+ setIsCheckingForUpdate(true);+ try {+ const updateFound = await invoke<boolean>("trigger_update_check");+ toast({+ title: updateFound ? "update found" : "you're up to date",+ description: updateFound+ ? "downloading in the background — banner will appear when ready"+ : `running latest version${currentVersion ? ` (v${currentVersion})` : ""}`,+ });+ } catch (e: any) {+ toast({+ title: "update check failed",+ description: e?.toString() || "please try again later",+ variant: "destructive",+ });+ } finally {+ setIsCheckingForUpdate(false);+ }+ };useEffect(() => {getVersion().then(setCurrentVersion).catch(() => {});@@ -140,6 +163,33 @@ export default function GeneralSettings() {</Card>)}+ {!isEnterprise && (+ <Card className="border-border bg-card">+ <CardContent className="px-3 py-2.5">+ <div className="flex items-center justify-between">+ <div className="flex items-center space-x-2.5">+ <RefreshCw className="h-4 w-4 text-muted-foreground shrink-0" />+ <div>+ <h3 className="text-sm font-medium text-foreground">Check for updates</h3>+ <p className="text-xs text-muted-foreground">+ {currentVersion ? `Running v${currentVersion}` : "Look for a new version now"}+ </p>+ </div>+ </div>+ <Button+ variant="outline"+ size="sm"+ onClick={handleCheckForUpdates}+ disabled={isCheckingForUpdate}+ className="ml-4 h-8"+ >+ {isCheckingForUpdate ? "checking..." : "check now"}+ </Button>+ </div>+ </CardContent>+ </Card>+ )}+{isEnterprise && (<Card className="border-border bg-card"><CardContent className="px-3 py-2.5">diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex 53b3d1c89..838eb10e1 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1014,6 +1014,7 @@ async fn main() {commands::is_enterprise_build_cmd,enterprise_install_metadata::get_enterprise_install_metadata,updates::get_pending_update,+ updates::trigger_update_check,commands::get_local_api_config,commands::regenerate_api_auth_key,commands::set_api_auth_key,diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rsindex f64e7c259..1dba03b71 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs@@ -446,37 +446,81 @@ impl UpdatesManager {}}- let app_handle = self.app.clone();- let update_version = update.version.clone();- let menu_item = self.update_menu_item.clone();- let mut downloaded: u64 = 0;- let mut last_pct: u8 = 0;- let download_result = update- .download_and_install(- move |chunk_len, content_len| {- downloaded += chunk_len as u64;- let pct = content_len- .map(|total| ((downloaded as f64 / total as f64) * 100.0) as u8)- .unwrap_or(0);- // Only emit every 5% to avoid flooding- if pct >= last_pct + 5 || pct == 100 {- last_pct = pct;- let progress = serde_json::json!({- "version": update_version,- "downloaded": downloaded,- "total": content_len,- "percent": pct,- });- let _ = app_handle.emit("update-download-progress", progress);- info!("update download: {}%", pct);- }- if let Some(ref m) = menu_item {- let _ = m.set_text(&format!("Downloading update... {}%", pct));+ // Retry transient download failures with exponential backoff.+ // Auth errors (401/403) short-circuit out of the loop — see error arm.+ let retry_delays = [+ Duration::from_secs(30),+ Duration::from_secs(120),+ Duration::from_secs(300),+ ];+ let download_result = {+ let mut attempt: usize = 0;+ loop {+ let app_handle = self.app.clone();+ let update_version = update.version.clone();+ let menu_item = self.update_menu_item.clone();+ let mut downloaded: u64 = 0;+ let mut last_pct: u8 = 0;+ let result = update+ .download_and_install(+ move |chunk_len, content_len| {+ downloaded += chunk_len as u64;+ let pct = content_len+ .map(|total| ((downloaded as f64 / total as f64) * 100.0) as u8)+ .unwrap_or(0);+ // Only emit every 5% to avoid flooding+ if pct >= last_pct + 5 || pct == 100 {+ last_pct = pct;+ let progress = serde_json::json!({+ "version": update_version,+ "downloaded": downloaded,+ "total": content_len,+ "percent": pct,+ });+ let _ = app_handle.emit("update-download-progress", progress);+ info!("update download: {}%", pct);+ }+ if let Some(ref m) = menu_item {+ let _ = m.set_text(&format!("Downloading update... {}%", pct));+ }+ },+ || {},+ )+ .await;++ match &result {+ Ok(_) => break result,+ Err(e) => {+ let err_str = e.to_string();+ // Auth errors won't recover from a retry — bail out and let+ // the error arm below emit the sign-in banner.+ let is_auth = err_str.contains("401")+ || err_str.contains("403")+ || err_str.contains("Unauthorized")+ || err_str.contains("Forbidden");+ let next_delay = retry_delays.get(attempt).copied();+ if is_auth || next_delay.is_none() {+ break result;+ }+ let delay = next_delay.unwrap();+ warn!(+ "update download attempt {} failed: {} — retrying in {}s",+ attempt + 1,+ err_str,+ delay.as_secs()+ );+ if let Some(ref item) = self.update_menu_item {+ let _ = item.set_text(&format!(+ "Update download failed — retrying in {}s",+ delay.as_secs()+ ));+ }+ tokio::time::sleep(delay).await;+ attempt += 1;}- },- || {},- )- .await;+ }+ }+ };match download_result {Ok(_) => {@@ -523,6 +567,36 @@ impl UpdatesManager {}return Ok(false);}+ // Generic failure (network/disk/server). Clear latched state+ // so the periodic loop and tray can retry without an app+ // restart, and tell the user what happened.+ warn!("update download failed after retries: {}", err_str);+ *self.update_available.lock().await = false;+ *self.pending_update.lock().await = None;+ if let Some(ref item) = self.update_menu_item {+ item.set_enabled(true)?;+ item.set_text("Update failed — click to retry")?;+ }+ let _ = self.app.emit(+ "update-failed",+ serde_json::json!({+ "version": update.version,+ "reason": err_str,+ }),+ );+ let app_notif = self.app.clone();+ let version_str = update.version.clone();+ std::thread::spawn(move || {+ let _ = app_notif+ .notification()+ .builder()+ .title("screenpipe update failed")+ .body(format!(+ "v{} couldn't download — open screenpipe to retry",+ version_str+ ))+ .show();+ });return Err(e.into());}}@@ -780,6 +854,20 @@ pub async fn get_pending_update(Ok(state.pending_update_snapshot().await)}+/// User-initiated update check from Settings → General. Returns:+/// - `Ok(true)` when an update was found (banner will appear after download).+/// - `Ok(false)` when already up to date or the build can't auto-update.+/// - `Err(String)` when the check itself failed (network, server, etc.).+#[tauri::command]+pub async fn trigger_update_check(+ state: tauri::State<'_, Arc<UpdatesManager>>,+) -> Result<bool, String> {+ state+ .check_for_updates(false)+ .await+ .map_err(|e| e.to_string())+}+pub fn start_update_check(app: &tauri::AppHandle,interval_minutes: u64,