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 cli image redactor mlx crash (#3840)

Louis Beaumont0c930e8beb16
diff --git a/crates/screenpipe-engine/Cargo.toml b/crates/screenpipe-engine/Cargo.toml
index a5fdee38e..3354dc07c 100644
--- a/crates/screenpipe-engine/Cargo.toml
+++ b/crates/screenpipe-engine/Cargo.toml
@@ -165,9 +165,10 @@ apple-intelligence = ["dep:screenpipe-apple-intelligence"]
qwen3-asr = ["screenpipe-audio/qwen3-asr"]
parakeet = ["screenpipe-audio/parakeet"]
parakeet-mlx = ["screenpipe-audio/parakeet-mlx"]
-# Image-PII detector via MLX (Apple Silicon-only). Off by default;
-# Mac release builds opt in to pick up the ~6× speedup over the ONNX
-# CoreML EP path.
+# Image-PII detector via MLX (Apple Silicon-only). Compiled into macOS
+# release builds for experiments, but the CLI runtime keeps ONNX as the
+# default stable path unless SCREENPIPE_ENABLE_EXPERIMENTAL_RFDETR_MLX=1
+# is set.
rfdetr-mlx = ["screenpipe-redact/mlx-mac"]
# v45 phase 3 text-PII redactor via ONNX Runtime. CPU baseline for
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
index a746c8d35..22fc3968f 100644
--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs
@@ -1880,43 +1880,48 @@ async fn main() -> anyhow::Result<()> {
use screenpipe_redact::{ImageRedactionPolicy, ImageRedactor};
use std::sync::Arc;
- // Prefer the MLX runtime on Mac when the safetensors weights
- // are present (~6× faster than the CoreML EP path). Falls
- // through to the ONNX adapter otherwise — load_or_download
- // fetches rfdetr_v9.onnx from
- // huggingface.co/screenpipe/pii-image-redactor on first run
- // (~108 MB), verifies SHA-256, caches at
- // ~/.screenpipe/models/. Subsequent starts are instant.
+ // The desktop app intentionally uses the ONNX image redactor for
+ // local mode. Keep the standalone CLI on that same stable path by
+ // default: the MLX RF-DETR port is still experimental and can crash
+ // the process while reconciling large frame backlogs. Developers can
+ // still opt in while iterating on that runtime.
#[allow(unused_mut)]
let mut detector_arc: Option<Arc<dyn ImageRedactor>> = None;
#[cfg(all(feature = "rfdetr-mlx", target_os = "macos", target_arch = "aarch64"))]
{
- use screenpipe_redact::adapters::rfdetr_mlx::{RfdetrMlxConfig, RfdetrMlxRedactor};
- let mlx_cfg = RfdetrMlxConfig::default();
- // Mirrors the ONNX adapter: download once, verify SHA-256,
- // cache at ~/.screenpipe/models/rfdetr_v9.safetensors.
- if let Err(e) = mlx_cfg.ensure_model_present().await {
- tracing::info!(
- "rfdetr-mlx safetensors download failed ({e}); falling back to ONNX adapter"
- );
- } else {
- match RfdetrMlxRedactor::load(mlx_cfg) {
- Ok(d) => {
- info!("image-PII detector: rfdetr-mlx (Apple Silicon GPU)");
- // Lazy-load + 60 s idle-unload — frees the
- // ~150–200 MB MLX resident footprint when the
- // worker is paused or the reconciliation queue
- // has drained. Same pattern as OpfAdapter.
- let d = Arc::new(d);
- let _ = Arc::clone(&d).spawn_idle_unloader();
- detector_arc = Some(d as Arc<dyn ImageRedactor>);
- }
- Err(e) => {
- tracing::info!(
- "rfdetr-mlx load failed ({e}); falling back to ONNX adapter"
- );
+ if std::env::var_os("SCREENPIPE_ENABLE_EXPERIMENTAL_RFDETR_MLX").is_some() {
+ use screenpipe_redact::adapters::rfdetr_mlx::{RfdetrMlxConfig, RfdetrMlxRedactor};
+ let mlx_cfg = RfdetrMlxConfig::default();
+ // Mirrors the ONNX adapter: download once, verify SHA-256,
+ // cache at ~/.screenpipe/models/rfdetr_v9.safetensors.
+ if let Err(e) = mlx_cfg.ensure_model_present().await {
+ tracing::info!(
+ "rfdetr-mlx safetensors download failed ({e}); falling back to ONNX adapter"
+ );
+ } else {
+ match RfdetrMlxRedactor::load(mlx_cfg) {
+ Ok(d) => {
+ info!("image-PII detector: rfdetr-mlx (Apple Silicon GPU)");
+ // Lazy-load + 60 s idle-unload — frees the
+ // ~150–200 MB MLX resident footprint when the
+ // worker is paused or the reconciliation queue
+ // has drained. Same pattern as OpfAdapter.
+ let d = Arc::new(d);
+ let _ = Arc::clone(&d).spawn_idle_unloader();
+ detector_arc = Some(d as Arc<dyn ImageRedactor>);
+ }
+ Err(e) => {
+ tracing::info!(
+ "rfdetr-mlx load failed ({e}); falling back to ONNX adapter"
+ );
+ }
}
}
+ } else {
+ tracing::info!(
+ "rfdetr-mlx disabled by default for CLI stability; \
+ set SCREENPIPE_ENABLE_EXPERIMENTAL_RFDETR_MLX=1 to opt in"
+ );
}
}
if detector_arc.is_none() {