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 cloud archive requiring sync: pass sync password to archive init
louis0301957cd1a918ce7f
diff --git a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsxindex 35b9b1023..8cae7e02c 100644--- a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx+++ b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx@@ -116,13 +116,23 @@ export function ArchiveSettings() {try {if (enabled) {- // Initialize archive — encryption key is derived server-side from the token+ // Pass sync password if available so archive can reuse the same+ // encryption keys (avoids "set up on another device" error).+ let syncPassword: string | undefined;+ try {+ const store = await getStore();+ syncPassword = (await store.get<string>("sync_password")) ?? undefined;+ } catch {+ // best effort+ }+const res = await fetch("http://localhost:3030/archive/init", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({token: settings.user?.token,retention_days: retentionDays,+ ...(syncPassword ? { password: syncPassword } : {}),}),});diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex c2412dda8..c84c4f09b 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "2.2.232"+version = "2.2.233"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/sync.rsindex e08a32198..10d4c254e 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs@@ -639,11 +639,26 @@ pub async fn auto_start_archive(app: &AppHandle) {}};+ // Try to get the sync password so archive can reuse the same encryption keys+ // (avoids the "encryption keys set up on another device" error).+ let sync_password = match CloudSyncSettingsStore::get(app) {+ Ok(Some(s)) if !s.encrypted_password.is_empty() => {+ match BASE64.decode(&s.encrypted_password) {+ Ok(bytes) => String::from_utf8(bytes).ok(),+ Err(_) => None,+ }+ }+ _ => None,+ };+let client = reqwest::Client::new();- let init_request = serde_json::json!({+ let mut init_request = serde_json::json!({"token": token,"retention_days": archive_settings.retention_days,});+ if let Some(ref pw) = sync_password {+ init_request["password"] = serde_json::json!(pw);+ }// Retry up to 5 times with increasing delays if the server isn't ready yet.// The server may still be starting when this runs (15s after app launch).diff --git a/crates/screenpipe-engine/src/archive.rs b/crates/screenpipe-engine/src/archive.rsindex 89ece77dd..2993c7a8a 100644--- a/crates/screenpipe-engine/src/archive.rs+++ b/crates/screenpipe-engine/src/archive.rs@@ -100,6 +100,10 @@ impl Default for ArchiveConfig {pub struct ArchiveInitRequest {pub token: String,pub retention_days: Option<u32>,+ /// Optional sync password — if the user has cloud sync set up, pass the+ /// sync password so archive can reuse the same encryption keys without+ /// requiring sync to be running.+ pub password: Option<String>,}#[derive(Debug, Serialize)]@@ -188,31 +192,55 @@ pub async fn archive_init()})?;- // Derive encryption password from the token (deterministic across devices)- let password = format!(+ // Try passwords in order:+ // 1. Sync password passed by the caller (if user has sync set up)+ // 2. Deterministic password derived from token (for archive-only users)+ let deterministic_pw = format!("screenpipe-archive-{:x}",md5::compute(request.token.as_bytes()));- match mgr.initialize(&password).await {- Ok(_) => Arc::new(mgr),- Err(e) => {- let err_str = e.to_string();- if err_str.contains("decryption failed") || err_str.contains("authentication error") {- // Keys exist on server but were created with a different password- // (likely from cloud sync setup). User needs to enable sync first.- warn!("archive: encryption keys exist but password doesn't match (likely set up via cloud sync on another device)");- return Err((- StatusCode::PRECONDITION_FAILED,- Json(json!({"error": "encryption keys were set up on another device via cloud sync. please enable cloud sync first in Settings → Sync, then try archive again."})),- ));+ let passwords_to_try: Vec<&str> = match &request.password {+ Some(pw) if !pw.is_empty() => vec![pw.as_str(), &deterministic_pw],+ _ => vec![&deterministic_pw],+ };++ let mut last_err = None;+ let mut initialized = false;++ for pw in &passwords_to_try {+ match mgr.initialize(pw).await {+ Ok(_) => {+ initialized = true;+ break;+ }+ Err(e) => {+ let err_str = e.to_string();+ if err_str.contains("decryption failed") || err_str.contains("authentication error") {+ info!("archive: password attempt failed (key mismatch), trying next");+ last_err = Some(e);+ } else {+ return Err((+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(json!({"error": format!("failed to initialize encryption: {}", e)})),+ ));+ }}- return Err((- StatusCode::INTERNAL_SERVER_ERROR,- Json(json!({"error": format!("failed to initialize encryption: {}", e)})),- ));}}++ if !initialized {+ warn!("archive: all password attempts failed");+ return Err((+ StatusCode::PRECONDITION_FAILED,+ Json(json!({"error": format!(+ "encryption key mismatch — try enabling cloud sync first in Settings → Sync, then retry archive. ({})",+ last_err.map(|e| e.to_string()).unwrap_or_default()+ )})),+ ));+ }++ Arc::new(mgr)}};