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

obs(health): surface attempts/persisted/dedup counters in vision stall log

Louis Beaumont3bb1239e39a9
diff --git a/crates/screenpipe-engine/src/routes/health.rs b/crates/screenpipe-engine/src/routes/health.rs
index 04abf4b11..fc8fe1013 100644
--- a/crates/screenpipe-engine/src/routes/health.rs
+++ b/crates/screenpipe-engine/src/routes/health.rs
@@ -300,12 +300,39 @@ async fn health_check_inner(state: &Arc<AppState>) -> HealthCheckResponse {
// So a long delta here typically means the screen is static
// (idle user, slide deck, video call, IDE waiting) — NOT a
// stuck pipeline. Phrase it that way to stop the false-alarm
- // panic, and keep the pool stats inline since they're still
- // useful when the cause IS real backpressure.
+ // panic.
+ //
+ // Also surface lifetime counters so when the cause IS a real
+ // pipeline stall, the log alone is enough to pin which stage
+ // failed — without us having to email the user back asking
+ // for `sqlite3` row counts.
+ //
+ // The triage rule: `attempts - persisted - dedup_skips` is the
+ // silent-loss count over the whole session. If that number
+ // climbs while a stall warning is firing, frames are being
+ // captured but lost between attempt and write. If it stays
+ // flat, the stall is just dedup on a static screen.
+ //
+ // attempts climbing, persisted climbing, dedup ≈ 0
+ // → healthy active screen
+ // attempts climbing, persisted ≈ flat, dedup climbing
+ // → static screen / idle user (false alarm)
+ // attempts climbing, persisted ≈ flat, dedup flat
+ // → real silent loss between attempt and writer
+ // attempts flat too
+ // → capture itself paused (TCC revoke, display sleep)
+ let silent_loss = vision_snap
+ .capture_attempts
+ .saturating_sub(vision_snap.frames_db_written)
+ .saturating_sub(vision_snap.dedup_skips);
warn!(
- "health_check: no unique vision frame in {}s (capture heartbeat {}s ago — usually means a static screen / idle user, not a pipeline stall) | pool: read={}/{} idle, write={}/{} idle | suspected: {}",
+ "health_check: no unique vision frame in {}s (capture heartbeat {}s ago — usually means a static screen / idle user, not a pipeline stall) | lifetime: attempts={}, persisted={}, dedup={}, silent_loss={} | pool: read={}/{} idle, write={}/{} idle | suspected: {}",
now_ts.saturating_sub(vision_snap.last_db_write_ts),
now_ts.saturating_sub(vision_snap.last_capture_attempt_ts),
+ vision_snap.capture_attempts,
+ vision_snap.frames_db_written,
+ vision_snap.dedup_skips,
+ silent_loss,
ri, rs, wi, ws,
suspected_stall_cause(ri, wi),
);
diff --git a/crates/screenpipe-screen/src/metrics.rs b/crates/screenpipe-screen/src/metrics.rs
index af2b91b10..6393509be 100644
--- a/crates/screenpipe-screen/src/metrics.rs
+++ b/crates/screenpipe-screen/src/metrics.rs
@@ -96,6 +96,15 @@ pub struct PipelineMetrics {
/// Unix timestamp (secs) of most recent capture attempt — heartbeat proving the loop is alive
/// even when DB writes time out or are slow.
pub last_capture_attempt_ts: AtomicU64,
+ /// Total number of capture attempts made by the loop (every tick, regardless of outcome).
+ /// Pair with `frames_captured` (successful persists) to detect silent loss between
+ /// attempt and write — `attempts - captured - dedup_skips` over a window that should
+ /// not be growing is the leak signal.
+ pub capture_attempts: AtomicU64,
+ /// Total number of dedup skips — capture cycle ran but content matched a previous
+ /// frame so nothing was written. Subtract from `attempts - captured` to isolate
+ /// real silent-loss vs. expected static-screen behavior.
+ pub dedup_skips: AtomicU64,
// --- Rolling window for DB latency ---
/// Recent DB write latencies in microseconds (rolling window, not lifetime accumulator).
@@ -123,6 +132,8 @@ impl PipelineMetrics {
pipeline_stall_count: AtomicU64::new(0),
last_db_write_ts: AtomicU64::new(0),
last_capture_attempt_ts: AtomicU64::new(0),
+ capture_attempts: AtomicU64::new(0),
+ dedup_skips: AtomicU64::new(0),
db_latency_window: Mutex::new(RollingLatencyWindow::new()),
}
}
@@ -140,6 +151,7 @@ impl PipelineMetrics {
.unwrap()
.as_secs();
self.last_capture_attempt_ts.store(now, Ordering::Relaxed);
+ self.capture_attempts.fetch_add(1, Ordering::Relaxed);
}
/// Record that a frame was skipped by similarity check.
@@ -180,6 +192,7 @@ impl PipelineMetrics {
.unwrap()
.as_secs();
self.last_db_write_ts.store(now, Ordering::Relaxed);
+ self.dedup_skips.fetch_add(1, Ordering::Relaxed);
}
/// Record a frame inserted into DB.
@@ -294,6 +307,8 @@ impl PipelineMetrics {
pipeline_stall_count: self.pipeline_stall_count.load(Ordering::Relaxed),
last_db_write_ts: self.last_db_write_ts.load(Ordering::Relaxed),
last_capture_attempt_ts: self.last_capture_attempt_ts.load(Ordering::Relaxed),
+ capture_attempts: self.capture_attempts.load(Ordering::Relaxed),
+ dedup_skips: self.dedup_skips.load(Ordering::Relaxed),
}
}
}
@@ -330,4 +345,8 @@ pub struct MetricsSnapshot {
pub last_db_write_ts: u64,
/// Unix timestamp (secs) of most recent capture attempt (0 = none yet)
pub last_capture_attempt_ts: u64,
+ /// Total capture attempts (every loop tick, regardless of outcome).
+ pub capture_attempts: u64,
+ /// Total dedup skips (capture cycle ran but content matched previous frame).
+ pub dedup_skips: u64,
}