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: resolve hydration mismatch and archive/init 500 error

Louis Beaumont8f79c33ce8d6
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 0fe95c4e1..59dd6f796 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -2293,7 +2293,7 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
<Plus size={14} />
<span>New</span>
</Button>
- <kbd className="hidden sm:inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono text-muted-foreground bg-muted/50 border border-border/50 rounded">
+ <kbd suppressHydrationWarning className="hidden sm:inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono text-muted-foreground bg-muted/50 border border-border/50 rounded">
{formatShortcutDisplay(settings.showChatShortcut || (isMac ? "Control+Super+L" : "Alt+L"), isMac)}
</kbd>
</div>
diff --git a/crates/screenpipe-server/src/archive.rs b/crates/screenpipe-server/src/archive.rs
index eefa69089..24f9b1d0b 100644
--- a/crates/screenpipe-server/src/archive.rs
+++ b/crates/screenpipe-server/src/archive.rs
@@ -145,43 +145,54 @@ pub async fn archive_init(
Uuid::new_v4().to_string()
};
- let device_name = hostname::get()
- .map(|h| h.to_string_lossy().to_string())
- .unwrap_or_else(|_| "Unknown".to_string());
- let device_os = std::env::consts::OS.to_string();
-
- // Create SyncManager
- let config = SyncClientConfig::new(
- request.token.clone(),
- machine_id.clone(),
- device_name,
- device_os,
- );
-
- let manager = SyncManager::new(config).map_err(|e| {
- error!("archive: failed to create sync manager: {}", e);
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(json!({"error": format!("failed to create sync manager: {}", e)})),
- )
- })?;
+ // Reuse the sync manager if sync is already initialized (same encryption keys).
+ // This avoids the AEAD decryption failure that occurs when archive derives a
+ // different password than what sync used to encrypt the master key.
+ let manager = {
+ let sync_guard = state.sync_state.read().await;
+ if let Some(ref sync_rt) = *sync_guard {
+ info!("archive: reusing sync manager (already initialized)");
+ sync_rt.manager.clone()
+ } else {
+ drop(sync_guard);
+
+ let device_name = hostname::get()
+ .map(|h| h.to_string_lossy().to_string())
+ .unwrap_or_else(|_| "Unknown".to_string());
+ let device_os = std::env::consts::OS.to_string();
+
+ let config = SyncClientConfig::new(
+ request.token.clone(),
+ machine_id.clone(),
+ device_name,
+ device_os,
+ );
- // Derive encryption password deterministically from the user's token.
- // Same account = same token = same key on every device. No password needed.
- let password = format!(
- "screenpipe-archive-{}",
- format!("{:x}", md5::compute(request.token.as_bytes()))
- );
+ let mgr = SyncManager::new(config).map_err(|e| {
+ error!("archive: failed to create sync manager: {}", e);
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(json!({"error": format!("failed to create sync manager: {}", e)})),
+ )
+ })?;
+
+ // Derive encryption password from the token (only used when sync is not active)
+ let password = format!(
+ "screenpipe-archive-{}",
+ format!("{:x}", md5::compute(request.token.as_bytes()))
+ );
- manager.initialize(&password).await.map_err(|e| {
- error!("archive: failed to initialize encryption: {}", e);
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(json!({"error": format!("failed to initialize encryption: {}", e)})),
- )
- })?;
+ mgr.initialize(&password).await.map_err(|e| {
+ error!("archive: failed to initialize encryption: {}", e);
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(json!({"error": format!("failed to initialize encryption: {}", e)})),
+ )
+ })?;
- let manager = Arc::new(manager);
+ Arc::new(mgr)
+ }
+ };
let archive_config = ArchiveConfig {
enabled: true,