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(storage): avoid repeated migration prompts during startup (#7028)
Ezra Ellette8945f5e559d0
diff --git a/apps/screenpipe-app-tauri/components/storage-migration-prompt.test.tsx b/apps/screenpipe-app-tauri/components/storage-migration-prompt.test.tsxindex 31d0897b6..2281c474b 100644--- a/apps/screenpipe-app-tauri/components/storage-migration-prompt.test.tsx+++ b/apps/screenpipe-app-tauri/components/storage-migration-prompt.test.tsx@@ -92,6 +92,42 @@ describe("automatic storage migration prompt", () => {expect(screen.queryByRole("alertdialog")).toBeNull();});+ it("stays closed across app launches while completed storage is reopening", async () => {+ Object.assign(status, {+ completed: true, using_new_storage: false, can_migrate: false,+ generation: "migrated-generation",+ });+ for (const session of ["app-launch-1", "app-launch-2", "app-launch-3"]) {+ status.app_session_id = session;+ const app = render(<StorageMigrationPrompt activity={idle} />);+ await waitFor(() => expect(commands.getStorageMigrationStatus).toHaveBeenCalled());+ expect(screen.queryByRole("alertdialog")).toBeNull();+ app.unmount();+ commands.getStorageMigrationStatus.mockClear();+ }+ expect(commands.startStorageMigration).not.toHaveBeenCalled();+ });++ it.each(["failure", "interruption"])("requires an explicit retry after %s across app launches", async (reason) => {+ Object.assign(status, {+ pending: true, in_place: true,+ error: reason === "failure" ? "Not enough free disk space." : "The previous storage migration did not finish.",+ });+ for (const session of ["app-launch-1", "app-launch-2"]) {+ status.app_session_id = session;+ const app = render(<StorageMigrationPrompt activity={{ ...idle, error: status.error }} />);+ await screen.findByRole("button", { name: "try again" });+ expect(commands.startStorageMigration).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole("button", { name: "do later" }));+ app.unmount();+ }+ status.app_session_id = "app-launch-3";+ render(<StorageMigrationPrompt activity={{ ...idle, error: status.error }} />);+ fireEvent.click(await screen.findByRole("button", { name: "try again" }));+ await waitFor(() => expect(commands.startStorageMigration).toHaveBeenCalledTimes(1));+ expect(commands.startStorageMigration).toHaveBeenCalledWith("/fixture");+ });+it("surfaces start failures and permits retry without losing the original", async () => {commands.startStorageMigration.mockResolvedValueOnce({ status: "error", error: "Could not prevent sleep. Migration has not started." });render(<StorageMigrationPrompt activity={idle} />);diff --git a/apps/screenpipe-app-tauri/src-tauri/src/storage_migration.rs b/apps/screenpipe-app-tauri/src-tauri/src/storage_migration.rsindex 769a1d205..38bd9a791 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/storage_migration.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/storage_migration.rs@@ -456,6 +456,12 @@ fn track_completed_migration(app: &tauri::AppHandle, root: &Path) {});}+fn needs_storage_activation(using_new_storage: Option<bool>, error: Option<&str>) -> bool {+ // No open server is normal during startup. Only an observed mismatch or+ // an actual migration failure makes a completed migration retryable.+ using_new_storage == Some(false) || error.is_some()+}+#[tauri::command]#[specta::specta]pub async fn get_storage_migration_status(@@ -487,7 +493,7 @@ pub async fn get_storage_migration_status(.map(|m| m.len()).unwrap_or(0);let mut blocked_reason = None;- let mut using_new_storage = false;+ let mut using_new_storage = None;let mut can_delete_source = false;{let server = recording.server.try_lock();@@ -501,10 +507,11 @@ pub async fn get_storage_migration_status("Apply the data directory change and restart before migrating.".into(),);} else {- using_new_storage = descriptor.is_some()- && server.db.storage_descriptor() == descriptor.as_ref()- && !server.db.pool.is_closed();- if completed && using_new_storage {+ using_new_storage = (!server.db.pool.is_closed()).then(|| {+ descriptor.is_some()+ && server.db.storage_descriptor() == descriptor.as_ref()+ });+ if completed && using_new_storage == Some(true) {match server.db.retained_migration_source_bytes() {Ok(bytes) => can_delete_source = bytes.is_some(),Err(error) => blocked_reason = Some(error.to_string()),@@ -530,7 +537,7 @@ pub async fn get_storage_migration_status(&& blocked_reason.is_none()&& (pending|| (!completed && descriptor.is_none() && source_bytes > 0)- || (completed && (!using_new_storage || error.is_some())));+ || (completed && needs_storage_activation(using_new_storage, error.as_deref())));Ok(StorageMigrationStatus {root: root.display().to_string(),app_session_id: APP_SESSION_ID.clone(),@@ -544,7 +551,7 @@ pub async fn get_storage_migration_status(pending,in_place,completed,- using_new_storage,+ using_new_storage: using_new_storage.unwrap_or(false),generation: descriptor.map(|d| d.generation),source_bytes,migrated_bytes: report.as_ref().map(|r| {@@ -889,6 +896,25 @@ pub async fn delete_original_storage_database(mod tests {use super::*;+ #[test]+ fn completed_migration_does_not_prompt_during_server_startup_or_restart() {+ // The receipt already matches, but startup has not installed the+ // server yet. Opening the migrated DB must not require user action.+ assert!(!needs_storage_activation(None, None));+ assert!(!needs_storage_activation(Some(true), None));+ }++ #[test]+ fn completed_migration_keeps_actual_activation_failures_retryable() {+ assert!(needs_storage_activation(Some(false), None));+ for using_new_storage in [None, Some(false), Some(true)] {+ assert!(needs_storage_activation(+ using_new_storage,+ Some("Your history was migrated, but recording could not resume.")+ ));+ }+ }+fn legacy_status() -> StorageMigrationStatus {StorageMigrationStatus {root: "/fixture".into(),