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): include the underlying error when an audio chunk insert fails (#4104)

Louis Beaumontbfd647136ece
diff --git a/crates/screenpipe-audio/src/audio_manager/manager.rs b/crates/screenpipe-audio/src/audio_manager/manager.rs
index 9ffae1336..a91e54fbc 100644
--- a/crates/screenpipe-audio/src/audio_manager/manager.rs
+++ b/crates/screenpipe-audio/src/audio_manager/manager.rs
@@ -830,6 +830,11 @@ impl AudioManager {
// Without this, audio files are written to disk but orphaned from the DB,
// causing silent data loss on the timeline.
let mut inserted = false;
+ // Keep the last failure so the final error log can name
+ // the actual cause. Without it every distinct DB failure
+ // (pool timeout vs stuck transaction vs cantopen) collapses
+ // into one undiagnosable Sentry issue.
+ let mut last_err: Option<String> = None;
for retry in 0..3u32 {
match db.insert_audio_chunk(&path, capture_dt).await {
Ok(_) => {
@@ -842,6 +847,7 @@ impl AudioManager {
retry + 1,
e
);
+ last_err = Some(format!("{:?}", e));
if retry < 2 {
tokio::time::sleep(std::time::Duration::from_millis(
500 * (retry as u64 + 1),
@@ -854,9 +860,12 @@ impl AudioManager {
if !inserted {
// path is a structured field so Sentry dedups the
// issue across different devices; otherwise every
- // device name creates a new Sentry issue.
+ // device name creates a new Sentry issue. error is a
+ // separate field so the underlying cause is filterable
+ // within that one issue rather than lost.
error!(
audio_chunk_path = %path,
+ error = last_err.as_deref().unwrap_or("unknown"),
"audio chunk DB insert failed after 3 retries, data may be missing from timeline"
);
}
diff --git a/docs/mockups/audio-error-context.png b/docs/mockups/audio-error-context.png
new file mode 100644
index 000000000..de9921ef4
Binary files /dev/null and b/docs/mockups/audio-error-context.png differ