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(settings): accept scrubbed legacy user id (#6789)

Ezra Ellette7ded3c132196
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
index cf9cd997f..021c2748c 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
@@ -3385,6 +3385,41 @@ mod tests {
);
}
+ /// Regression for DM/KE/KF: the auth-token migration intentionally scrubs
+ /// a JWT-shaped legacy `settings.userId` to JSON null. That compatibility
+ /// value must not make the entire persisted settings object unreadable and
+ /// turn an otherwise verified account into the recording gate's Unknown
+ /// state.
+ #[test]
+ fn scrubbed_legacy_user_id_keeps_verified_recording_access() {
+ let mut persisted = SettingsStore::default();
+ persisted.user.id = Some("user_free".to_string());
+ persisted.user.subscription_plan = Some("none".to_string());
+ persisted.user.entitlement = Some(json!({
+ "active": true,
+ "plan": "none",
+ "source": "free",
+ "checked_at": chrono::Utc::now().to_rfc3339(),
+ "features": { "app": true, "cloud": false }
+ }));
+ persisted.recording.audio_transcription_engine = "parakeet".to_string();
+
+ let mut settings_json = serde_json::to_value(&persisted).unwrap();
+ settings_json["userId"] = Value::Null;
+
+ let recovered: SettingsStore = serde_json::from_value(settings_json.clone())
+ .expect("a store with only the proven legacy userId null must deserialize");
+ assert_eq!(recovered.recording.user_id, "");
+ assert_eq!(recovered.recording.audio_transcription_engine, "parakeet");
+ assert_eq!(recovered.local_plan_policy(), LocalPlanPolicy::VerifiedFree);
+
+ settings_json["userId"] = json!({ "unexpected": true });
+ assert!(
+ serde_json::from_value::<SettingsStore>(settings_json).is_err(),
+ "malformed non-null userId must remain an error"
+ );
+ }
+
/// Regression for the Windows 2.6.20+ onboarding outage: a torn `store.bin`
/// must be recovered, not converted into a permanent recording lockout.
///
diff --git a/crates/screenpipe-config/src/recording.rs b/crates/screenpipe-config/src/recording.rs
index 141a8a54c..904b8f10d 100644
--- a/crates/screenpipe-config/src/recording.rs
+++ b/crates/screenpipe-config/src/recording.rs
@@ -6,6 +6,16 @@
use serde::{Deserialize, Deserializer, Serialize};
+/// The auth-token migration scrubs a JWT-shaped legacy `userId` by persisting
+/// JSON `null`. Keep the historical empty-string sentinel when that store is
+/// read back without accepting nulls for unrelated recording settings.
+fn deserialize_null_user_id_as_default<'de, D>(deserializer: D) -> Result<String, D::Error>
+where
+ D: Deserializer<'de>,
+{
+ Ok(Option::<String>::deserialize(deserializer)?.unwrap_or_default())
+}
+
/// Older desktop builds persisted a single selected monitor as a string, while
/// current builds persist an array. Accept both shapes so an upgrade preserves
/// the user's selection instead of rejecting the entire settings store.
@@ -712,7 +722,10 @@ pub struct RecordingSettings {
// ── Cloud / Auth ───────────────────────────────────────────────────
/// Screenpipe cloud user ID. Empty string means not logged in.
/// Kept as String (not Option) to match existing store.bin schema.
- #[serde(rename = "userId")]
+ #[serde(
+ rename = "userId",
+ deserialize_with = "deserialize_null_user_id_as_default"
+ )]
pub user_id: String,
/// Display name for speaker identification.
@@ -1300,6 +1313,33 @@ mod tests {
assert!(!settings.enhanced_incognito_detection); // old stores stay permission-free
}
+ #[test]
+ fn scrubbed_legacy_user_id_null_uses_empty_string_sentinel() {
+ let settings: RecordingSettings = serde_json::from_str(
+ r#"{
+ "disableAudio": false,
+ "audioTranscriptionEngine": "whisper-large-v3-turbo",
+ "audioDevices": ["default"],
+ "monitorIds": ["default"],
+ "videoQuality": "balanced",
+ "userId": null
+ }"#,
+ )
+ .expect("the auth-token scrubbed store must remain readable");
+
+ assert_eq!(settings.user_id, "");
+ assert_eq!(
+ settings.audio_transcription_engine,
+ "whisper-large-v3-turbo"
+ );
+
+ let malformed = serde_json::from_str::<RecordingSettings>(r#"{"userId": 42}"#);
+ assert!(
+ malformed.is_err(),
+ "non-null malformed userId must still fail"
+ );
+ }
+
#[test]
fn flatten_simulation() {
// Simulates what happens when SettingsStore uses #[serde(flatten)]