Skip to content

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

fix(windows): dedicated thread for tree walker COM init + filter invalid datetime timestamps

Louis Beaumont4078d5bb80a2
diff --git a/Cargo.lock b/Cargo.lock
index 081ce853f..a4eead9c2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5520,7 +5520,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"anyhow",
"bytemuck",
@@ -5576,7 +5576,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -5617,7 +5617,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"anyhow",
"chrono",
@@ -5642,7 +5642,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"anyhow",
"chrono",
@@ -5660,7 +5660,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"anyhow",
"chrono",
@@ -5681,7 +5681,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"anyhow",
"async-trait",
@@ -5742,7 +5742,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.146"
+version = "0.3.149"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index 757ec505a..41714dc28 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -2039,12 +2039,12 @@ impl DatabaseManager {
sqlx::Error,
> {
let latest_frame: Option<(DateTime<Utc>,)> =
- sqlx::query_as("SELECT timestamp FROM frames ORDER BY timestamp DESC LIMIT 1")
+ sqlx::query_as("SELECT timestamp FROM frames WHERE timestamp IS NOT NULL AND timestamp != '' ORDER BY timestamp DESC LIMIT 1")
.fetch_optional(&self.pool)
.await?;
let latest_audio: Option<(DateTime<Utc>,)> =
- sqlx::query_as("SELECT timestamp FROM audio_chunks ORDER BY timestamp DESC LIMIT 1")
+ sqlx::query_as("SELECT timestamp FROM audio_chunks WHERE timestamp IS NOT NULL AND timestamp != '' ORDER BY timestamp DESC LIMIT 1")
.fetch_optional(&self.pool)
.await?;
@@ -2057,7 +2057,7 @@ impl DatabaseManager {
{
Some(_) => {
sqlx::query_as(
- "SELECT timestamp FROM ui_monitoring ORDER BY timestamp DESC LIMIT 1",
+ "SELECT timestamp FROM ui_monitoring WHERE timestamp IS NOT NULL AND timestamp != '' ORDER BY timestamp DESC LIMIT 1",
)
.fetch_optional(&self.pool)
.await?
diff --git a/crates/screenpipe-server/src/ui_recorder.rs b/crates/screenpipe-server/src/ui_recorder.rs
index 86fc0d883..b2abde7c5 100644
--- a/crates/screenpipe-server/src/ui_recorder.rs
+++ b/crates/screenpipe-server/src/ui_recorder.rs
@@ -325,11 +325,30 @@ pub async fn start_ui_recording(
let ignored_windows_clone = config.ignored_windows.clone();
let included_windows_clone = config.included_windows.clone();
- // Run the entire tree walker loop in a blocking thread since AX APIs are synchronous IPC
+ // Run the entire tree walker loop in a dedicated thread since AX APIs are synchronous IPC.
+ // On Windows we use std::thread instead of spawn_blocking because COM (UIA) requires
+ // controlled initialization from thread birth — tokio's blocking pool may already have
+ // COM initialized with incompatible threading model, causing E_FAIL (0x80004005).
let tree_wake = wake_signal.clone();
- Some(tokio::task::spawn_blocking(move || {
- run_tree_walker(tree_db, tree_stop, walk_interval, rt_handle, tree_wake, ignored_windows_clone, included_windows_clone);
- }))
+ #[cfg(target_os = "windows")]
+ {
+ let join_handle = std::thread::Builder::new()
+ .name("tree-walker".to_string())
+ .spawn(move || {
+ run_tree_walker(tree_db, tree_stop, walk_interval, rt_handle, tree_wake, ignored_windows_clone, included_windows_clone);
+ })
+ .expect("failed to spawn tree-walker thread");
+ // Wrap in a JoinHandle<()> compatible with the tokio handle used on other platforms
+ Some(tokio::task::spawn_blocking(move || {
+ let _ = join_handle.join();
+ }))
+ }
+ #[cfg(not(target_os = "windows"))]
+ {
+ Some(tokio::task::spawn_blocking(move || {
+ run_tree_walker(tree_db, tree_stop, walk_interval, rt_handle, tree_wake, ignored_windows_clone, included_windows_clone);
+ }))
+ }
} else {
info!("AX tree walker is disabled");
None