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(capture): don't strip the AX walk when the focus event stream goes quiet (#6187)
Louis Beaumontaddf87824fdd
diff --git a/crates/screenpipe-engine/src/focus_aware_controller.rs b/crates/screenpipe-engine/src/focus_aware_controller.rsindex 390f940dd..21fe1b059 100644--- a/crates/screenpipe-engine/src/focus_aware_controller.rs+++ b/crates/screenpipe-engine/src/focus_aware_controller.rs@@ -223,13 +223,32 @@ impl FocusAwareController {.lock().ok().is_some_and(|time| time.elapsed() < STALE_FOCUS_CUTOFF);- focus_is_fresh- && self+ if focus_is_fresh {+ return self.current_focus.lock().ok().and_then(|focus| focus.clone())- .is_some_and(|focus| focus.matches(identity))+ .is_some_and(|focus| focus.matches(identity));+ }++ // Events only flow when focus *changes*, so on a single-monitor setup+ // (or any stretch where the cursor stays on one display) the stream+ // goes quiet and `last_event_time` blows past the cutoff even though+ // nothing is wrong. Treating quiet as "not focused" silently stripped+ // the AX walk from every capture — frames kept flowing but with OCR+ // text and empty app/window attribution. Pull the tracker's latest+ // resolution instead: its own safety-net poll keeps `current()` fresh+ // independent of event emission, so this is still a *confirmed*+ // focus read, not a guess.+ //+ // When the tracker cannot resolve at all (Null tracker, cursor in a+ // display gap, platform tracker wedged) this stays fail-closed —+ // "unknown monitor → OCR + unknown identity" is the deliberate+ // capture-source boundary from #6018.+ self.tracker+ .current()+ .is_some_and(|current| current.matches(identity))}#[cfg(test)]@@ -402,6 +421,34 @@ mod tests {FocusAwareController::new(tracker)}+ /// Tracker whose `current()` answer is pinned by the test. Stands in for a+ /// healthy platform tracker whose event stream has gone quiet because+ /// focus stopped *changing* — the normal single-monitor condition.+ struct StaticFocusTracker {+ current: std::sync::Mutex<Option<MonitorIdentity>>,+ tx: tokio::sync::broadcast::Sender<crate::focus_tracker::FocusEvent>,+ }++ impl StaticFocusTracker {+ fn resolving(identity: MonitorIdentity) -> Self {+ let (tx, _) = tokio::sync::broadcast::channel(16);+ Self {+ current: std::sync::Mutex::new(Some(identity)),+ tx,+ }+ }+ }++ impl FocusTracker for StaticFocusTracker {+ fn current(&self) -> Option<MonitorIdentity> {+ self.current.lock().expect("static tracker mutex").clone()+ }+ fn subscribe(&self) -> tokio::sync::broadcast::Receiver<crate::focus_tracker::FocusEvent> {+ self.tx.subscribe()+ }+ fn stop(&self) {}+ }+#[tokio::test]async fn initial_state_is_active_for_all_monitors() {let ctrl = make_ctrl();@@ -492,6 +539,11 @@ mod tests {// Both monitors should now report Active (safe fallback).assert_eq!(ctrl.state(1), CaptureState::Active);assert_eq!(ctrl.state(2), CaptureState::Active);+ // hosts_focus stays closed: the Null tracker cannot resolve a monitor,+ // and unresolved focus means OCR + unknown identity (the #6018+ // capture-source boundary). Contrast with+ // hosts_focus_survives_quiet_event_stream_via_tracker_pull, where a+ // healthy tracker still resolves the monitor and keeps its AX walk.assert!(!ctrl.hosts_focus(1));assert!(!ctrl.hosts_focus(2));// A fresh focus event should clear the stale latch and restore@@ -501,6 +553,49 @@ mod tests {assert_eq!(ctrl.state(2), CaptureState::Cold);}+ /// The incident this gate caused: one monitor, cursor parked on it, so+ /// focus never *changes* and the tracker (correctly) emits nothing. After+ /// 30 quiet seconds `last_event_time` is stale — but the tracker itself+ /// still resolves the cursor's monitor every poll. hosts_focus must pull+ /// that resolution instead of failing closed, or every capture loses its+ /// tree walk: OCR text, empty app_name, empty window_name, forever.+ #[tokio::test]+ async fn hosts_focus_survives_quiet_event_stream_via_tracker_pull() {+ let identity = MonitorIdentity::new(3, Some("Display_1920x1080_0,0".to_string()));+ let tracker: Arc<dyn FocusTracker> =+ Arc::new(StaticFocusTracker::resolving(identity.clone()));+ let ctrl = FocusAwareController::new(tracker);++ ctrl.set_focus_identity_for_test(identity.clone());+ assert!(ctrl.hosts_focus_for_identity(&identity));++ // 60 quiet seconds — no focus change, so no events. Not a fault.+ ctrl.backdate_last_event_for_test(Instant::now() - Duration::from_secs(60));++ assert!(+ ctrl.hosts_focus_for_identity(&identity),+ "a quiet event stream must not strip focus from the monitor the tracker still resolves"+ );+ }++ /// Isolation survives the stale fallback: when the tracker resolves the+ /// cursor onto monitor A, a stale-event query for monitor B stays false.+ /// The fail-open tier only applies when nothing can resolve focus at all.+ #[tokio::test]+ async fn stale_fallback_still_isolates_the_unfocused_monitor() {+ let focused = MonitorIdentity::new(1, Some("Dell_3840x2160_0,0".to_string()));+ let other = MonitorIdentity::new(2, Some("LG_1920x1080_3840,0".to_string()));+ let tracker: Arc<dyn FocusTracker> =+ Arc::new(StaticFocusTracker::resolving(focused.clone()));+ let ctrl = FocusAwareController::new(tracker);++ ctrl.set_focus_identity_for_test(focused.clone());+ ctrl.backdate_last_event_for_test(Instant::now() - Duration::from_secs(60));++ assert!(ctrl.hosts_focus_for_identity(&focused));+ assert!(!ctrl.hosts_focus_for_identity(&other));+ }+#[tokio::test]async fn stable_identity_matches_when_runtime_ids_differ() {let ctrl = make_ctrl();diff --git a/docs/coverage/CORE.md b/docs/coverage/CORE.mdindex f50654dbb..1c7c32980 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- Mapped suites: 32- Mapped Rust files: 321-- Active test blocks: 3061+- Active test blocks: 3062- Ignored/manual test blocks: 137-- Declared test blocks: 3198-- Weighted coverage points: 2519.0+- Declared test blocks: 3199+- Weighted coverage points: 2519.7Confidence 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 | 29 | 2930 | 132 | 2459.0 | 21 | 11 | 100% |-| macos | 29 | 2983 | 112 | 2469.4 | 22 | 11 | 100% |-| linux | 25 | 2616 | 105 | 2175.8 | 20 | 11 | 100% |+| windows | 29 | 2931 | 132 | 2459.7 | 21 | 11 | 100% |+| macos | 29 | 2985 | 112 | 2470.8 | 22 | 11 | 100% |+| linux | 25 | 2618 | 105 | 2177.2 | 20 | 11 | 100% |## Crate Summary| Crate | Suites | Integration files | Source unit files | Active tests | Ignored tests | Weighted points | Flows || --- | --- | --- | --- | --- | --- | --- | --- |-| screenpipe-engine | 10 | 18 | 102 | 1439 | 42 | 1103.2 | 10 |+| screenpipe-engine | 10 | 18 | 102 | 1441 | 42 | 1104.6 | 10 || screenpipe-db | 5 | 52 | 14 | 447 | 16 | 424.2 | 9 || screenpipe-sqlite-coordinator | 1 | 0 | 2 | 16 | 0 | 16.0 | 2 || screenpipe-audio | 6 | 25 | 51 | 584 | 43 | 510.4 | 5 |@@ -72,17 +72,17 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| meeting | 6 suites / 1401 active / 19 ignored / 1144.2 pts | 6 suites / 1401 active / 19 ignored / 1144.2 pts | 4 suites / 1123 active / 15 ignored / 888.7 pts || ocr | 4 suites / 124 active / 7 ignored / 118.3 pts | 4 suites / 128 active / 7 ignored / 123.8 pts | 3 suites / 119 active / 6 ignored / 114.8 pts || os-integration | 1 suites / 6 active / 0 ignored / 1.7 pts | 1 suites / 6 active / 0 ignored / 1.7 pts | - |-| performance | 13 suites / 1369 active / 67 ignored / 1208.1 pts | 14 suites / 1467 active / 70 ignored / 1247.3 pts | 13 suites / 1369 active / 67 ignored / 1208.1 pts |+| performance | 13 suites / 1371 active / 67 ignored / 1209.5 pts | 14 suites / 1469 active / 70 ignored / 1248.7 pts | 13 suites / 1371 active / 67 ignored / 1209.5 pts || pipes | 1 suites / 462 active / 3 ignored / 323.4 pts | 1 suites / 462 active / 3 ignored / 323.4 pts | 1 suites / 462 active / 3 ignored / 323.4 pts || privacy | 5 suites / 871 active / 36 ignored / 707.5 pts | 5 suites / 920 active / 16 ignored / 712.4 pts | 5 suites / 846 active / 14 ignored / 685.0 pts || real-app | - | 1 suites / 98 active / 3 ignored / 39.2 pts | - || speaker | 2 suites / 342 active / 8 ignored / 342.0 pts | 2 suites / 342 active / 8 ignored / 342.0 pts | 2 suites / 342 active / 8 ignored / 342.0 pts |-| storage | 3 suites / 470 active / 29 ignored / 381.5 pts | 3 suites / 470 active / 29 ignored / 381.5 pts | 3 suites / 470 active / 29 ignored / 381.5 pts |+| storage | 3 suites / 472 active / 29 ignored / 382.9 pts | 3 suites / 472 active / 29 ignored / 382.9 pts | 3 suites / 472 active / 29 ignored / 382.9 pts || sync | 1 suites / 462 active / 3 ignored / 323.4 pts | 1 suites / 462 active / 3 ignored / 323.4 pts | 1 suites / 462 active / 3 ignored / 323.4 pts |-| timeline | 4 suites / 928 active / 33 ignored / 755.2 pts | 4 suites / 928 active / 33 ignored / 755.2 pts | 4 suites / 928 active / 33 ignored / 755.2 pts |+| timeline | 4 suites / 930 active / 33 ignored / 756.6 pts | 4 suites / 930 active / 33 ignored / 756.6 pts | 4 suites / 930 active / 33 ignored / 756.6 pts || transcription | 5 suites / 692 active / 40 ignored / 545.2 pts | 5 suites / 692 active / 40 ignored / 545.2 pts | 5 suites / 692 active / 40 ignored / 545.2 pts |-| ui-events | 4 suites / 701 active / 28 ignored / 533.9 pts | 3 suites / 652 active / 5 ignored / 499.6 pts | 3 suites / 652 active / 5 ignored / 499.6 pts |-| vision-capture | 5 suites / 489 active / 32 ignored / 387.8 pts | 5 suites / 493 active / 32 ignored / 393.3 pts | 4 suites / 484 active / 31 ignored / 384.3 pts |+| ui-events | 4 suites / 700 active / 28 ignored / 533.2 pts | 3 suites / 652 active / 5 ignored / 499.6 pts | 3 suites / 652 active / 5 ignored / 499.6 pts |+| vision-capture | 5 suites / 491 active / 32 ignored / 389.2 pts | 5 suites / 495 active / 32 ignored / 394.7 pts | 4 suites / 486 active / 31 ignored / 385.7 pts |## Critical Flow Matrix@@ -134,7 +134,7 @@ bun run coverage:core -- --llvm-cov-summary ../../docs/coverage/core-llvm-cov-su| 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 | 13 | 105 | 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 | 18 | 175 | 3 | 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 | 31 | 319 | 4 | 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 | 23 | 257 | 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-capture-timeline | screenpipe-engine | windows, macos, linux | vision-capture, timeline, storage, performance | capture-ocr-pipeline, timeline-streaming, performance-liveness | high | partial | mixed | 23 | 259 | 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 | 11 | 111 | 1 | Fast logic coverage for the config bridge, 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 | 8 | 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. |@@ -355,7 +355,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 | 80 | 0 | 80 || engine-meeting-privacy-sync | screenpipe-engine | src/external_memory_sync.rs | source | 10 | 0 | 10 |-| engine-capture-timeline | screenpipe-engine | src/focus_aware_controller.rs | source | 12 | 0 | 12 |+| engine-capture-timeline | screenpipe-engine | src/focus_aware_controller.rs | source | 14 | 0 | 14 || 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 |