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(audio,timeline): stop device_monitor 'default' spam; restore day-picker (#3508)

Louis Beaumontf0ad46149d3f
diff --git a/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts b/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
index 9ebe2678b..2407bf8f9 100644
--- a/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
+++ b/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
@@ -37,6 +37,9 @@ export async function listDaysWithFrames(): Promise<Set<string>> {
// audio_chunks has no timestamp column itself; the recording time
// lives on audio_transcriptions, which is what the timeline UI also
// uses to render the audio track.
+ // LIMIT is required by the /raw_sql validator; bound it to the max so
+ // future heavy users with many recording days don't get clipped.
+ // One row per local-calendar day, so 10000 = ~27 years of headroom.
const query = `
SELECT DISTINCT DATE(timestamp, 'localtime') AS day FROM (
SELECT timestamp FROM frames WHERE timestamp IS NOT NULL
@@ -44,6 +47,7 @@ export async function listDaysWithFrames(): Promise<Set<string>> {
SELECT timestamp FROM audio_transcriptions WHERE timestamp IS NOT NULL
)
ORDER BY day
+ LIMIT 10000
`;
const response = await localFetch("/raw_sql", {
method: "POST",
diff --git a/crates/screenpipe-audio/src/audio_manager/device_monitor.rs b/crates/screenpipe-audio/src/audio_manager/device_monitor.rs
index 25bc257f3..5450ef1e0 100644
--- a/crates/screenpipe-audio/src/audio_manager/device_monitor.rs
+++ b/crates/screenpipe-audio/src/audio_manager/device_monitor.rs
@@ -194,8 +194,9 @@ pub async fn start_device_monitor(
// started different devices from saved config.
let mut needs_initial_sync = true;
- // One-time migration flag for legacy "Display N (output)" device names
- #[cfg(target_os = "macos")]
+ // One-time migration flag: on first loop iteration, scrub the bare
+ // "default" sentinel (all platforms) and migrate legacy "Display N
+ // (output)" names to "System Audio (output)" (macOS only).
let mut legacy_migrated = false;
loop {
@@ -227,6 +228,34 @@ pub async fn start_device_monitor(
}
let enabled_devices = audio_manager.enabled_devices().await;
+ // Scrub the legacy bare "default" sentinel from `enabled_devices`
+ // once per session. Older versions persisted "default" to mean
+ // "follow the system default device"; today that's represented
+ // by the `use_system_default_audio` flag, and modern
+ // `start_device` only ever inserts names with an (input)/(output)
+ // suffix. The stray entry has no behavioral effect (recording
+ // proceeds on the resolved devices) but caused the monitor below
+ // to ERROR every poll forever.
+ //
+ // Narrowed to the literal sentinel so that an unplugged real
+ // device persisted under a bare name doesn't get silently
+ // dropped from the user's enabled set.
+ if !legacy_migrated {
+ let sentinels: Vec<String> = enabled_devices
+ .iter()
+ .filter(|name| name.trim().eq_ignore_ascii_case("default"))
+ .cloned()
+ .collect();
+ for name in &sentinels {
+ info!(
+ "[DEVICE_RECOVERY] dropping legacy '{}' sentinel from enabled_devices (use_system_default_audio supersedes it)",
+ name
+ );
+ audio_manager.forget_device(name).await;
+ }
+ }
+ let enabled_devices = audio_manager.enabled_devices().await;
+
// Migrate legacy "Display N (output)" device names to "System Audio (output)".
// This handles upgrades from versions that tracked per-display output devices.
#[cfg(target_os = "macos")]
@@ -254,6 +283,12 @@ pub async fn start_device_monitor(
}
}
}
+ // Non-macOS platforms still need to flip the flag so the scrub
+ // above runs exactly once.
+ #[cfg(not(target_os = "macos"))]
+ {
+ legacy_migrated = true;
+ }
// Handle "Follow System Default" mode
if audio_manager.use_system_default_audio().await {
@@ -867,7 +902,7 @@ pub async fn start_device_monitor(
let device = match parse_audio_device(&device_name) {
Ok(device) => device,
Err(e) => {
- error!("Device name {} invalid: {}", device_name, e);
+ debug!("Device name {} invalid: {}", device_name, e);
continue;
}
};
@@ -909,7 +944,7 @@ pub async fn start_device_monitor(
let device = match parse_audio_device(device_name) {
Ok(device) => device,
Err(e) => {
- error!("Device name {} invalid: {}", device_name, e);
+ debug!("Device name {} invalid: {}", device_name, e);
continue;
}
};
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rs
index 8c05d38d2..c0bb1e958 100644
--- a/crates/screenpipe-audio/src/audio_manager/manager.rs
+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs
@@ -1040,6 +1040,18 @@ impl AudioManager {
self.options.read().await.enabled_devices.clone()
}
+ /// Drop a name from `enabled_devices` without trying to parse it or stop
+ /// a running stream. Used to scrub legacy sentinel entries (e.g. bare
+ /// "default" from older versions) that have no corresponding parseable
+ /// device and would otherwise stay in the set forever.
+ pub async fn forget_device(&self, device_name: &str) {
+ self.options
+ .write()
+ .await
+ .enabled_devices
+ .remove(device_name);
+ }
+
/// Stop all SCK-based (Output) audio devices for DRM pause.
/// Input (microphone) devices are left running. Unlike `stop_device()`,
/// this does NOT remove devices from `enabled_devices` since DRM pause