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(sdk): preserve recording cadence on static Windows desktops
Louis Beaumont3c49b0f6f597
diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.ymlindex a49247f8a..224a958d2 100644--- a/.github/workflows/sdk.yml+++ b/.github/workflows/sdk.yml@@ -186,6 +186,9 @@ jobs:run: ls *.node- name: Run integration testsshell: bash+ env:+ # Keep Windows capture timing visible when the live FPS assertion regresses.+ SCREENPIPE_SDK_PERF: ${{ runner.os == 'Windows' && '1' || '0' }}run: |set -eo pipefailfiles=$(find __test__ -name '*.test.mjs' | sort)diff --git a/crates/screenpipe-screen/src/monitor/windows.rs b/crates/screenpipe-screen/src/monitor/windows.rsindex 40b4b1dd2..1103bec94 100644--- a/crates/screenpipe-screen/src/monitor/windows.rs+++ b/crates/screenpipe-screen/src/monitor/windows.rs@@ -101,7 +101,12 @@ impl SafeMonitor {.lock().map_err(|e| anyhow::anyhow!("persistent capture mutex poisoned: {}", e))?;if let Some(ref capture) = *guard {- match capture.get_latest_image(std::time::Duration::from_millis(200)) {+ let image = if streaming {+ capture.get_latest_image_streaming(std::time::Duration::from_millis(200))+ } else {+ capture.get_latest_image(std::time::Duration::from_millis(200))+ };+ match image {Ok(img) => {persistent_failures.store(0, Ordering::Relaxed);return Ok(img);@@ -130,7 +135,12 @@ impl SafeMonitor {match crate::wgc_capture::PersistentCapture::new(monitor_id) {Ok(mut capture) => {// First frame — allow longer timeout for WGC to deliver- match capture.get_latest_image(std::time::Duration::from_millis(500)) {+ let image = if streaming {+ capture.get_latest_image_streaming(std::time::Duration::from_millis(500))+ } else {+ capture.get_latest_image(std::time::Duration::from_millis(500))+ };+ match image {Ok(img) => {let mut guard = persistent.lock().map_err(|e| {anyhow::anyhow!("persistent capture mutex poisoned: {}", e)diff --git a/crates/screenpipe-screen/src/wgc_capture.rs b/crates/screenpipe-screen/src/wgc_capture.rsindex a14442563..074a41ef8 100644--- a/crates/screenpipe-screen/src/wgc_capture.rs+++ b/crates/screenpipe-screen/src/wgc_capture.rs@@ -139,6 +139,24 @@ impl CopyDemand {}}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+enum FrameReadPolicy {+ /// One-shot screenshots wait for compositor pixels newer than the request.+ Fresh,+ /// Sustained recording may reuse the last pixels while a refresh stays pending.+ CachedWhileRefreshing,+}++impl FrameReadPolicy {+ fn can_read(self, has_texture: bool, request_complete: bool) -> bool {+ has_texture+ && match self {+ Self::Fresh => request_complete,+ Self::CachedWhileRefreshing => true,+ }+ }+}+/// Shared D3D11 device state for all persistent captures. One device serves every/// monitor's session; it lives in `SHARED_D3D` so it can be dropped and recreated/// after device removal, unlike a `LazyLock` (which would also poison forever if the@@ -680,6 +698,21 @@ impl PersistentCapture {/// BGRA->RGBA swizzle happen here, lazily, only when a frame is actually needed —/// not on every compositor frame `FrameArrived` delivers.pub fn get_latest_image(&self, timeout: Duration) -> Result<DynamicImage> {+ self.get_image(timeout, FrameReadPolicy::Fresh)+ }++ /// Read at recording cadence while still requesting the next changed frame.+ ///+ /// WGC only emits compositor frames when the desktop changes. A sustained video+ /// stream must nevertheless keep its timeline moving, so after the first frame we+ /// may reuse the cached texture immediately. The request generation remains+ /// pending, allowing the next compositor update to replace that texture without+ /// continuously copying unchanged GPU frames.+ pub fn get_latest_image_streaming(&self, timeout: Duration) -> Result<DynamicImage> {+ self.get_image(timeout, FrameReadPolicy::CachedWhileRefreshing)+ }++ fn get_image(&self, timeout: Duration, policy: FrameReadPolicy) -> Result<DynamicImage> {let deadline = Instant::now() + timeout;let (frame_lock, frame_ready) = &*self.latest;let mut slot = frame_lock@@ -702,7 +735,10 @@ impl PersistentCapture {"WGC session closed (capture item closed or stopped)"));}- if slot.demand.is_complete(request_generation) && slot.texture.is_some() {+ if policy.can_read(+ slot.texture.is_some(),+ slot.demand.is_complete(request_generation),+ ) {break;}let now = Instant::now();@@ -907,6 +943,20 @@ mod tests {assert!(!deliver_frame(&mut demand));}+ #[test]+ fn streaming_reuses_cached_texture_while_refresh_remains_pending() {+ let mut demand = CopyDemand::default();+ let first = demand.request();+ assert!(deliver_frame(&mut demand));+ assert!(demand.is_complete(first));++ let refresh = demand.request();+ assert!(!demand.is_complete(refresh));+ assert!(FrameReadPolicy::CachedWhileRefreshing.can_read(true, false));+ assert!(!FrameReadPolicy::Fresh.can_read(true, false));+ assert!(demand.pending_generation().is_some());+ }+#[test]fn abandoned_request_leaves_at_most_one_copy() {let mut demand = CopyDemand::default();