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

refactor: move GPU serialization to audiopipe, remove redundant locks

Louis Beaumonta708378f1f98
diff --git a/Cargo.lock b/Cargo.lock
index 712370cb5..7817e6c9c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -242,7 +242,7 @@ dependencies = [
[[package]]
name = "antirez-asr-sys"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/audiopipe.git?rev=d9cf445#d9cf445483c6a8ea24a5eb6ee92c84353408cba6"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=95297cb#95297cbad694f3d0eac27884bdfa0e1428770c7a"
dependencies = [
"cc",
]
@@ -560,7 +560,7 @@ dependencies = [
[[package]]
name = "audiopipe"
version = "0.2.0"
-source = "git+https://github.com/screenpipe/audiopipe.git?rev=d9cf445#d9cf445483c6a8ea24a5eb6ee92c84353408cba6"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=95297cb#95297cbad694f3d0eac27884bdfa0e1428770c7a"
dependencies = [
"antirez-asr-sys",
"half",
@@ -5983,7 +5983,7 @@ checksum = "478e0585659a122aa407eb7e3c0e1fa51b1d8a870038bd29f0cf4a8551eea972"
[[package]]
name = "qwen3-asr-sys"
version = "0.1.0"
-source = "git+https://github.com/screenpipe/audiopipe.git?rev=d9cf445#d9cf445483c6a8ea24a5eb6ee92c84353408cba6"
+source = "git+https://github.com/screenpipe/audiopipe.git?rev=95297cb#95297cbad694f3d0eac27884bdfa0e1428770c7a"
dependencies = [
"cc",
"cmake",
diff --git a/crates/screenpipe-audio/Cargo.toml b/crates/screenpipe-audio/Cargo.toml
index 2a166deb1..ca3c75b3c 100644
--- a/crates/screenpipe-audio/Cargo.toml
+++ b/crates/screenpipe-audio/Cargo.toml
@@ -83,7 +83,7 @@ ort = { version = "=2.0.0-rc.6", default-features = false, features = ["ndarray"
ort-sys = { version = "=2.0.0-rc.6", default-features = false }
knf-rs = "0.3.2"
futures = "0.3.31"
-audiopipe = { git = "https://github.com/screenpipe/audiopipe.git", rev = "d9cf445", default-features = false, features = ["qwen3-asr-antirez-blas", "parakeet"], optional = true }
+audiopipe = { git = "https://github.com/screenpipe/audiopipe.git", rev = "95297cb", default-features = false, features = ["qwen3-asr-antirez-blas", "parakeet"], optional = true }
mlx-rs = { version = "0.25", optional = true }
bytes = { version = "1.9.0", features = ["serde"] }
rand = "0.9.0"
diff --git a/crates/screenpipe-audio/src/transcription/engine.rs b/crates/screenpipe-audio/src/transcription/engine.rs
index 885688d75..c39c50f98 100644
--- a/crates/screenpipe-audio/src/transcription/engine.rs
+++ b/crates/screenpipe-audio/src/transcription/engine.rs
@@ -19,19 +19,6 @@ use std::sync::Mutex as StdMutex;
use tracing::{error, info, warn};
use whisper_rs::{WhisperContext, WhisperState};
-/// Global GPU serialization lock for MLX Metal operations.
-///
-/// MLX uses asynchronous Metal command buffers that can overlap even when the
-/// Rust model mutex is held. If a Metal command buffer fails (e.g. GPU memory
-/// pressure, timeout), MLX calls abort() — killing the entire process. This
-/// mutex ensures only ONE MLX transcription uses the GPU at any time,
-/// preventing concurrent Metal submissions from different threads.
-///
-/// Uses std::sync::Mutex (not tokio) because transcription runs on blocking threads.
-#[cfg(feature = "parakeet-mlx")]
-static MLX_GPU_LOCK: std::sync::LazyLock<std::sync::Mutex<()>> =
- std::sync::LazyLock::new(|| std::sync::Mutex::new(()));
-
/// MLX Metal memory management — cap the GPU buffer cache to prevent unbounded growth.
/// MLX's caching allocator keeps freed GPU buffers for reuse; without a limit the
/// cache grows to 10+ GB over hours of transcription on a 0.6B model.
@@ -613,17 +600,9 @@ impl TranscriptionSession {
#[cfg(feature = "parakeet-mlx")]
Self::ParakeetMlx { model, .. } => {
- // Acquire the global GPU lock — only one MLX operation at a time.
- // This prevents concurrent Metal command buffer submissions that
- // cause abort() when the GPU can't handle overlapping workloads.
- let _gpu_guard = match MLX_GPU_LOCK.lock() {
- Ok(g) => Some(g),
- Err(poisoned) => {
- tracing::warn!("mlx gpu lock poisoned (previous panic), recovering");
- Some(poisoned.into_inner())
- }
- };
-
+ // GPU serialization is handled by audiopipe's Model::GPU_LOCK.
+ // The per-model mutex here just prevents concurrent Rust access
+ // to the same Model instance.
let mut engine = model.lock().map_err(|e| anyhow!("stt model lock: {}", e))?;
// Clear GPU cache before transcription to reduce Metal command buffer
// errors from GPU memory pressure (prevents abort in MLX completion handler)