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
fix: detect DB pool exhaustion in health endpoint
Mykola Kotliarenko6d782e33ed72
diff --git a/crates/screenpipe-engine/src/routes/health.rs b/crates/screenpipe-engine/src/routes/health.rsindex d00427e65..29ab2f0d8 100644--- a/crates/screenpipe-engine/src/routes/health.rs+++ b/crates/screenpipe-engine/src/routes/health.rs@@ -183,10 +183,52 @@ pub async fn health_check(State(state): State<Arc<AppState>>) -> JsonResponse<Helet last_audio_ts = audio_snap.last_db_write_ts;let now = Utc::now();+ let now_ts = now.timestamp() as u64;// 60 seconds — tight enough to detect real stalls, loose enough to// tolerate adaptive FPS (0.1-0.5 fps) and brief DB contention spikes.let threshold_secs = 60u64;+ // Detect DB write stalls: capture loop is alive (heartbeat fresh) but DB+ // writes have stopped. This indicates pool exhaustion or DB lock contention+ // — data is being captured but silently lost.+ let vision_db_write_stalled = if !state.vision_disabled+ && vision_snap.last_capture_attempt_ts > 0+ && vision_snap.uptime_secs > 120.0+ {+ let capture_fresh = now_ts.saturating_sub(vision_snap.last_capture_attempt_ts)+ < threshold_secs;+ let db_stale = vision_snap.last_db_write_ts == 0+ || now_ts.saturating_sub(vision_snap.last_db_write_ts) > threshold_secs;+ let stalled = capture_fresh && db_stale;+ if stalled {+ warn!(+ "health_check: vision DB writes stalled — capture heartbeat {}s ago but last DB write {}s ago (pool exhaustion likely)",+ now_ts.saturating_sub(vision_snap.last_capture_attempt_ts),+ if vision_snap.last_db_write_ts > 0 { now_ts.saturating_sub(vision_snap.last_db_write_ts) } else { 0 },+ );+ }+ stalled+ } else {+ false+ };++ let audio_db_write_stalled = if !state.audio_disabled+ && global_audio_active+ && audio_snap.uptime_secs > 120.0+ {+ let db_stale = audio_snap.last_db_write_ts == 0+ || now_ts.saturating_sub(audio_snap.last_db_write_ts) > threshold_secs;+ if db_stale {+ warn!(+ "health_check: audio DB writes stalled — devices active but last DB write {}s ago (pool exhaustion likely)",+ if audio_snap.last_db_write_ts > 0 { now_ts.saturating_sub(audio_snap.last_db_write_ts) } else { 0 },+ );+ }+ db_stale+ } else {+ false+ };+let frame_status = if state.vision_disabled {"disabled"} else if crate::sleep_monitor::screen_is_locked() {@@ -249,7 +291,7 @@ pub async fn health_check(State(state): State<Arc<AppState>>) -> JsonResponse<Hevision_snap.avg_db_latency_ms);}- high_drop_rate || high_db_latency+ high_drop_rate || high_db_latency || vision_db_write_stalled} else {false};@@ -257,15 +299,14 @@ pub async fn health_check(State(state): State<Arc<AppState>>) -> JsonResponse<He// Audio degradation: chunks_channel_full > 0 means the Whisper consumer// couldn't keep up and audio was dropped even after a 30s backpressure wait.let audio_degraded = if !state.audio_disabled && audio_snap.uptime_secs > 120.0 {- if audio_snap.chunks_channel_full > 0 {+ let channel_full = audio_snap.chunks_channel_full > 0;+ if channel_full {warn!("health_check: {} audio chunk(s) dropped (transcription engine too slow)",audio_snap.chunks_channel_full);- true- } else {- false}+ channel_full || audio_db_write_stalled} else {false};@@ -311,12 +352,26 @@ pub async fn health_check(State(state): State<Arc<AppState>>) -> JsonResponse<Hevision_snap.avg_db_latency_ms));}+ if vision_db_write_stalled {+ detail_parts.push(format!(+ "vision DB writes stalled for {}s — capture running but data not saved (restart recommended)",+ now_ts.saturating_sub(vision_snap.last_db_write_ts)+ ));+ }}if audio_degraded {- detail_parts.push(format!(- "{} audio chunk(s) dropped — transcription too slow",- audio_snap.chunks_channel_full- ));+ if audio_snap.chunks_channel_full > 0 {+ detail_parts.push(format!(+ "{} audio chunk(s) dropped — transcription too slow",+ audio_snap.chunks_channel_full+ ));+ }+ if audio_db_write_stalled {+ detail_parts.push(format!(+ "audio DB writes stalled for {}s — devices active but data not saved (restart recommended)",+ now_ts.saturating_sub(audio_snap.last_db_write_ts)+ ));+ }}let systems_str = unhealthy_systems.join(", ");