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 cloud archive "not initialized" error + auto-start retry

louis030195e217229de8c4
diff --git a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
index 1a2cd49db..35b9b1023 100644
--- a/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/archive-settings.tsx
@@ -135,16 +135,16 @@ export function ArchiveSettings() {
await persistArchiveStore(true, retentionDays);
toast({ title: "Cloud archive enabled" });
} else {
- // Disable archive
- const res = await fetch("http://localhost:3030/archive/configure", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ enabled: false }),
- });
-
- if (!res.ok) {
- const data = await res.json();
- throw new Error(data.error || "failed to disable archive");
+ // Disable archive — always update local settings even if server
+ // is unreachable (the intent is to turn it off).
+ try {
+ await fetch("http://localhost:3030/archive/configure", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ enabled: false }),
+ });
+ } catch {
+ // Server unreachable — still disable locally
}
await updateSettings({ cloudArchiveEnabled: false });
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index cbe8e4eda..c2412dda8 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.231"
+version = "2.2.232"
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.rs
index af304ca8f..e08a32198 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
@@ -645,43 +645,62 @@ pub async fn auto_start_archive(app: &AppHandle) {
"retention_days": archive_settings.retention_days,
});
- match client
- .post("http://localhost:3030/archive/init")
- .json(&init_request)
- .send()
- .await
- {
- Ok(response) if response.status().is_success() => {
- info!(
- "cloud archive auto-started (retention={}d)",
- archive_settings.retention_days
- );
+ // 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).
+ let retry_delays = [0, 5, 10, 15, 30]; // seconds
+ for (attempt, delay) in retry_delays.iter().enumerate() {
+ if *delay > 0 {
+ tokio::time::sleep(tokio::time::Duration::from_secs(*delay)).await;
}
- Ok(response) if response.status().as_u16() == 409 => {
- info!("cloud archive: already initialized, re-enabling");
- // Already initialized — make sure it's enabled
- let enable_req = serde_json::json!({ "enabled": true });
- if let Err(e) = client
- .post("http://localhost:3030/archive/configure")
- .json(&enable_req)
- .send()
- .await
- {
- warn!("cloud archive: failed to re-enable: {}", e);
+
+ match client
+ .post("http://localhost:3030/archive/init")
+ .json(&init_request)
+ .send()
+ .await
+ {
+ Ok(response) if response.status().is_success() => {
+ info!(
+ "cloud archive auto-started (retention={}d)",
+ archive_settings.retention_days
+ );
+ return;
+ }
+ Ok(response) if response.status().as_u16() == 409 => {
+ info!("cloud archive: already initialized, re-enabling");
+ // Already initialized — make sure it's enabled
+ let enable_req = serde_json::json!({ "enabled": true });
+ if let Err(e) = client
+ .post("http://localhost:3030/archive/configure")
+ .json(&enable_req)
+ .send()
+ .await
+ {
+ warn!("cloud archive: failed to re-enable: {}", e);
+ }
+ return;
+ }
+ Ok(response) => {
+ let status = response.status();
+ let body = response.text().await.unwrap_or_default();
+ warn!(
+ "cloud archive auto-start: init failed ({}): {} (attempt {}/{})",
+ status, body, attempt + 1, retry_delays.len()
+ );
+ // Non-transient error (auth, config), don't retry
+ return;
+ }
+ Err(e) => {
+ warn!(
+ "cloud archive auto-start: server not reachable (attempt {}/{}): {}",
+ attempt + 1, retry_delays.len(), e
+ );
+ // Transient — server may still be starting, retry
}
- }
- Ok(response) => {
- let status = response.status();
- let body = response.text().await.unwrap_or_default();
- warn!(
- "cloud archive auto-start: init failed ({}): {}",
- status, body
- );
- }
- Err(e) => {
- warn!("cloud archive auto-start: server not reachable: {}", e);
}
}
+
+ warn!("cloud archive auto-start: gave up after {} attempts", retry_delays.len());
}
/// Auto-start local data retention on app launch if previously enabled.
diff --git a/crates/screenpipe-engine/src/archive.rs b/crates/screenpipe-engine/src/archive.rs
index 1bc19234c..89ece77dd 100644
--- a/crates/screenpipe-engine/src/archive.rs
+++ b/crates/screenpipe-engine/src/archive.rs
@@ -268,12 +268,26 @@ pub async fn archive_configure(
Json(request): Json<ArchiveConfigureRequest>,
) -> Result<Json<Value>, (StatusCode, Json<Value>)> {
let mut guard = state.archive_state.inner.write().await;
- let runtime = guard.as_mut().ok_or_else(|| {
- (
- StatusCode::BAD_REQUEST,
- Json(json!({"error": "archive not initialized"})),
- )
- })?;
+
+ let runtime = match guard.as_mut() {
+ Some(rt) => rt,
+ None => {
+ // Archive not initialized — if caller wants to disable, that's a no-op
+ let wants_enabled = request.enabled.unwrap_or(false);
+ if !wants_enabled {
+ info!("archive: configure(disable) on uninitialized state — no-op");
+ return Ok(Json(json!({
+ "success": true,
+ "enabled": false,
+ "retention_days": request.retention_days.unwrap_or(7),
+ })));
+ }
+ return Err((
+ StatusCode::BAD_REQUEST,
+ Json(json!({"error": "archive not initialized, call /archive/init first"})),
+ ));
+ }
+ };
if let Some(days) = request.retention_days {
runtime.config.retention_days = days;