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(enterprise): make local retention reachable for headless fleets

Louis Beaumonted922d9d9d08
diff --git a/apps/screenpipe-app-tauri/lib/hooks/managed-settings.test.ts b/apps/screenpipe-app-tauri/lib/hooks/managed-settings.test.ts
index 2c07c413f..65e267af8 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/managed-settings.test.ts
+++ b/apps/screenpipe-app-tauri/lib/hooks/managed-settings.test.ts
@@ -200,6 +200,39 @@ describe("computeManagedSettingUpdates", () => {
expect(r.liveChanged).toBe(true);
});
+ // Regression: an org with the Storage tab hidden had no reachable retention
+ // control — the policy column existed but never reached the device, so local
+ // databases grew unbounded for months.
+ it("enforces local retention (enabled + window + mode) as engine settings", () => {
+ const r = computeManagedSettingUpdates(
+ {
+ localRetentionEnabled: "true",
+ localRetentionDays: 7,
+ localRetentionMode: "all",
+ },
+ { localRetentionEnabled: false, localRetentionDays: 14, localRetentionMode: "media" },
+ );
+ expect(r.engineUpdates.localRetentionEnabled).toBe(true);
+ expect(r.engineUpdates.localRetentionDays).toBe(7);
+ expect(r.engineUpdates.localRetentionMode).toBe("all");
+ // The recorder restart is what re-runs auto_start_retention on device.
+ expect(r.engineChanged).toBe(true);
+ });
+
+ it("accepts every retention mode and rejects an out-of-range window", () => {
+ for (const mode of ["media", "lean", "all"]) {
+ const r = computeManagedSettingUpdates({ localRetentionMode: mode }, {});
+ expect(r.engineUpdates.localRetentionMode).toBe(mode);
+ }
+ expect(
+ computeManagedSettingUpdates({ localRetentionMode: "wipe" }, {}).engineUpdates,
+ ).not.toHaveProperty("localRetentionMode");
+ // 0 days would mean "delete everything, right now".
+ expect(
+ computeManagedSettingUpdates({ localRetentionDays: 0 }, {}).engineUpdates,
+ ).not.toHaveProperty("localRetentionDays");
+ });
+
it("has unique policy and device keys", () => {
const policyKeys = MANAGED_SETTING_DEFINITIONS.map((definition) => definition.policyKey);
const deviceKeys = MANAGED_SETTING_DEFINITIONS.map((definition) => definition.deviceKey);
diff --git a/apps/screenpipe-app-tauri/lib/hooks/managed-settings.ts b/apps/screenpipe-app-tauri/lib/hooks/managed-settings.ts
index 36074e51a..4efb46186 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/managed-settings.ts
+++ b/apps/screenpipe-app-tauri/lib/hooks/managed-settings.ts
@@ -155,6 +155,16 @@ export const MANAGED_SETTING_DEFINITIONS: readonly ManagedSettingDefinition[] =
enumeration("piiBackend", ["local", "tinfoil"], "local"),
stringArray("piiRedactionLabels", ["secret"], ["secret"]),
+ // Local disk retention. Without these the only way an org can cap local
+ // growth is the Storage settings tab, which a headless deployment hides —
+ // so a fleet with the UI hidden had no reachable retention control at all
+ // and its databases grew unbounded. Marked "engine" so a policy change
+ // restarts the recorder, and that restart is what re-runs
+ // `auto_start_retention` and pushes the new window to the running engine.
+ bool("localRetentionEnabled", false),
+ number("localRetentionDays", 1, 3650, 14),
+ enumeration("localRetentionMode", ["media", "lean", "all"], "media"),
+
bool("listen_on_lan", false, "engine", "listenOnLan"),
bool("analyticsEnabled", true, "live"),
];
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
index 98960b2c5..98392388c 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs
@@ -431,6 +431,21 @@ pub async fn auto_start_archive(app: &AppHandle) {
}
/// Auto-start local data retention on app launch if previously enabled.
+/// Which `RetentionMode` a stored `localRetentionMode` means.
+///
+/// Every variant the engine accepts is listed here. An earlier version omitted
+/// `lean`, so picking it silently ran `media` instead — that frees disk files
+/// but leaves db.sqlite exactly as large, the opposite of what `lean` is for.
+/// Unknown/missing values stay on the conservative `media`, which only deletes
+/// media files and never database rows.
+fn retention_mode_from_settings(stored: Option<&serde_json::Value>) -> &'static str {
+ match stored.and_then(|v| v.as_str()) {
+ Some("all") => "all",
+ Some("lean") => "lean",
+ _ => "media",
+ }
+}
+
pub async fn auto_start_retention(app: &AppHandle) {
let settings = match SettingsStore::get(app) {
Ok(Some(s)) => s,
@@ -478,12 +493,7 @@ pub async fn auto_start_retention(app: &AppHandle) {
let mode = if is_free_plan {
"all"
} else {
- settings
- .extra
- .get("localRetentionMode")
- .and_then(|v| v.as_str())
- .filter(|s| *s == "media" || *s == "all")
- .unwrap_or("media")
+ retention_mode_from_settings(settings.extra.get("localRetentionMode"))
};
let client = reqwest::Client::new();
@@ -529,3 +539,28 @@ pub async fn delete_cloud_data(state: State<'_, SyncState>) -> Result<(), String
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::retention_mode_from_settings;
+ use serde_json::json;
+
+ #[test]
+ fn retention_mode_accepts_every_engine_variant() {
+ assert_eq!(retention_mode_from_settings(Some(&json!("media"))), "media");
+ assert_eq!(retention_mode_from_settings(Some(&json!("all"))), "all");
+ // Regression: "lean" used to fall through to "media", so the one mode
+ // that shrinks db.sqlite quietly did nothing.
+ assert_eq!(retention_mode_from_settings(Some(&json!("lean"))), "lean");
+ }
+
+ #[test]
+ fn retention_mode_falls_back_to_the_non_destructive_default() {
+ // Unset, wrong type, or a value this build doesn't know must never
+ // escalate to row deletion.
+ assert_eq!(retention_mode_from_settings(None), "media");
+ assert_eq!(retention_mode_from_settings(Some(&json!(7))), "media");
+ assert_eq!(retention_mode_from_settings(Some(&json!("wipe"))), "media");
+ assert_eq!(retention_mode_from_settings(Some(&json!(null))), "media");
+ }
+}