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(health): expose unresolved focus and never-progressed capture
Louis Beaumont99f0fdb99c55
diff --git a/crates/screenpipe-engine/src/focus_aware_controller.rs b/crates/screenpipe-engine/src/focus_aware_controller.rsindex 21fe1b059..619e0fff7 100644--- a/crates/screenpipe-engine/src/focus_aware_controller.rs+++ b/crates/screenpipe-engine/src/focus_aware_controller.rs@@ -217,6 +217,19 @@ impl FocusAwareController {self.hosts_focus_for_identity(&MonitorIdentity::from_monitor(monitor))}+ /// A long-lived unresolved tracker must be visible to health consumers.+ /// Keep capture fail-closed: never attach global AX to an arbitrary display.+ pub fn resolution_degraded(&self) -> bool {+ let stale = self+ .last_event_time+ .lock()+ .ok()+ .is_some_and(|time| time.elapsed() >= STALE_FOCUS_CUTOFF);+ // A quiet event stream is normal. The platform's independent poll+ // remains authoritative; only unresolved focus after grace is a fault.+ stale && self.tracker.current().is_none()+ }+fn hosts_focus_for_identity(&self, identity: &MonitorIdentity) -> bool {let focus_is_fresh = self.last_event_time@@ -449,6 +462,24 @@ mod tests {fn stop(&self) {}}+ #[tokio::test]+ async fn unresolved_focus_is_visible_after_grace_and_recovers() {+ let identity = MonitorIdentity::runtime_id(1);+ let tracker = Arc::new(StaticFocusTracker::resolving(identity.clone()));+ let ctrl = FocusAwareController::new(tracker.clone());+ *tracker.current.lock().unwrap() = None;+ ctrl.set_unknown_for_test();+ assert!(!ctrl.resolution_degraded());+ ctrl.backdate_last_event_for_test(Instant::now() - Duration::from_secs(60));+ assert!(!ctrl.hosts_focus(1));+ assert!(!ctrl.hosts_focus(2));+ assert!(ctrl.resolution_degraded());+ *tracker.current.lock().unwrap() = Some(identity);+ assert!(!ctrl.resolution_degraded());+ assert!(ctrl.hosts_focus(1));+ assert!(!ctrl.hosts_focus(2));+ }+#[tokio::test]async fn initial_state_is_active_for_all_monitors() {let ctrl = make_ctrl();diff --git a/crates/screenpipe-engine/src/routes/health.rs b/crates/screenpipe-engine/src/routes/health.rsindex b2ae1350e..2bbf0ffb3 100644--- a/crates/screenpipe-engine/src/routes/health.rs+++ b/crates/screenpipe-engine/src/routes/health.rs@@ -97,6 +97,35 @@ fn audio_backlog_is_stalled(backlog_deep_and_old && no_recent_progress}+// This predicate is shared by the live health route and its regression eval.+fn vision_persistence_stalled(+ now: u64,+ last_attempt: u64,+ last_progress: u64,+ threshold: u64,+) -> bool {+ let capture_fresh = now.saturating_sub(last_attempt) < threshold;+ // Caller already gates this on >120s uptime and a real capture attempt.+ // Never having made progress is a failure after warm-up, not perpetual startup.+ let db_stale = last_progress == 0 || now.saturating_sub(last_progress) > threshold;+ capture_fresh && db_stale+}++#[cfg(test)]+mod persistence_startup_regression {+ use super::vision_persistence_stalled;+ #[test]+ fn active_capture_with_no_success_after_warmup_is_stalled() {+ assert!(vision_persistence_stalled(1000, 999, 0, 60));+ }+ #[test]+ fn recent_progress_and_idle_capture_are_not_write_stalls() {+ assert!(!vision_persistence_stalled(1000, 999, 990, 60));+ assert!(!vision_persistence_stalled(1000, 800, 800, 60));+ assert!(vision_persistence_stalled(1000, 999, 800, 60));+ }+}+/// Describe the most likely cause of a DB-write stall from pool stats./// Old message always said "pool exhaustion likely" which was wrong when the/// real cause was elsewhere (e.g. metrics gap on reconciliation path) and the@@ -723,7 +752,9 @@ pub struct HealthCheckResponse {/// How many times the persistent-failure hook fired (engine-restart requests).#[serde(default)]pub persistent_failure_signals: u64,- /// True when vision capture loop is alive but DB writes have stopped (pool exhaustion).+ /// macOS monitor focus has remained unresolved beyond the grace period.+ #[serde(default)]+ pub vision_focus_unresolved: bool,#[serde(default)]pub vision_db_write_stalled: bool,/// True when audio devices are active but DB writes have stopped (pool exhaustion).@@ -1032,6 +1063,7 @@ fn degraded_response() -> HealthCheckResponse {write_queue_consecutive_contention: 0,write_pool_reopens: 0,persistent_failure_signals: 0,+ vision_focus_unresolved: false,vision_db_write_stalled: false,audio_db_write_stalled: false,drm_content_paused: false,@@ -1324,14 +1356,12 @@ async fn health_check_inner(state: &Arc<AppState>) -> HealthCheckResponse {&& 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;- // Require at least one successful DB write before flagging a stall.- // last_db_write_ts == 0 means "never written yet" (pipeline warming up),- // not "writes stopped" — same fix as audio side.- 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;+ let stalled = vision_persistence_stalled(+ now_ts,+ vision_snap.last_capture_attempt_ts,+ vision_snap.last_db_write_ts,+ threshold_secs,+ );// Baseline captured on the transition into a stall so the classifier// sees what moved *during* it. Lifetime totals cannot answer@@ -2008,6 +2038,16 @@ async fn health_check_inner(state: &Arc<AppState>) -> HealthCheckResponse {write_queue_consecutive_contention: wqh.consecutive_contention_batches(),write_pool_reopens: wqh.write_pool_reopens(),persistent_failure_signals: wqh.persistent_failure_signals(),+ vision_focus_unresolved: cfg!(target_os = "macos")+ && vision_capture_expected+ && !state.vision_disabled+ && !crate::sleep_monitor::screen_is_locked()+ && state+ .vision_manager+ .load()+ .as_ref()+ .as_ref()+ .is_some_and(|manager| manager.focus_resolution_degraded()),vision_db_write_stalled,audio_db_write_stalled,drm_content_paused: crate::drm_detector::drm_content_paused(),@@ -2053,6 +2093,10 @@ fn add_health_reasons(response: &mut HealthCheckResponse) {"Check selected audio devices, permissions, and the transcription engine.",);}+ if response.vision_focus_unresolved {+ add("vision", "focus_unresolved", "capture is running without resolved monitor focus",+ "Inspect focus tracking and display topology. Frames remain unattributed until focus resolves.");+ }if response.write_queue_degraded {add("database",@@ -2713,6 +2757,23 @@ mod tests {assert!(!response.unhealthy_reasons.is_empty());}+ #[test]+ fn unresolved_focus_degrades_health_even_with_fresh_frames() {+ let mut response = dummy_response("healthy");+ response.vision_focus_unresolved = true;+ add_health_reasons(&mut response);+ assert_eq!(response.status, "degraded");+ assert_eq!(response.status_code, 503);+ assert!(response+ .unhealthy_reasons+ .iter()+ .any(|r| r["code"] == "focus_unresolved"));+ let mut recovered = dummy_response("healthy");+ add_health_reasons(&mut recovered);+ assert_eq!(recovered.status, "healthy");+ assert!(recovered.unhealthy_reasons.is_empty());+ }+fn dummy_response(status: &str) -> HealthCheckResponse {HealthCheckResponse {status: status.to_string(),@@ -2753,6 +2814,7 @@ mod tests {write_queue_consecutive_contention: 0,write_pool_reopens: 0,persistent_failure_signals: 0,+ vision_focus_unresolved: false,vision_db_write_stalled: false,audio_db_write_stalled: false,drm_content_paused: false,diff --git a/crates/screenpipe-engine/src/vision_manager/manager.rs b/crates/screenpipe-engine/src/vision_manager/manager.rsindex 29153d786..8c217cd64 100644--- a/crates/screenpipe-engine/src/vision_manager/manager.rs+++ b/crates/screenpipe-engine/src/vision_manager/manager.rs@@ -183,6 +183,11 @@ pub struct VisionManager {}impl VisionManager {+ /// Report unresolved attribution separately from capture-loop liveness.+ pub fn focus_resolution_degraded(&self) -> bool {+ self.focus_controller.resolution_degraded()+ }+/// Create a new VisionManagerpub fn new(config: VisionManagerConfig,diff --git a/docs/COVERAGE.md b/docs/COVERAGE.mdindex b6789d50c..4acfbc30f 100644--- a/docs/COVERAGE.md+++ b/docs/COVERAGE.md@@ -38,15 +38,15 @@ results and `cargo llvm-cov` data on top when judging release confidence.- Mapped suites: 37- Mapped Rust files: 399-- Active test blocks: 3889+- Active test blocks: 3893- Ignored/manual test blocks: 184-- Weighted coverage points: 3204.5+- Weighted coverage points: 3207.3| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score || --- | --- | --- | --- | --- | --- | --- | --- |-| windows | 33 | 3726 | 166 | 3131.5 | 21 | 11 | 100% |-| macos | 32 | 3769 | 145 | 3126.8 | 22 | 11 | 100% |-| linux | 29 | 3304 | 141 | 2749.8 | 20 | 11 | 100% |+| windows | 33 | 3730 | 166 | 3134.3 | 21 | 11 | 100% |+| macos | 32 | 3773 | 145 | 3129.6 | 22 | 11 | 100% |+| linux | 29 | 3308 | 141 | 2752.6 | 20 | 11 | 100% |## Refreshdiff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.mdindex 7208571e8..4901dacec 100644--- a/docs/coverage/CORE.md+++ b/docs/coverage/CORE.md@@ -9,10 +9,10 @@ confidence, and criticality.- Tracked crates: screenpipe-engine, screenpipe-db, screenpipe-sqlite-coordinator, screenpipe-audio, screenpipe-screen, screenpipe-a11y, screenpipe-fs- Mapped suites: 37- Mapped Rust files: 399-- Active test blocks: 3889+- Active test blocks: 3893- Ignored/manual test blocks: 184-- Declared test blocks: 4073-- Weighted coverage points: 3204.5+- Declared test blocks: 4077+- Weighted coverage points: 3207.3Confidence weights: strong=1.0, partial=0.7, conditional=0.4, smoke=0.3.Criticality weights: high=1.0, medium=0.7, low=0.4.@@ -23,15 +23,15 @@ are explicitly enabled in a runtime lane.| Platform | Suites | Active tests | Ignored tests | Weighted points | Layers | Flows | Critical score || --- | --- | --- | --- | --- | --- | --- | --- |-| windows | 33 | 3726 | 166 | 3131.5 | 21 | 11 | 100% |-| macos | 32 | 3769 | 145 | 3126.8 | 22 | 11 | 100% |-| linux | 29 | 3304 | 141 | 2749.8 | 20 | 11 | 100% |+| windows | 33 | 3730 | 166 | 3134.3 | 21 | 11 | 100% |+| macos | 32 | 3773 | 145 | 3129.6 | 22 | 11 | 100% |+| linux | 29 | 3308 | 141 | 2752.6 | 20 | 11 | 100% |## Crate Summary| Crate | Suites | Integration files | Source unit files | Active tests | Ignored tests | Weighted points | Flows || --- | --- | --- | --- | --- | --- | --- | --- |-| screenpipe-engine | 12 | 22 | 131 | 1858 | 53 | 1431.3 | 10 |+| screenpipe-engine | 12 | 22 | 131 | 1862 | 53 | 1434.1 | 10 || screenpipe-db | 5 | 68 | 28 | 629 | 31 | 599.4 | 9 || screenpipe-sqlite-coordinator | 1 | 0 | 3 | 27 | 0 | 27.0 | 2 || screenpipe-audio | 8 | 29 | 53 | 695 | 53 | 606.9 | 5 |@@ -69,21 +69,21 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| database | 7 suites / 585 active / 27 ignored / 555.4 pts | 7 suites / 585 active / 27 ignored / 555.4 pts | 7 suites / 585 active / 27 ignored / 555.4 pts || db-search | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts | 2 suites / 120 active / 9 ignored / 120.0 pts || engine-lifecycle | 6 suites / 270 active / 1 ignored / 242.0 pts | 6 suites / 270 active / 1 ignored / 242.0 pts | 6 suites / 266 active / 9 ignored / 241.1 pts |-| local-api | 3 suites / 481 active / 12 ignored / 340.6 pts | 3 suites / 481 active / 12 ignored / 340.6 pts | 3 suites / 481 active / 12 ignored / 340.6 pts |-| meeting | 6 suites / 1753 active / 32 ignored / 1434.4 pts | 6 suites / 1753 active / 32 ignored / 1434.4 pts | 4 suites / 1399 active / 28 ignored / 1104.1 pts |+| local-api | 3 suites / 484 active / 12 ignored / 342.7 pts | 3 suites / 484 active / 12 ignored / 342.7 pts | 3 suites / 484 active / 12 ignored / 342.7 pts |+| meeting | 6 suites / 1756 active / 32 ignored / 1436.5 pts | 6 suites / 1756 active / 32 ignored / 1436.5 pts | 4 suites / 1402 active / 28 ignored / 1106.2 pts || ocr | 4 suites / 141 active / 7 ignored / 130.8 pts | 4 suites / 134 active / 7 ignored / 128.6 pts | 3 suites / 125 active / 6 ignored / 119.6 pts || os-integration | 1 suites / 6 active / 0 ignored / 1.7 pts | 1 suites / 6 active / 0 ignored / 1.7 pts | - |-| performance | 13 suites / 1685 active / 82 ignored / 1487.8 pts | 14 suites / 1810 active / 90 ignored / 1537.8 pts | 13 suites / 1685 active / 82 ignored / 1487.8 pts |+| performance | 13 suites / 1686 active / 82 ignored / 1488.5 pts | 14 suites / 1811 active / 90 ignored / 1538.5 pts | 13 suites / 1686 active / 82 ignored / 1488.5 pts || pipes | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts || privacy | 5 suites / 1013 active / 42 ignored / 816.8 pts | 5 suites / 1069 active / 21 ignored / 818.5 pts | 5 suites / 971 active / 14 ignored / 781.7 pts || real-app | - | 1 suites / 125 active / 8 ignored / 50.0 pts | - || speaker | 2 suites / 416 active / 18 ignored / 416.0 pts | 2 suites / 416 active / 18 ignored / 416.0 pts | 2 suites / 416 active / 18 ignored / 416.0 pts |-| storage | 4 suites / 689 active / 41 ignored / 574.7 pts | 4 suites / 689 active / 41 ignored / 574.7 pts | 4 suites / 689 active / 41 ignored / 574.7 pts |+| storage | 4 suites / 690 active / 41 ignored / 575.4 pts | 4 suites / 690 active / 41 ignored / 575.4 pts | 4 suites / 690 active / 41 ignored / 575.4 pts || sync | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts | 1 suites / 551 active / 3 ignored / 385.7 pts |-| timeline | 4 suites / 1239 active / 48 ignored / 1017.6 pts | 4 suites / 1239 active / 48 ignored / 1017.6 pts | 4 suites / 1239 active / 48 ignored / 1017.6 pts |-| transcription | 7 suites / 892 active / 53 ignored / 698.0 pts | 6 suites / 886 active / 53 ignored / 693.8 pts | 6 suites / 886 active / 53 ignored / 693.8 pts |+| timeline | 4 suites / 1243 active / 48 ignored / 1020.4 pts | 4 suites / 1243 active / 48 ignored / 1020.4 pts | 4 suites / 1243 active / 48 ignored / 1020.4 pts |+| transcription | 7 suites / 895 active / 53 ignored / 700.1 pts | 6 suites / 889 active / 53 ignored / 695.9 pts | 6 suites / 889 active / 53 ignored / 695.9 pts || ui-events | 4 suites / 828 active / 34 ignored / 627.7 pts | 3 suites / 759 active / 5 ignored / 579.4 pts | 3 suites / 759 active / 5 ignored / 579.4 pts |-| vision-capture | 6 suites / 576 active / 32 ignored / 453.6 pts | 6 suites / 569 active / 32 ignored / 451.4 pts | 5 suites / 560 active / 31 ignored / 442.4 pts |+| vision-capture | 6 suites / 577 active / 32 ignored / 454.3 pts | 6 suites / 570 active / 32 ignored / 452.1 pts | 5 suites / 561 active / 31 ignored / 443.1 pts |## Critical Flow Matrix@@ -136,8 +136,8 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| db-runtime-reliability | screenpipe-db | windows, macos, linux | database, performance | performance-liveness | high | partial | mixed | 17 | 51 | 6 | SQLite hard-fault classification, failpoint VFS injection, fresh-identity recovery verification with integrity/FK/write canaries, query cancellation, close-severs-connections regressions, multi-pool WAL parity, runtime version pinning, and WAL chaos plus memory-pressure probes, plus read-only quarantine self-heal verification for transient IOERR faults. || db-search-indexing | screenpipe-db | windows, macos, linux | db-search, ocr, accessibility, performance | local-api-search, capture-ocr-pipeline, accessibility-ui-events, performance-liveness | high | strong | mixed | 14 | 107 | 4 | FTS, tokenizer, OCR snapshot search, query planning, ordering, accessibility search, and contention coverage. || db-timeline-frames | screenpipe-db | windows, macos, linux | database, timeline, storage, performance | timeline-streaming, performance-liveness | high | strong | mixed | 39 | 308 | 15 | Frame/audio joins, timeline query shape, suggestions frames, write queue, DB primitives (src/db.rs split into src/db/ modules), feedback record upserts, media eviction anti-join regressions, SAF output registry, semantic storage, and timeline performance. |-| engine-api-routes | screenpipe-engine | windows, macos, linux | local-api, timeline, meeting, transcription | local-api-search, timeline-streaming, meeting-live-notes, audio-record-transcribe | high | partial | mixed | 46 | 432 | 7 | Route/unit coverage for search, health, streaming, meetings, time/timezone, and transcription. Legacy endpoint/websocket tests require local data and remain ignored. |-| engine-capture-timeline | screenpipe-engine | windows, macos, linux | vision-capture, timeline, storage, performance | capture-ocr-pipeline, timeline-streaming, performance-liveness | high | partial | mixed | 25 | 306 | 26 | Covers capture trigger logic, frame/audio linking, hot cache, timeline refresh regressions, fragmented MP4 extraction, and HD-mode control. Several real-data tests are intentionally ignored by default. |+| engine-api-routes | screenpipe-engine | windows, macos, linux | local-api, timeline, meeting, transcription | local-api-search, timeline-streaming, meeting-live-notes, audio-record-transcribe | high | partial | mixed | 46 | 435 | 7 | Route/unit coverage for search, health, streaming, meetings, time/timezone, and transcription. Legacy endpoint/websocket tests require local data and remain ignored. |+| engine-capture-timeline | screenpipe-engine | windows, macos, linux | vision-capture, timeline, storage, performance | capture-ocr-pipeline, timeline-streaming, performance-liveness | high | partial | mixed | 25 | 307 | 26 | Covers capture trigger logic, frame/audio linking, hot cache, timeline refresh regressions, fragmented MP4 extraction, and HD-mode control. Several real-data tests are intentionally ignored by default. || engine-config-lifecycle | screenpipe-engine | windows, macos, linux | configuration, engine-lifecycle, performance | settings-to-engine-config, engine-health-lifecycle, performance-liveness | high | strong | mixed | 13 | 125 | 1 | Fast logic coverage for the config bridge, health-endpoint identity, tray health debounce, sleep/power policies, and queue backpressure. || engine-db-recovery-cli | screenpipe-engine | windows, macos, linux | database, engine-lifecycle | engine-health-lifecycle, performance-liveness | high | strong | unit | 1 | 33 | 0 | Exact DB/WAL/SHM working-copy preservation, rollback on archive failure, and restart repair for crashes during the multi-file generation swap. || engine-focus-os | screenpipe-engine | windows, macos | engine-lifecycle, os-integration | engine-health-lifecycle, performance-liveness | medium | conditional | unit | 3 | 6 | 0 | Platform focus-tracker parsing/helpers. These files are cfg-gated and only execute on their target OS. |@@ -408,7 +408,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| engine-meeting-privacy-sync | screenpipe-engine | src/drm_detector.rs | source | 19 | 2 | 21 || engine-capture-timeline | screenpipe-engine | src/event_driven_capture.rs | source | 98 | 0 | 98 || engine-meeting-privacy-sync | screenpipe-engine | src/external_memory_sync.rs | source | 13 | 0 | 13 |-| engine-capture-timeline | screenpipe-engine | src/focus_aware_controller.rs | source | 14 | 0 | 14 |+| engine-capture-timeline | screenpipe-engine | src/focus_aware_controller.rs | source | 15 | 0 | 15 || engine-focus-os | screenpipe-engine | src/focus_tracker/darwin.rs | source | 3 | 0 | 3 || engine-focus-os | screenpipe-engine | src/focus_tracker/windows.rs | source | 1 | 0 | 1 || engine-capture-timeline | screenpipe-engine | src/frame_linker_actor.rs | source | 2 | 0 | 2 |@@ -465,7 +465,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| engine-api-routes | screenpipe-engine | src/routes/data.rs | source | 2 | 0 | 2 || engine-api-routes | screenpipe-engine | src/routes/elements.rs | source | 25 | 1 | 26 || engine-api-routes | screenpipe-engine | src/routes/frames.rs | source | 12 | 1 | 13 |-| engine-api-routes | screenpipe-engine | src/routes/health.rs | source | 53 | 0 | 53 |+| engine-api-routes | screenpipe-engine | src/routes/health.rs | source | 56 | 0 | 56 || engine-api-routes | screenpipe-engine | src/routes/live_views.rs | source | 1 | 0 | 1 || engine-api-routes | screenpipe-engine | src/routes/meeting_summary_status.rs | source | 11 | 0 | 11 || engine-api-routes | screenpipe-engine | src/routes/meetings.rs | source | 7 | 0 | 7 |