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: oauth connection status checks token validity, not just file existence
Louis Beaumont7ec561b82d44
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 3b92a719b..5ab9d53f9 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.3.55"+version = "2.3.56"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/crates/screenpipe-connect/src/connections/mod.rs b/crates/screenpipe-connect/src/connections/mod.rsindex 867d997f6..25d3b7b94 100644--- a/crates/screenpipe-connect/src/connections/mod.rs+++ b/crates/screenpipe-connect/src/connections/mod.rs@@ -213,7 +213,14 @@ impl ConnectionManager {let def = i.def();let is_oauth = i.oauth_config().is_some();let connected = if is_oauth {- !oauth::list_oauth_instances(def.id).is_empty()+ oauth::list_oauth_instances(def.id)+ .iter()+ .any(|inst| {+ oauth::is_oauth_instance_connected(+ def.id,+ inst.as_deref(),+ )+ })} else {store.get(def.id)diff --git a/crates/screenpipe-connect/src/oauth.rs b/crates/screenpipe-connect/src/oauth.rsindex 8c62309e8..277b6e3a2 100644--- a/crates/screenpipe-connect/src/oauth.rs+++ b/crates/screenpipe-connect/src/oauth.rs@@ -118,6 +118,32 @@ pub fn read_oauth_token_instance(integration_id: &str, instance: Option<&str>) -v["access_token"].as_str().map(String::from)}+/// Check if an OAuth instance is recoverable — has a valid token or a+/// refresh token that can be used to obtain a new one.+pub fn is_oauth_instance_connected(integration_id: &str, instance: Option<&str>) -> bool {+ let content = match std::fs::read_to_string(oauth_token_path_instance(+ integration_id,+ instance,+ )) {+ Ok(c) => c,+ Err(_) => return false,+ };+ let v: Value = match serde_json::from_str(&content) {+ Ok(v) => v,+ Err(_) => return false,+ };++ // Valid (non-expired) access token → connected+ if let Some(expires_at) = v["expires_at"].as_u64() {+ if unix_now() < expires_at.saturating_sub(60) {+ return v["access_token"].as_str().is_some();+ }+ }++ // Expired but has refresh token → recoverable (still "connected")+ v["refresh_token"].as_str().is_some()+}+/// Write the raw provider token response to disk, augmenting it with a/// computed `expires_at` unix timestamp if `expires_in` is present.pub fn write_oauth_token(integration_id: &str, data: &Value) -> Result<()> {@@ -237,9 +263,17 @@ pub async fn get_valid_token_instance(if let Some(token) = read_oauth_token_instance(integration_id, instance) {return Some(token);}- refresh_token_instance(client, integration_id, instance)- .await- .ok()+ match refresh_token_instance(client, integration_id, instance).await {+ Ok(token) => Some(token),+ Err(e) => {+ tracing::warn!(+ "oauth refresh failed for {}(instance={:?}): {e:#}",+ integration_id,+ instance,+ );+ None+ }+ }}// ---------------------------------------------------------------------------