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(retention,audio): harden new-install retention default and tap idle gate

Louis Beaumontb1974a3eae6b
diff --git a/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
index 3fe0f88c7..b85229517 100644
--- a/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
+++ b/apps/screenpipe-app-tauri/e2e/specs/windows-user-journey.spec.ts
@@ -847,6 +847,19 @@ describe("Windows user journey", function () {
"Storage settings did not show the local retention controls",
);
+ // Fresh installs default to media retention, and selecting the already
+ // active mode early-returns without a dialog. Switch to "off" first
+ // (idempotent when already off) so the media click below always opens
+ // the confirmation dialog.
+ const offRetentionMode = await $('[data-testid="retention-mode-off"]');
+ await offRetentionMode.waitForExist({ timeout: t(20_000) });
+ await offRetentionMode.scrollIntoView();
+ await offRetentionMode.click();
+ await waitForBodyText(
+ (bodyText) => bodyText.includes("currently: keeping everything forever."),
+ "Storage settings did not switch retention off before the media preview",
+ );
+
const mediaRetentionMode = await $('[data-testid="retention-mode-media"]');
await mediaRetentionMode.waitForExist({ timeout: t(20_000) });
await mediaRetentionMode.scrollIntoView();
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 69519c06d..27b4731ae 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -10927,7 +10927,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.5.90"
+version = "2.5.91"
dependencies = [
"aes 0.8.4",
"aes-gcm 0.10.3",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 444ebdf4b..d2c4d31df 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -1319,7 +1319,8 @@ async fn main() {
// models at load time — don't fetch the 834MB whisper file for them.
// If the user later switches to a whisper engine, TranscriptionEngine::new
// downloads it in the background ("will retry at server start").
- "disabled" | "parakeet" | "parakeet-mlx" | "qwen3-asr" => None,
+ "disabled" | "parakeet" | "parakeet-tdt-0.6b-v2" | "parakeet-mlx"
+ | "qwen3-asr" => None,
_ => {
use screenpipe_audio::core::engine::AudioTranscriptionEngine;
Some(std::sync::Arc::new(match store_for_download.recording.audio_transcription_engine.as_str() {
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/store.rs b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
index 4528827d3..a96af23f9 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/store.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/store.rs
@@ -1776,12 +1776,29 @@ pub fn init_store(app: &AppHandle) -> Result<SettingsStore, String> {
// Existing stores are never touched here: flipping the fallback for users who
// installed before this default would silently delete their old recordings —
// auto_start_retention() in sync.rs deliberately reads `localRetentionEnabled ?? false`.
+ //
+ // A fresh settings store is NOT proof of a fresh install: the store-recovery
+ // paths (unreadable encrypted store.bin with no snapshot, corrupted JSON with
+ // no healthy .last-good) fall back to an empty store for users with years of
+ // recordings, and machine migrations often copy ~/.screenpipe without the
+ // app-config dir. So additionally require that the data dir holds no existing
+ // recordings — retention may only default on when there is nothing to delete.
if is_new_store && !store.extra.contains_key("localRetentionEnabled") {
- store.extra.insert(
- "localRetentionEnabled".to_string(),
- serde_json::Value::Bool(true),
- );
- should_save = true;
+ let (data_dir, _) = crate::config::resolve_data_dir(&store.data_dir);
+ let has_existing_recordings = data_dir.join("db.sqlite").exists();
+ if has_existing_recordings {
+ tracing::info!(
+ "fresh settings store but existing recordings found at {:?} — \
+ leaving local retention off (likely store recovery or migration)",
+ data_dir
+ );
+ } else {
+ store.extra.insert(
+ "localRetentionEnabled".to_string(),
+ serde_json::Value::Bool(true),
+ );
+ should_save = true;
+ }
}
if should_save {
diff --git a/crates/screenpipe-audio/src/core/process_tap/macos.rs b/crates/screenpipe-audio/src/core/process_tap/macos.rs
index d19ad8a80..81646a567 100644
--- a/crates/screenpipe-audio/src/core/process_tap/macos.rs
+++ b/crates/screenpipe-audio/src/core/process_tap/macos.rs
@@ -862,31 +862,37 @@ fn merge_exclusion_audio_object_ids(
configured
}
-/// Best-effort check: is any process other than ours currently rendering audio
-/// output anywhere on the system? Distinguishes "expected silence" (nothing is
-/// playing, so a silent tap is healthy) from "suspicious silence" (an app is
-/// playing but the tap captures zeros — e.g. per-app routing bypasses the
-/// anchored device — where a rebuild can re-anchor). Our own process always
-/// runs IO on the tap's aggregate device, so it must be excluded.
+/// pid + bundle id of every process other than ours that CoreAudio reports as
+/// rendering audio output right now. Returns `None` when CoreAudio can't
+/// answer; callers must treat that as "possibly playing" so a genuinely broken
+/// tap is never left un-rebuilt.
///
-/// Returns `None` when CoreAudio can't answer; callers must treat that as
-/// "possibly playing" so a genuinely broken tap is never left un-rebuilt.
-fn any_other_process_rendering_audio() -> Option<bool> {
+/// NOTE: `is_running_output` is IO *registration*, not audible playback —
+/// always-on daemons (com.apple.CoreSpeech, remote-desktop helpers) report 1
+/// around the clock (device-level DEVICE_IS_RUNNING_SOMEWHERE is polluted the
+/// same way; measured empirically). A plain "is anything rendering?" check is
+/// therefore a no-op on such machines. The watchdog instead tracks the SET of
+/// renderer pids and treats only a NEWLY appearing renderer as evidence that
+/// audible playback started.
+fn other_audio_renderers() -> Option<Vec<(i32, Option<String>)>> {
let self_pid = std::process::id() as i32;
let processes = ca::Process::list().ok()?;
+ let mut renderers = Vec::new();
for process in processes {
- // Skip only entries that positively identify as us. Entries whose pid
- // can't be read still count: erring toward "something is playing"
- // keeps rebuilds allowed, which can only reproduce today's behavior,
- // never suppress a needed rebuild.
- if process.pid().map(|pid| pid == self_pid).unwrap_or(false) {
+ // Fail-open per entry: an unreadable pid becomes sentinel -1 (still
+ // counted as a renderer once), and an unreadable is_running_output
+ // counts as rendering. Erring toward "something is playing" keeps
+ // rebuilds allowed — it can only reproduce the old behavior, never
+ // suppress a needed rebuild.
+ let pid = process.pid().unwrap_or(-1);
+ if pid == self_pid {
continue;
}
- if process.is_running_output().unwrap_or(false) {
- return Some(true);
+ if process.is_running_output().unwrap_or(true) {
+ renderers.push((pid, process.bundle_id().ok().map(|b| b.to_string())));
}
}
- Some(false)
+ Some(renderers)
}
/// Create and start a CoreAudio Process Tap for system audio capture.
@@ -954,6 +960,10 @@ pub fn spawn_process_tap_capture(
let mut silence_started: Option<std::time::Instant> = None;
let mut last_rebuild: Option<std::time::Instant> = None;
let mut silence_rebuild_streak: u32 = 0;
+ // Renderer pids already observed registered during silence — treated
+ // as inaudible daemons by the silence gate below. Cleared whenever the
+ // tap captures real audio, so every playback source gets re-detected.
+ let mut known_renderers: std::collections::HashSet<i32> = std::collections::HashSet::new();
while !is_disconnected.load(Ordering::Relaxed) {
std::thread::sleep(POLL);
@@ -966,6 +976,7 @@ pub fn spawn_process_tap_capture(
if got_real_audio {
silence_started = None;
silence_rebuild_streak = 0;
+ known_renderers.clear();
} else if window_callbacks > 0 {
// Callback IS firing — buffers are just silent. Start (or
// continue) the silence window.
@@ -989,22 +1000,52 @@ pub fn spawn_process_tap_capture(
.map(|t| t.elapsed() >= silence_cooldown)
.unwrap_or(true);
- // Silence while nothing is playing anywhere is EXPECTED, not a
+ // Silence while nothing is audibly playing is EXPECTED, not a
// broken anchor — on a quiet machine the old behavior rebuilt the
- // tap all day (~150 generations/day observed). Only checked at the
- // moment a rebuild would fire, so the Process::list() enumeration
- // runs at most once per silence window, not per 500ms tick. On a
- // CoreAudio error (None) we fall through and rebuild as before.
- if should_rebuild_for_silence && any_other_process_rendering_audio() == Some(false) {
- debug!(
- "Process Tap silent for {}s on '{}' but no other process is \
- rendering audio — expected silence, skipping rebuild",
- WATCHDOG_SILENCE_SECS, current_uid
- );
- should_rebuild_for_silence = false;
- // Restart the window: once playback resumes, the tap gets a
- // fresh 45s to prove it captures audio before any rebuild.
- silence_started = None;
+ // tap all day (~150 generations/day observed). Registration-level
+ // signals can't tell "audible" apart from "registered" (always-on
+ // daemons like CoreSpeech report rendering 24/7), so the gate is a
+ // set-delta: renderers already registered through a silent window
+ // are treated as inaudible; only a NEWLY appearing renderer (a
+ // meeting app or player starting) counts as playback and lets the
+ // rebuild through. `known_renderers` clears whenever real audio is
+ // captured, so a tap that breaks mid-playback re-detects its source
+ // as "new" on the next window and still recovers. Only evaluated at
+ // the moment a rebuild would fire (at most once per silence
+ // window), never on the 500ms tick. On a CoreAudio error (None) we
+ // fall through and rebuild as before.
+ if should_rebuild_for_silence {
+ match other_audio_renderers() {
+ None => {}
+ Some(renderers) => {
+ let new_renderers: Vec<(i32, Option<String>)> = renderers
+ .iter()
+ .filter(|(pid, _)| !known_renderers.contains(pid))
+ .cloned()
+ .collect();
+ known_renderers.extend(renderers.iter().map(|(pid, _)| *pid));
+ if new_renderers.is_empty() {
+ debug!(
+ "Process Tap silent for {}s on '{}' with no new audio \
+ renderer ({} long-registered) — expected silence, \
+ skipping rebuild",
+ WATCHDOG_SILENCE_SECS,
+ current_uid,
+ renderers.len()
+ );
+ should_rebuild_for_silence = false;
+ // Restart the window: once a new renderer appears, the
+ // tap gets a fresh 45s to prove it captures audio
+ // before any rebuild.
+ silence_started = None;
+ } else {
+ debug!(
+ "new audio renderer(s) while Process Tap silent: {:?}",
+ new_renderers
+ );
+ }
+ }
+ }
}
// Check the current default output device UID.
@@ -1210,16 +1251,83 @@ mod tests {
assert_eq!(a, b);
}
+ #[test]
+ fn list_output_device_running_state() {
+ // Diagnostic (run with --nocapture): for every output-capable device,
+ // print is_running_somewhere BEFORE and DURING a live tap capture.
+ // Answers two questions: (a) do registered-but-inaudible daemons
+ // (CoreSpeech, remote desktop) keep output devices "running"? (b) does
+ // our own tap's aggregate mark its anchor sub-device as running?
+ if !is_process_tap_available() {
+ eprintln!("skipping: CoreAudio Process Tap unavailable");
+ return;
+ }
+ let print_states = |label: &str| {
+ if let Ok(devices) = ca::System::devices() {
+ for d in devices {
+ let has_output = d
+ .output_stream_cfg()
+ .map(|c| c.number_buffers() > 0)
+ .unwrap_or(false);
+ if !has_output {
+ continue;
+ }
+ let running: u32 = d
+ .prop(&ca::PropSelector::DEVICE_IS_RUNNING_SOMEWHERE.global_addr())
+ .unwrap_or(999);
+ println!(
+ "{label}: uid={:?} running_somewhere={running}",
+ d.uid().ok().map(|u| u.to_string()),
+ );
+ }
+ }
+ };
+ print_states("before-tap");
+ let (tx, _rx) = broadcast::channel(16);
+ let is_disconnected = Arc::new(AtomicBool::new(false));
+ if let Ok((_capture, _config, uid)) =
+ build_inclusion_capture(&[std::process::id() as i32], tx, is_disconnected)
+ {
+ std::thread::sleep(std::time::Duration::from_millis(1500));
+ println!("tap anchored to uid={uid}");
+ print_states("during-tap");
+ }
+ }
+
+ #[test]
+ fn list_current_audio_renderers() {
+ // Diagnostic (run with --nocapture): prints every process CoreAudio
+ // reports as rendering output right now. Used to check whether
+ // always-on IO daemons defeat the idle gate on a given machine.
+ let Ok(processes) = ca::Process::list() else {
+ println!("Process::list failed");
+ return;
+ };
+ for p in processes {
+ let out = p.is_running_output().unwrap_or(false);
+ if out {
+ println!(
+ "renderer: pid={:?} bundle={:?}",
+ p.pid().ok(),
+ p.bundle_id().ok().map(|b| b.to_string()),
+ );
+ }
+ }
+ println!("self pid = {}", std::process::id());
+ }
+
#[test]
fn other_process_audio_probe_answers() {
// Smoke test: on any Mac with coreaudiod the probe must produce an
- // answer (Some), never panic. Whether audio is playing depends on the
- // machine, so only the availability of an answer is asserted — the
- // watchdog treats None as "possibly playing" and keeps old behavior.
- let result = any_other_process_rendering_audio();
+ // answer (Some), never panic. Which renderers are registered depends
+ // on the machine, so only the availability of an answer and the
+ // self-exclusion are asserted — the watchdog treats None as "possibly
+ // playing" and keeps old behavior.
+ let renderers = other_audio_renderers().expect("CoreAudio process list should be readable");
+ let self_pid = std::process::id() as i32;
assert!(
- result.is_some(),
- "CoreAudio process list should be readable"
+ renderers.iter().all(|(pid, _)| *pid != self_pid),
+ "own process must be excluded from the renderer set"
);
}