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(enterprise-sync): re-read local api auth key on every request
Louis Beaumont2d13533b6e8a
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 8500277ef..4409bedfc 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -10580,7 +10580,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.4.251"+version = "2.4.249"dependencies = ["aes","aes-gcm",@@ -10635,7 +10635,6 @@ dependencies = ["screenpipe-redact","screenpipe-screen","screenpipe-secrets",- "screenpipe-sync","screenpipe-vault","security-framework","sentry 0.42.0",@@ -10836,7 +10835,6 @@ dependencies = ["reqwest 0.13.3","screenpipe-events","screenpipe-secrets",- "screenpipe-sync","screenpipe-vault","serde","serde_json",@@ -11054,26 +11052,6 @@ dependencies = ["tracing",]-[[package]]-name = "screenpipe-sync"-version = "0.3.339"-dependencies = [- "async-trait",- "base64 0.22.1",- "bytes",- "chacha20poly1305",- "hex",- "rand 0.8.5",- "reqwest 0.13.3",- "serde",- "serde_json",- "sha2 0.10.9",- "thiserror 1.0.69",- "tokio",- "tracing",- "zeroize",-]-[[package]]name = "screenpipe-vault"version = "0.3.339"diff --git a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rsindex dce6649f7..6a409c563 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs@@ -37,15 +37,23 @@ mod imp {pub(super) struct ScreenpipeLocalClient {api_url_base: String,- api_key: Option<String>,+ // App handle, so we can re-read the current api_auth_key from+ // `RecordingState` on every request. The previous implementation+ // captured the key once at startup — but `enterprise_sync::spawn`+ // runs *before* the recording server finishes booting, so the+ // snapshot was always `None`. Every subsequent /search call hit+ // a 403 because no Bearer header was attached, the sync task+ // backed off for an hour, and no telemetry ever made it to the+ // customer's storage backend.+ app: tauri::AppHandle,http: reqwest::Client,}impl ScreenpipeLocalClient {- pub fn new(api_url_base: String, api_key: Option<String>) -> Self {+ pub fn new(api_url_base: String, app: tauri::AppHandle) -> Self {Self {api_url_base,- api_key,+ app,http: reqwest::Client::builder().timeout(std::time::Duration::from_secs(30)).build()@@ -53,8 +61,12 @@ mod imp {}}+ fn current_api_key(&self) -> Option<String> {+ crate::recording::local_api_context_from_app(&self.app).api_key+ }+fn auth(&self, req: reqwest::RequestBuilder) -> reqwest::RequestBuilder {- match &self.api_key {+ match self.current_api_key() {Some(key) => req.header("Authorization", format!("Bearer {key}")),None => req,}@@ -480,9 +492,13 @@ mod imp {let api = local_api_context_from_app(app);let api_url_base = api.url("");+ // NB: don't capture `api.api_key` here — at spawn-time the+ // recording server hasn't finished booting and the key is+ // usually `None`. ScreenpipeLocalClient re-reads it from+ // RecordingState on every request via the app handle.let local: Arc<dyn LocalApiClient> = Arc::new(ScreenpipeLocalClient::new(api_url_base,- api.api_key.clone(),+ app.clone(),));let (tx, rx) = tokio::sync::watch::channel(false);