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 streaming capture over RDP
Louis Beaumont42042665b1a7
diff --git a/crates/screenpipe-screen/src/monitor.rs b/crates/screenpipe-screen/src/monitor.rsindex 309106755..47dbf355a 100644--- a/crates/screenpipe-screen/src/monitor.rs+++ b/crates/screenpipe-screen/src/monitor.rs@@ -176,6 +176,16 @@ impl SafeMonitor {pub fn get_info(&self) -> MonitorData {(*self.monitor_data).clone()}++ /// Capture a frame for a sustained recording loop.+ ///+ /// Most platforms use the same capture path as [`Self::capture_image`]. Windows+ /// overrides this method so an explicitly long-lived recorder can keep its WGC+ /// session between frames, including inside Remote Desktop sessions.+ #[cfg(any(target_os = "linux", target_os = "macos"))]+ pub async fn capture_image_streaming(&self) -> anyhow::Result<image::DynamicImage> {+ self.capture_image().await+ }}/// Update the cached monitor descriptions from a successful monitor list.diff --git a/crates/screenpipe-screen/src/monitor/windows.rs b/crates/screenpipe-screen/src/monitor/windows.rsindex afe68f41f..40b4b1dd2 100644--- a/crates/screenpipe-screen/src/monitor/windows.rs+++ b/crates/screenpipe-screen/src/monitor/windows.rs@@ -39,12 +39,25 @@ impl SafeMonitor {// Windows: Use persistent WGC capture to avoid orange border flash.// Falls back to per-frame xcap capture if persistent session fails.pub async fn capture_image(&self) -> Result<DynamicImage> {+ self.capture_image_inner(false).await+ }++ /// Capture a frame as part of a sustained recording loop.+ ///+ /// Unlike one-shot [`Self::capture_image`] calls, an explicit streaming caller+ /// keeps the WGC session alive between frames even under RDP. The session remains+ /// scoped to this `SafeMonitor` and is closed when the recorder drops it.+ pub async fn capture_image_streaming(&self) -> Result<DynamicImage> {+ self.capture_image_inner(true).await+ }++ async fn capture_image_inner(&self, streaming: bool) -> Result<DynamicImage> {let monitor_id = self.monitor_id;let persistent = self.persistent_capture.clone();let persistent_disabled = self.persistent_capture_disabled.clone();let persistent_failures = self.persistent_capture_failures.clone();let result = tokio::task::spawn_blocking(move || -> Result<DynamicImage> {- if Self::is_remote_session() {+ if Self::should_use_request_scoped_capture(Self::is_remote_session(), streaming) {RDP_CAPTURE_LOG_ONCE.call_once(|| {tracing::info!("RDP session detected; using request-scoped WGC capture"@@ -168,6 +181,10 @@ impl SafeMonitor {Ok(result)}+ fn should_use_request_scoped_capture(is_remote_session: bool, streaming: bool) -> bool {+ is_remote_session && !streaming+ }+/// True when this process is running in a Remote Desktop / Terminal Services/// client session. A live WGC session makes the RDP compositor continuously/// produce capture frames, so RDP uses one session per screenshot request.@@ -408,6 +425,16 @@ mod tests {assert!(persistent.lock().unwrap().is_none());}+ #[test]+ fn rdp_capture_policy_keeps_only_explicit_streams_persistent() {+ assert!(SafeMonitor::should_use_request_scoped_capture(true, false));+ assert!(!SafeMonitor::should_use_request_scoped_capture(true, true));+ assert!(!SafeMonitor::should_use_request_scoped_capture(+ false, false+ ));+ assert!(!SafeMonitor::should_use_request_scoped_capture(false, true));+ }+#[tokio::test]#[ignore = "requires a live Remote Desktop session"]async fn rdp_capture_closes_wgc_session_after_each_request() {diff --git a/ee/sdk/recorder-core/src/platform/recorder.rs b/ee/sdk/recorder-core/src/platform/recorder.rsindex 893beacc6..8d0b49de2 100644--- a/ee/sdk/recorder-core/src/platform/recorder.rs+++ b/ee/sdk/recorder-core/src/platform/recorder.rs@@ -630,12 +630,13 @@ async fn capture_loop(}let t_cap = std::time::Instant::now();- // capture_image uses screenpipe-screen's persistent SCK stream- // internally (stream_manager), already ar_pool-wrapped.- let frame = match monitor.capture_image().await {+ // MP4 recording is a sustained stream, so explicitly retain the native+ // capture session between frames. In particular, Windows RDP one-shot+ // screenshots stay request-scoped while this recorder keeps WGC alive.+ let frame = match monitor.capture_image_streaming().await {Ok(img) => img,Err(e) => {- warn!("screenpipe-sdk: capture_image: {e}");+ warn!("screenpipe-sdk: capture_image_streaming: {e}");continue;}};