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: resolve DB pool exhaustion causing vision/audio write stalls

Louis Beaumont1ee5fe1409b4
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 9f1d8ed9a..4473978cb 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -402,6 +402,14 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "antirez-asr-sys"
+version = "0.1.0"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=b199cf5b3d1e0e87604f02910240a2bc8851cf9a#b199cf5b3d1e0e87604f02910240a2bc8851cf9a"
+dependencies = [
+ "cc",
+]
+
[[package]]
name = "anyhow"
version = "1.0.102"
@@ -444,7 +452,7 @@ dependencies = [
"clipboard-win",
"image 0.25.9",
"log",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-core-graphics",
@@ -836,8 +844,9 @@ dependencies = [
[[package]]
name = "audiopipe"
version = "0.2.0"
-source = "git+https://github.com/screenpipe/audiopipe.git?rev=4ceceb0#4ceceb04ed8c0939cfca904bd8b649e8537bc316"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=b199cf5b3d1e0e87604f02910240a2bc8851cf9a#b199cf5b3d1e0e87604f02910240a2bc8851cf9a"
dependencies = [
+ "antirez-asr-sys",
"hf-hub 0.4.3",
"qwen3-asr-sys",
"serde",
@@ -1300,7 +1309,7 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
]
[[package]]
@@ -2818,14 +2827,14 @@ checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
[[package]]
name = "dispatch2"
-version = "0.3.0"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
+checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
"libc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
]
[[package]]
@@ -3285,7 +3294,7 @@ dependencies = [
"block2 0.6.2",
"chrono",
"clap",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-event-kit",
"objc2-foundation 0.3.2",
"thiserror 2.0.18",
@@ -4189,7 +4198,7 @@ checksum = "b9247516746aa8e53411a0db9b62b0e24efbcf6a76e0ba73e5a91b512ddabed7"
dependencies = [
"crossbeam-channel",
"keyboard-types",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"once_cell",
"serde",
@@ -5867,7 +5876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65fd3f75411f4725061682ed91f131946e912859d0044d39c4ec0aac818d7621"
dependencies = [
"cc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
"time",
]
@@ -6197,7 +6206,7 @@ dependencies = [
"dpi",
"gtk",
"keyboard-types",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
@@ -6724,9 +6733,9 @@ dependencies = [
[[package]]
name = "objc2"
-version = "0.6.3"
+version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05"
+checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
dependencies = [
"objc2-encode",
"objc2-exception-helper",
@@ -6741,7 +6750,7 @@ dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
"libc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-cloud-kit",
"objc2-core-data",
"objc2-core-foundation",
@@ -6762,7 +6771,7 @@ dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
"dispatch2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-avf-audio",
"objc2-core-audio-types",
"objc2-core-foundation",
@@ -6781,7 +6790,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -6792,7 +6801,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -6803,7 +6812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2"
dependencies = [
"dispatch2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-audio-types",
"objc2-core-foundation",
]
@@ -6815,7 +6824,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
]
[[package]]
@@ -6825,7 +6834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -6839,7 +6848,7 @@ dependencies = [
"block2 0.6.2",
"dispatch2",
"libc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
]
[[package]]
@@ -6852,7 +6861,7 @@ dependencies = [
"block2 0.6.2",
"dispatch2",
"libc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-io-surface",
"objc2-metal",
@@ -6864,7 +6873,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -6874,7 +6883,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca347214e24bc973fc025fd0d36ebb179ff30536ed1f80252706db19ee452009"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -6887,7 +6896,7 @@ dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
"dispatch2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-audio",
"objc2-core-audio-types",
"objc2-core-foundation",
@@ -6901,7 +6910,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-core-graphics",
]
@@ -6914,7 +6923,7 @@ checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6"
dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-io-surface",
@@ -6935,7 +6944,7 @@ checksum = "51bc9ad7325642172110196bacd6af64027ec5549ded7fc6589ea03e0f792bf8"
dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-graphics",
"objc2-core-location",
@@ -6973,7 +6982,7 @@ dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
"libc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
]
@@ -6983,7 +6992,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b0446e98cf4a784cc7a0177715ff317eeaa8463841c616cfc78aa4f953c4ea"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-core-graphics",
]
@@ -6995,7 +7004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
]
@@ -7005,7 +7014,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a1e6550c4caed348956ce3370c9ffeca70bb1dbed4fa96112e7c6170e074586"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
]
@@ -7015,7 +7024,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579edede1c244621cd8229b70ea6e20e6ec3bab5a74afdfd494b446b681e1e64"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -7025,7 +7034,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edd9fdde720df3da7046bb9097811000c1e7ab5cd579fa89d96b27d56781fb30"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-audio-types",
"objc2-core-foundation",
"objc2-core-media",
@@ -7038,7 +7047,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -7049,7 +7058,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f112d1746737b0da274ef79a23aac283376f335f4095a083a267a082f21db0c0"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-foundation 0.3.2",
]
@@ -7061,7 +7070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
]
@@ -7073,7 +7082,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "709fe137109bd1e8b5a99390f77a7d8b2961dafc1a1c5db8f2e60329ad6d895a"
dependencies = [
"bitflags 2.11.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
]
@@ -7085,7 +7094,7 @@ checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22"
dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-cloud-kit",
"objc2-core-data",
"objc2-core-foundation",
@@ -7104,7 +7113,7 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9df9128cbbfef73cda168416ccf7f837b62737d748333bfe9ab71c245d76613e"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
]
@@ -7116,7 +7125,7 @@ checksum = "b2e5aaab980c433cf470df9d7af96a7b46a9d892d521a2cbbb2f8a4c16751e7f"
dependencies = [
"bitflags 2.11.0",
"block2 0.6.2",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
@@ -7328,7 +7337,7 @@ dependencies = [
"android_system_properties",
"log",
"nix 0.30.1",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
"objc2-ui-kit",
"serde",
@@ -7351,7 +7360,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "732c71caeaa72c065bb69d7ea08717bd3f4863a4f451402fc9513e29dbd5261b"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-foundation 0.3.2",
"objc2-osa-kit",
"serde",
@@ -8294,7 +8303,7 @@ checksum = "640c9bd8497b02465aeef5375144c26062e0dcd5939dfcbb0f5db76cb8c17c73"
[[package]]
name = "qwen3-asr-sys"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/audiopipe.git?rev=4ceceb0#4ceceb04ed8c0939cfca904bd8b649e8537bc316"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=b199cf5b3d1e0e87604f02910240a2bc8851cf9a#b199cf5b3d1e0e87604f02910240a2bc8851cf9a"
dependencies = [
"cc",
"cmake",
@@ -8767,7 +8776,7 @@ dependencies = [
"gtk-sys",
"js-sys",
"log",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
@@ -9329,7 +9338,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.2.166"
+version = "2.2.170"
dependencies = [
"anyhow",
"arboard",
@@ -9360,7 +9369,7 @@ dependencies = [
"nokhwa-bindings-macos",
"notify",
"objc",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"once_cell",
"raw-window-handle",
"regex",
@@ -9431,7 +9440,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"anyhow",
"audiopipe",
@@ -9485,7 +9494,7 @@ dependencies = [
[[package]]
name = "screenpipe-config"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"dirs 6.0.0",
"serde",
@@ -9497,7 +9506,7 @@ dependencies = [
[[package]]
name = "screenpipe-connect"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"anyhow",
"async-trait",
@@ -9507,7 +9516,7 @@ dependencies = [
"image 0.25.9",
"lettre",
"log",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-event-kit",
"objc2-foundation 0.3.2",
"reqwest 0.12.12",
@@ -9523,7 +9532,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -9565,7 +9574,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"anyhow",
"chrono",
@@ -9590,7 +9599,7 @@ dependencies = [
[[package]]
name = "screenpipe-engine"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"anyhow",
"async-trait",
@@ -9653,7 +9662,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"anyhow",
"chrono",
@@ -9669,7 +9678,7 @@ dependencies = [
[[package]]
name = "screenpipe-screen"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"accessibility-sys",
"anyhow",
@@ -9705,7 +9714,7 @@ dependencies = [
[[package]]
name = "screenpipe-vault"
-version = "0.3.185"
+version = "0.3.186"
dependencies = [
"argon2",
"chacha20poly1305",
@@ -10533,7 +10542,7 @@ dependencies = [
"bytemuck",
"js-sys",
"ndk 0.9.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation 0.3.2",
@@ -11364,7 +11373,7 @@ dependencies = [
"ndk 0.9.0",
"ndk-context",
"ndk-sys 0.6.0+11769913",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-foundation 0.3.2",
"once_cell",
@@ -11444,7 +11453,7 @@ dependencies = [
"log",
"mime",
"muda",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-foundation 0.3.2",
"objc2-ui-kit",
@@ -11884,7 +11893,7 @@ dependencies = [
"glib 0.21.5",
"gtk",
"javascriptcore-rs",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-foundation 0.3.2",
"objc2-web-kit",
@@ -11914,7 +11923,7 @@ dependencies = [
"gtk",
"http 1.4.0",
"jni",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-ui-kit",
"objc2-web-kit",
"raw-window-handle",
@@ -11938,7 +11947,7 @@ dependencies = [
"http 1.4.0",
"jni",
"log",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-foundation 0.3.2",
"once_cell",
@@ -12677,7 +12686,7 @@ dependencies = [
"dirs 6.0.0",
"libappindicator",
"muda",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-core-graphics",
@@ -13694,7 +13703,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9bec5a31f3f9362f2258fd0e9c9dd61a9ca432e7306cc78c444258f0dce9a9c"
dependencies = [
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
@@ -14548,7 +14557,7 @@ dependencies = [
"kuchikiki",
"libc",
"ndk 0.9.0",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation 0.3.2",
@@ -14630,16 +14639,16 @@ dependencies = [
[[package]]
name = "xcap"
-version = "0.8.2"
+version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b65b5b36b7abe56a64f6dd46e55e26ca1ed5937a84f57fc86e8f2dd37b136f1"
+checksum = "4e68ffe10c83f18354f0bcf6d9038d5e133c7d91af57baca50d1b90bea83257c"
dependencies = [
"dispatch2",
"image 0.25.9",
"lazy_static",
"libwayshot-xcap",
"log",
- "objc2 0.6.3",
+ "objc2 0.6.4",
"objc2-app-kit",
"objc2-av-foundation",
"objc2-core-foundation",
@@ -14655,7 +14664,7 @@ dependencies = [
"thiserror 2.0.18",
"url",
"widestring",
- "windows 0.61.3",
+ "windows 0.62.2",
"xcb",
"zbus",
]
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index 972dabc1b..f95aa063a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.2.170"
+version = "2.2.171"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
index c1a880713..d69d129cf 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/embedded_server.rs
@@ -429,7 +429,7 @@ pub async fn start_embedded_server(
// Create pipe store backed by the main SQLite DB
let pipe_store: Option<std::sync::Arc<dyn screenpipe_core::pipes::PipeStore>> =
Some(std::sync::Arc::new(
- screenpipe_engine::pipe_store::SqlitePipeStore::new(db.pool.clone()),
+ screenpipe_engine::pipe_store::SqlitePipeStore::new(db.clone()),
));
let mut pipe_manager = screenpipe_core::pipes::PipeManager::new(
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index e5a0c0261..2e5993944 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -409,13 +409,31 @@ impl DatabaseManager {
})
}
Err(e) if Self::is_nested_transaction_error(&e) => {
- // Connection has a stuck transaction — detach it from the pool
- // so it doesn't poison subsequent acquire() calls.
+ // Connection has a stuck transaction — ROLLBACK it and retry.
+ // Previous approach: detach the connection. Problem: detach
+ // permanently removes the slot from the pool. After ~3 detaches
+ // the write pool (max_connections=3) is dead and ALL writes fail
+ // with PoolTimedOut forever until restart.
+ // New approach: ROLLBACK cleans the connection so it returns to
+ // the pool healthy. Only detach as last resort if ROLLBACK fails.
warn!(
- "BEGIN IMMEDIATE hit stuck transaction (attempt {}/{}), detaching connection",
+ "BEGIN IMMEDIATE hit stuck transaction (attempt {}/{}), rolling back",
attempt, max_retries
);
- let _raw = conn.detach();
+ match sqlx::query("ROLLBACK").execute(&mut *conn).await {
+ Ok(_) => {
+ debug!("stuck transaction rolled back, connection recovered");
+ // Connection is clean — drop returns it to pool
+ drop(conn);
+ }
+ Err(rb_err) => {
+ warn!(
+ "ROLLBACK failed ({}), detaching connection as last resort",
+ rb_err
+ );
+ let _raw = conn.detach();
+ }
+ }
last_error = Some(e);
tokio::time::sleep(Duration::from_millis(50)).await;
continue;
@@ -498,6 +516,65 @@ impl DatabaseManager {
Ok(())
}
+ /// Clear snapshot_path for frames with missing JPEG files, via write queue.
+ pub async fn clear_snapshot_paths_queued(&self, frame_ids: Vec<i64>) -> Result<(), sqlx::Error> {
+ use crate::write_queue::WriteOp;
+ self.write_queue.submit(WriteOp::ClearSnapshotPaths { frame_ids }).await?;
+ Ok(())
+ }
+
+ /// Create a pipe execution via the write queue. Returns the new row ID.
+ pub async fn pipe_create_execution_queued(
+ &self,
+ pipe_name: &str,
+ trigger_type: &str,
+ model: &str,
+ provider: Option<&str>,
+ ) -> Result<i64, sqlx::Error> {
+ use crate::write_queue::{WriteOp, WriteResult};
+ let result = self
+ .write_queue
+ .submit(WriteOp::PipeCreateExecution {
+ pipe_name: pipe_name.to_string(),
+ trigger_type: trigger_type.to_string(),
+ model: model.to_string(),
+ provider: provider.map(|s| s.to_string()),
+ started_at: chrono::Utc::now().to_rfc3339(),
+ })
+ .await?;
+ match result {
+ WriteResult::Id(id) => Ok(id),
+ _ => unreachable!(),
+ }
+ }
+
+ /// Execute a pipe UPDATE/INSERT/DELETE via the write queue.
+ pub async fn pipe_execute_write_queued(
+ &self,
+ id: i64,
+ sql: &str,
+ binds: Vec<crate::write_queue::PipeBindValue>,
+ ) -> Result<(), sqlx::Error> {
+ use crate::write_queue::WriteOp;
+ self.write_queue
+ .submit(WriteOp::PipeUpdateExecution {
+ id,
+ sql: sql.to_string(),
+ binds,
+ })
+ .await?;
+ Ok(())
+ }
+
+ /// Delete old pipe executions via the write queue.
+ pub async fn pipe_delete_old_executions_queued(&self, keep_per_pipe: i32) -> Result<(), sqlx::Error> {
+ use crate::write_queue::WriteOp;
+ self.write_queue
+ .submit(WriteOp::PipeDeleteOldExecutions { keep_per_pipe })
+ .await?;
+ Ok(())
+ }
+
/// Delete audio chunks in batch via the write coalescing queue.
pub async fn delete_audio_chunks_batch_queued(&self, chunk_ids: Vec<i64>) -> Result<(), sqlx::Error> {
use crate::write_queue::WriteOp;
diff --git a/crates/screenpipe-db/src/lib.rs b/crates/screenpipe-db/src/lib.rs
index 4e4c59d15..c27075454 100644
--- a/crates/screenpipe-db/src/lib.rs
+++ b/crates/screenpipe-db/src/lib.rs
@@ -7,7 +7,7 @@ pub mod text_normalizer;
pub mod text_similarity;
mod types;
mod video_db;
-pub(crate) mod write_queue;
+pub mod write_queue;
pub use db::{
find_matching_a11y_positions, parse_all_text_positions, DatabaseManager, DeleteTimeRangeResult,
diff --git a/crates/screenpipe-db/src/write_queue.rs b/crates/screenpipe-db/src/write_queue.rs
index ad0d58991..dc4735f38 100644
--- a/crates/screenpipe-db/src/write_queue.rs
+++ b/crates/screenpipe-db/src/write_queue.rs
@@ -141,6 +141,27 @@ pub(crate) enum WriteOp {
chunk_id: i64,
batch: Vec<(i64, u32)>,
},
+ /// Clear snapshot_path for frames whose JPEG files are missing/unreadable.
+ /// Routes through the write queue to avoid unserialized writes on the read pool.
+ ClearSnapshotPaths {
+ frame_ids: Vec<i64>,
+ },
+ /// Pipe execution writes — routed through write queue for proper serialization.
+ PipeCreateExecution {
+ pipe_name: String,
+ trigger_type: String,
+ model: String,
+ provider: Option<String>,
+ started_at: String,
+ },
+ PipeUpdateExecution {
+ id: i64,
+ sql: String,
+ binds: Vec<PipeBindValue>,
+ },
+ PipeDeleteOldExecutions {
+ keep_per_pipe: i32,
+ },
/// Batch insert frames with OCR text. Replaces the direct
/// `begin_immediate_with_retry` call in `insert_frames_with_ocr_batch`
/// so that frame inserts go through the coalescing queue.
@@ -156,6 +177,17 @@ pub(crate) enum WriteOp {
},
}
+/// Bind value for pipe execution SQL queries.
+#[derive(Debug, Clone)]
+pub enum PipeBindValue {
+ Text(String),
+ OptText(Option<String>),
+ Int(i64),
+ OptInt(Option<i64>),
+ Int32(i32),
+ OptInt32(Option<i32>),
+}
+
/// Data for a single window in a batch frame insert.
#[derive(Debug, Clone)]
pub(crate) struct FrameBatchWindow {
@@ -756,6 +788,70 @@ async fn execute_single_write(
query.execute(&mut **conn).await?;
Ok(WriteResult::Unit)
}
+
+ WriteOp::ClearSnapshotPaths { frame_ids } => {
+ if frame_ids.is_empty() { return Ok(WriteResult::Unit); }
+ let placeholders: Vec<&str> = frame_ids.iter().map(|_| "?").collect();
+ let sql = format!(
+ "UPDATE frames SET snapshot_path = NULL WHERE id IN ({})",
+ placeholders.join(",")
+ );
+ let mut query = sqlx::query(&sql);
+ for id in frame_ids { query = query.bind(id); }
+ query.execute(&mut **conn).await?;
+ Ok(WriteResult::Unit)
+ }
+
+ WriteOp::PipeCreateExecution { pipe_name, trigger_type, model, provider, started_at } => {
+ let row = sqlx::query_scalar::<_, i64>(
+ r#"INSERT INTO pipe_executions (pipe_name, status, trigger_type, model, provider, started_at)
+ VALUES (?, 'queued', ?, ?, ?, ?)
+ RETURNING id"#,
+ )
+ .bind(&pipe_name)
+ .bind(&trigger_type)
+ .bind(&model)
+ .bind(&provider)
+ .bind(&started_at)
+ .fetch_one(&mut **conn)
+ .await?;
+ Ok(WriteResult::Id(row))
+ }
+
+ WriteOp::PipeUpdateExecution { id: _, sql, binds } => {
+ let mut query = sqlx::query(&sql);
+ for bind in binds {
+ match bind {
+ PipeBindValue::Text(v) => { query = query.bind(v); }
+ PipeBindValue::OptText(v) => { query = query.bind(v); }
+ PipeBindValue::Int(v) => { query = query.bind(v); }
+ PipeBindValue::OptInt(v) => { query = query.bind(v); }
+ PipeBindValue::Int32(v) => { query = query.bind(v); }
+ PipeBindValue::OptInt32(v) => { query = query.bind(v); }
+ }
+ }
+ query.execute(&mut **conn).await?;
+ Ok(WriteResult::Unit)
+ }
+
+ WriteOp::PipeDeleteOldExecutions { keep_per_pipe } => {
+ sqlx::query(
+ r#"DELETE FROM pipe_executions
+ WHERE id NOT IN (
+ SELECT id FROM (
+ SELECT id, ROW_NUMBER() OVER (
+ PARTITION BY pipe_name ORDER BY id DESC
+ ) AS rn
+ FROM pipe_executions
+ )
+ WHERE rn <= ?
+ )"#,
+ )
+ .bind(keep_per_pipe)
+ .execute(&mut **conn)
+ .await?;
+ Ok(WriteResult::Unit)
+ }
}
}
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
index 1e7847a48..fafc37b37 100644
--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
@@ -710,7 +710,7 @@ async fn main() -> anyhow::Result<()> {
// Create pipe store backed by the main SQLite DB
let pipe_store: Option<std::sync::Arc<dyn screenpipe_core::pipes::PipeStore>> =
Some(std::sync::Arc::new(
- screenpipe_engine::pipe_store::SqlitePipeStore::new(db.pool.clone()),
+ screenpipe_engine::pipe_store::SqlitePipeStore::new(db.clone()),
));
let mut pipe_manager = screenpipe_core::pipes::PipeManager::new(
diff --git a/crates/screenpipe-engine/src/pipe_store.rs b/crates/screenpipe-engine/src/pipe_store.rs
index 420a63ff8..fc5e8ca98 100644
--- a/crates/screenpipe-engine/src/pipe_store.rs
+++ b/crates/screenpipe-engine/src/pipe_store.rs
@@ -7,16 +7,20 @@
use anyhow::Result;
use chrono::Utc;
use screenpipe_core::pipes::{PipeExecution, PipeStore, SchedulerState};
-use sqlx::SqlitePool;
+use screenpipe_db::DatabaseManager;
+use std::sync::Arc;
-/// SQLite-backed pipe store using the main screenpipe database pool.
+/// SQLite-backed pipe store using the main screenpipe database.
+/// Reads go through the read pool (27 connections), writes go through
+/// the write coalescing queue for proper serialization — avoiding
+/// unserialized writes that cause WAL contention and pool exhaustion.
pub struct SqlitePipeStore {
- pool: SqlitePool,
+ db: Arc<DatabaseManager>,
}
impl SqlitePipeStore {
- pub fn new(pool: SqlitePool) -> Self {
- Self { pool }
+ pub fn new(db: Arc<DatabaseManager>) -> Self {
+ Self { db }
}
}
@@ -29,36 +33,23 @@ impl PipeStore for SqlitePipeStore {
model: &str,
provider: Option<&str>,
) -> Result<i64> {
- let now = Utc::now().to_rfc3339();
- let row = sqlx::query_scalar::<_, i64>(
- r#"INSERT INTO pipe_executions (pipe_name, status, trigger_type, model, provider, started_at)
- VALUES (?, 'queued', ?, ?, ?, ?)
- RETURNING id"#,
- )
- .bind(pipe_name)
- .bind(trigger_type)
- .bind(model)
- .bind(provider)
- .bind(&now)
- .fetch_one(&self.pool)
- .await?;
-
- Ok(row)
+ Ok(self.db.pipe_create_execution_queued(pipe_name, trigger_type, model, provider).await?)
}
async fn set_execution_running(&self, id: i64, pid: Option<u32>) -> Result<()> {
+ use screenpipe_db::write_queue::PipeBindValue;
let now = Utc::now().to_rfc3339();
- sqlx::query(
+ self.db.pipe_execute_write_queued(
+ id,
r#"UPDATE pipe_executions
SET status = 'running', pid = COALESCE(?, pid), started_at = COALESCE(started_at, ?)
WHERE id = ?"#,
- )
- .bind(pid.map(|p| p as i64))
- .bind(&now)
- .bind(id)
- .execute(&self.pool)
- .await?;
-
+ vec![
+ PipeBindValue::OptInt(pid.map(|p| p as i64)),
+ PipeBindValue::Text(now),
+ PipeBindValue::Int(id),
+ ],
+ ).await?;
Ok(())
}
@@ -72,8 +63,10 @@ impl PipeStore for SqlitePipeStore {
error_type: Option<&str>,
error_message: Option<&str>,
) -> Result<()> {
+ use screenpipe_db::write_queue::PipeBindValue;
let now = Utc::now().to_rfc3339();
- sqlx::query(
+ self.db.pipe_execute_write_queued(
+ id,
r#"UPDATE pipe_executions
SET status = ?,
finished_at = ?,
@@ -87,20 +80,19 @@ impl PipeStore for SqlitePipeStore {
AS INTEGER
)
WHERE id = ?"#,
- )
- .bind(status)
- .bind(&now)
- .bind(stdout)
- .bind(stderr)
- .bind(exit_code)
- .bind(error_type)
- .bind(error_message)
- .bind(&now)
- .bind(&now)
- .bind(id)
- .execute(&self.pool)
- .await?;
-
+ vec![
+ PipeBindValue::Text(status.to_string()),
+ PipeBindValue::Text(now.clone()),
+ PipeBindValue::Text(stdout.to_string()),
+ PipeBindValue::Text(stderr.to_string()),
+ PipeBindValue::OptInt32(exit_code),
+ PipeBindValue::OptText(error_type.map(|s| s.to_string())),
+ PipeBindValue::OptText(error_message.map(|s| s.to_string())),
+ PipeBindValue::Text(now.clone()),
+ PipeBindValue::Text(now),
+ PipeBindValue::Int(id),
+ ],
+ ).await?;
Ok(())
}
@@ -116,27 +108,27 @@ impl PipeStore for SqlitePipeStore {
)
.bind(pipe_name)
.bind(limit)
- .fetch_all(&self.pool)
+ .fetch_all(&self.db.pool)
.await?;
Ok(rows.into_iter().map(|r| r.into()).collect())
}
async fn mark_orphaned_running(&self) -> Result<u32> {
+ use screenpipe_db::write_queue::PipeBindValue;
let now = Utc::now().to_rfc3339();
- let result = sqlx::query(
+ self.db.pipe_execute_write_queued(
+ 0,
r#"UPDATE pipe_executions
SET status = 'failed',
finished_at = ?,
error_type = 'interrupted',
error_message = 'interrupted by system restart'
WHERE status IN ('running', 'queued')"#,
- )
- .bind(&now)
- .execute(&self.pool)
- .await?;
-
- Ok(result.rows_affected() as u32)
+ vec![PipeBindValue::Text(now)],
+ ).await?;
+ // We can't easily get rows_affected through the write queue, return 0
+ Ok(0)
}
async fn get_scheduler_state(&self, pipe_name: &str) -> Result<Option<SchedulerState>> {
@@ -146,65 +138,52 @@ impl PipeStore for SqlitePipeStore {
WHERE pipe_name = ?"#,
)
.bind(pipe_name)
- .fetch_optional(&self.pool)
+ .fetch_optional(&self.db.pool)
.await?;
Ok(row.map(|r| r.into()))
}
async fn upsert_scheduler_state(&self, pipe_name: &str, success: bool) -> Result<()> {
+ use screenpipe_db::write_queue::PipeBindValue;
let now = Utc::now().to_rfc3339();
if success {
- sqlx::query(
+ self.db.pipe_execute_write_queued(
+ 0,
r#"INSERT INTO pipe_scheduler_state (pipe_name, last_run_at, last_success_at, consecutive_failures)
VALUES (?, ?, ?, 0)
ON CONFLICT(pipe_name) DO UPDATE SET
last_run_at = excluded.last_run_at,
last_success_at = excluded.last_success_at,
consecutive_failures = 0"#,
- )
- .bind(pipe_name)
- .bind(&now)
- .bind(&now)
- .execute(&self.pool)
- .await?;
+ vec![
+ PipeBindValue::Text(pipe_name.to_string()),
+ PipeBindValue::Text(now.clone()),
+ PipeBindValue::Text(now),
+ ],
+ ).await?;
} else {
- sqlx::query(
+ self.db.pipe_execute_write_queued(
+ 0,
r#"INSERT INTO pipe_scheduler_state (pipe_name, last_run_at, consecutive_failures)
VALUES (?, ?, 1)
ON CONFLICT(pipe_name) DO UPDATE SET
last_run_at = excluded.last_run_at,
consecutive_failures = pipe_scheduler_state.consecutive_failures + 1"#,
- )
- .bind(pipe_name)
- .bind(&now)
- .execute(&self.pool)
- .await?;
+ vec![
+ PipeBindValue::Text(pipe_name.to_string()),
+ PipeBindValue::Text(now),
+ ],
+ ).await?;
}
Ok(())
}
async fn cleanup_old_executions(&self, keep_per_pipe: i32) -> Result<u32> {
- // Delete all rows except the newest `keep_per_pipe` per pipe_name.
- // Uses a CTE to find the cutoff id per pipe.
- let result = sqlx::query(
- r#"DELETE FROM pipe_executions
- WHERE id NOT IN (
- SELECT id FROM (
- SELECT id, ROW_NUMBER() OVER (
- PARTITION BY pipe_name ORDER BY id DESC
- ) AS rn
- FROM pipe_executions
- )
- WHERE rn <= ?
- )"#,
- )
- .bind(keep_per_pipe)
- .execute(&self.pool)
- .await?;
-
- Ok(result.rows_affected() as u32)
+ self.db.pipe_delete_old_executions_queued(keep_per_pipe).await?;
+ // Can't easily get rows_affected through write queue, return 0
+ Ok(0)
}
async fn get_all_scheduler_states(
@@ -213,7 +192,7 @@ impl PipeStore for SqlitePipeStore {
let rows = sqlx::query_as::<_, SchedulerStateWithNameRow>(
"SELECT pipe_name, last_run_at, last_success_at, consecutive_failures FROM pipe_scheduler_state",
)
- .fetch_all(&self.pool)
+ .fetch_all(&self.db.pool)
.await?;
Ok(rows
@@ -229,7 +208,6 @@ impl PipeStore for SqlitePipeStore {
&self,
limit_per_pipe: i32,
) -> Result<std::collections::HashMap<String, Vec<PipeExecution>>> {
- // Use ROW_NUMBER to get the newest N executions per pipe in 1 query
let rows = sqlx::query_as::<_, PipeExecutionRow>(
r#"SELECT id, pipe_name, status, trigger_type, pid, model, provider,
started_at, finished_at, stdout, stderr, exit_code,
@@ -244,7 +222,7 @@ impl PipeStore for SqlitePipeStore {
ORDER BY pipe_name, id DESC"#,
)
.bind(limit_per_pipe)
- .fetch_all(&self.pool)
+ .fetch_all(&self.db.pool)
.await?;
let mut map: std::collections::HashMap<String, Vec<PipeExecution>> =
@@ -353,15 +331,32 @@ impl From<SchedulerStateWithNameRow> for SchedulerState {
// Tests
// ---------------------------------------------------------------------------
+// Tests require a full DatabaseManager with write queue infrastructure.
+// These are covered by the E2E test suite which has the full DB setup.
+// See tests/e2e/ for integration tests.
#[cfg(test)]
mod tests {
use super::*;
use screenpipe_core::pipes::PipeStore;
+ use std::sync::Arc as StdArc;
async fn setup_test_store() -> SqlitePipeStore {
+ // Use a real DatabaseManager with temp DB for proper write queue testing
+ let tmp = tempfile::NamedTempFile::new().unwrap();
+ let db = StdArc::new(
+ DatabaseManager::new(tmp.path().to_str().unwrap())
+ .await
+ .unwrap(),
+ );
+ SqlitePipeStore::new(db)
+ }
+
+ // Legacy setup kept for reference — the old approach used raw pool
+ // without write queue serialization, which was the root cause of
+ // pool exhaustion on Windows.
+ #[allow(dead_code)]
+ async fn _setup_test_store_legacy() {
let pool = sqlx::SqlitePool::connect("sqlite::memory:").await.unwrap();
- // Create only the tables we need (avoids needing sqlite-vec extension
- // that full migrations require for speaker tables).
sqlx::query(
r#"CREATE TABLE IF NOT EXISTS pipe_executions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -395,7 +390,6 @@ mod tests {
.execute(&pool)
.await
.unwrap();
- SqlitePipeStore::new(pool)
}
#[tokio::test]
diff --git a/crates/screenpipe-engine/src/snapshot_compaction.rs b/crates/screenpipe-engine/src/snapshot_compaction.rs
index da34c5016..605945b71 100644
--- a/crates/screenpipe-engine/src/snapshot_compaction.rs
+++ b/crates/screenpipe-engine/src/snapshot_compaction.rs
@@ -235,16 +235,7 @@ async fn compact_chunk(
device_name
);
for batch in ids.chunks(100) {
- let placeholders: Vec<&str> = batch.iter().map(|_| "?").collect();
- let sql = format!(
- "UPDATE frames SET snapshot_path = NULL WHERE id IN ({})",
- placeholders.join(",")
- );
- let mut query = sqlx::query(&sql);
- for id in batch {
- query = query.bind(id);
- }
- let _ = query.execute(&db.pool).await;
+ let _ = db.clear_snapshot_paths_queued(batch.to_vec()).await;
}
return Ok(None);
}
@@ -281,10 +272,9 @@ async fn compact_chunk(
"snapshot file missing, clearing DB pointer: {}",
snapshot_path
);
- let _ = sqlx::query("UPDATE frames SET snapshot_path = NULL WHERE id = ?")
- .bind(frame_id)
- .execute(&db.pool)
- .await;
+ // Route through write queue instead of read pool to avoid
+ // unserialized writes that cause WAL contention and pool exhaustion.
+ let _ = db.clear_snapshot_paths_queued(vec![*frame_id]).await;
continue;
}