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
telemetry(audio): dedup per-device errors + rate-limit processing errors
Louis Beaumontc8b8395129a6
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rsindex 3f3681482..aceea356f 100644--- a/crates/screenpipe-audio/src/audio_manager/manager.rs+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs@@ -8,10 +8,10 @@ use std::{collections::HashSet,path::PathBuf,sync::{- atomic::{AtomicBool, Ordering},+ atomic::{AtomicBool, AtomicU64, Ordering},Arc,},- time::Duration,+ time::{Duration, SystemTime, UNIX_EPOCH},};use tokio::{sync::{Mutex, RwLock},@@ -50,6 +50,34 @@ use crate::{use chrono::{DateTime, Utc};use serde::{Deserialize, Serialize};+/// Rate-limiter for the "Error processing audio" log.+///+/// Why: when the ONNX segmentation/embedding model file is missing or+/// corrupt, every audio chunk fails with the same error — one user hit+/// 583 events from the model-missing error alone (Sentry SCREENPIPE-CLI).+/// Firing to Sentry on every chunk is noise; once every 5 minutes is+/// enough to see the problem. Below-threshold hits still go to debug!().+///+/// A single shared timestamp is intentional: the error class doesn't+/// matter for rate-limiting purposes — we just want to stop flooding+/// Sentry during a sustained failure.+static LAST_AUDIO_PROCESS_ERROR_EPOCH_SECS: AtomicU64 = AtomicU64::new(0);+const AUDIO_PROCESS_ERROR_SENTRY_INTERVAL_SECS: u64 = 300;++fn log_audio_process_error(e: &anyhow::Error) {+ let now = SystemTime::now()+ .duration_since(UNIX_EPOCH)+ .map(|d| d.as_secs())+ .unwrap_or(0);+ let last = LAST_AUDIO_PROCESS_ERROR_EPOCH_SECS.load(Ordering::Relaxed);+ if now.saturating_sub(last) >= AUDIO_PROCESS_ERROR_SENTRY_INTERVAL_SECS {+ LAST_AUDIO_PROCESS_ERROR_EPOCH_SECS.store(now, Ordering::Relaxed);+ error!("Error processing audio: {:?}", e);+ } else {+ debug!("Error processing audio (rate-limited): {:?}", e);+ }+}+#[derive(Debug, Clone, Eq, PartialEq)]pub enum AudioManagerStatus {Running,@@ -684,7 +712,13 @@ impl AudioManager {}}if !inserted {- error!("audio chunk DB insert failed after 3 retries, data may be missing from timeline: {}", path);+ // path is a structured field so Sentry dedups the+ // issue across different devices; otherwise every+ // device name creates a new Sentry issue.+ error!(+ audio_chunk_path = %path,+ "audio chunk DB insert failed after 3 retries, data may be missing from timeline"+ );}Some(path)}@@ -768,7 +802,7 @@ impl AudioManager {.await{metrics.record_process_error();- error!("Error processing audio: {:?}", e);+ log_audio_process_error(&e);}}} else {@@ -789,7 +823,7 @@ impl AudioManager {.await{metrics.record_process_error();- error!("Error processing audio: {:?}", e);+ log_audio_process_error(&e);}}} else {@@ -810,7 +844,7 @@ impl AudioManager {.await{metrics.record_process_error();- error!("Error processing audio: {:?}", e);+ log_audio_process_error(&e);}}}diff --git a/crates/screenpipe-audio/src/transcription/transcription_result.rs b/crates/screenpipe-audio/src/transcription/transcription_result.rsindex ba59602ae..4b6f55daa 100644--- a/crates/screenpipe-audio/src/transcription/transcription_result.rs+++ b/crates/screenpipe-audio/src/transcription/transcription_result.rs@@ -166,9 +166,12 @@ pub async fn process_transcription_result(tokio::time::sleep(std::time::Duration::from_millis(500 * (retry as u64 + 1))).await;} else {+ // device as a structured field so Sentry dedups across+ // different devices into a single issue.error!(- "Failed to insert audio chunk+transcription for device {} after 3 retries: {}",- result.input.device, e+ device = %result.input.device,+ error = %e,+ "Failed to insert audio chunk+transcription after 3 retries");}}