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: write vault sentinel before encryption, detect encrypted DB as fallback

Louis Beaumontbb3ba65d884b
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index fe9f4781e..6dffa4443 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -661,6 +661,14 @@ async fn vault_status(app: AppHandle) -> Result<String, String> {
if data_dir.join(".vault_locked").exists() {
return Ok("locked".to_string());
}
+ // Fallback: if vault.meta exists but no sentinel, check if DB is actually encrypted
+ // (handles crash during lock where sentinel wasn't written yet)
+ let db_path = data_dir.join("db.sqlite");
+ if db_path.exists() {
+ if let Ok(true) = screenpipe_vault::crypto::is_encrypted_file(&db_path) {
+ return Ok("locked".to_string());
+ }
+ }
Ok("unlocked".to_string())
}
@@ -2035,8 +2043,10 @@ async fn main() {
}
// Check if vault is locked — if so, skip server start and notify frontend
- let vault_locked_sentinel = data_dir.join(".vault_locked");
- let vault_is_locked = vault_locked_sentinel.exists();
+ let vault_is_locked = data_dir.join(".vault_locked").exists()
+ || (data_dir.join("vault.meta").exists()
+ && data_dir.join("db.sqlite").exists()
+ && screenpipe_vault::crypto::is_encrypted_file(&data_dir.join("db.sqlite")).unwrap_or(false));
if vault_is_locked {
info!("Vault is locked — skipping server start, waiting for unlock");
let _ = app_handle.emit("vault-locked-on-startup", ());
diff --git a/crates/screenpipe-vault/src/manager.rs b/crates/screenpipe-vault/src/manager.rs
index 99e186ad4..1a9ad1c4e 100644
--- a/crates/screenpipe-vault/src/manager.rs
+++ b/crates/screenpipe-vault/src/manager.rs
@@ -146,6 +146,10 @@ impl VaultManager {
*self.state.write().await = VaultState::Migrating { progress: 0.0 };
tokio::spawn(async move {
+ // Write sentinel FIRST — if we crash mid-encryption, startup
+ // still knows the vault is locked and won't try to open the DB.
+ let _ = std::fs::write(&sentinel, "locked");
+
// Encrypt DB file (must be closed by caller already)
if db_path.exists() {
info!("encrypting db.sqlite...");
@@ -175,8 +179,7 @@ impl VaultManager {
}
}
- // Write sentinel and mark locked
- let _ = std::fs::write(&sentinel, "locked");
+ // Mark locked (sentinel already written at start)
*vault_state.write().await = VaultState::Locked;
info!("vault locked");