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(audio): stop building throwaway ORT sessions in boot-time model pre-download (#4991)
Ezra Ellette766f06d9f2b3
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex d0cb5c452..7f2536d3c 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1388,7 +1388,13 @@ async fn main() {}},async {- match screenpipe_audio::speaker::models::get_or_download_model(+ // File-only fetch — NOT get_or_download_model, which also builds+ // an ORT session. That session would be immediately discarded here+ // and would compete for CPU with the real session build that+ // SegmentationManager does moments later for the same file (root+ // cause of the "ort session init: timed out after 30s" boot warning+ // observed on the macos-15-intel CI runner).+ match screenpipe_audio::speaker::models::ensure_model_file(screenpipe_audio::speaker::models::PyannoteModel::Segmentation).await {Ok(p) => info!("segmentation model pre-download complete: {:?}", p),@@ -1396,7 +1402,7 @@ async fn main() {}},async {- match screenpipe_audio::speaker::models::get_or_download_model(+ match screenpipe_audio::speaker::models::ensure_model_file(screenpipe_audio::speaker::models::PyannoteModel::Embedding).await {Ok(p) => info!("embedding model pre-download complete: {:?}", p),diff --git a/crates/screenpipe-audio/src/speaker/models.rs b/crates/screenpipe-audio/src/speaker/models.rsindex e932f96e5..f4a4aa533 100644--- a/crates/screenpipe-audio/src/speaker/models.rs+++ b/crates/screenpipe-audio/src/speaker/models.rs@@ -36,14 +36,39 @@ pub async fn get_or_download_model(model_type: PyannoteModel) -> Result<LoadedMoget_or_download_model_with_retries(model_type, MAX_RECOVERY_RETRIES).await}+/// Ensure the model file is on disk without building an ORT session for it.+///+/// Callers that only want the file warmed in cache (e.g. main.rs's opportunistic+/// boot-time pre-download) must use this instead of `get_or_download_model` —+/// that one unconditionally calls `create_session`, which is a real CPU-bound+/// ONNX Runtime graph load/optimize, not just a disk check. A pre-download call+/// that builds (and immediately discards) a session competes for CPU with the+/// *real* session build that `SegmentationManager`/`EmbeddingExtractor` does+/// moments later on the same file, and on a CPU-constrained host that+/// self-inflicted contention is enough to trip `ORT_INIT_TIMEOUT` on both sides+/// (observed on GitHub's `macos-15-intel` runner: concurrent pre-download ++/// on-demand session builds for the same model pushed session build time from+/// the normal sub-second range past the 30s watchdog).+pub async fn ensure_model_file(model_type: PyannoteModel) -> Result<PathBuf> {+ let (url, filename, model_path_lock, downloading_flag) = model_state(model_type);+ let cache_dir = get_cache_dir()?;+ let downloader = ModelDownloader::new(+ url.to_string(),+ filename.to_string(),+ cache_dir,+ downloading_flag,+ model_path_lock,+ );+ downloader.ensure_model_available().await+}+async fn get_or_download_model_with_retries(model_type: PyannoteModel,max_retries: u8,) -> Result<LoadedModel> {let mut retry_count = 0;loop {- let (url, filename, model_path_lock, downloading_flag) = model_state(model_type);- let cache_dir = get_cache_dir()?;+ let (_, filename, model_path_lock, _) = model_state(model_type);{let mut cached = model_path_lock.lock().await;@@ -58,14 +83,7 @@ async fn get_or_download_model_with_retries(}}- let downloader = ModelDownloader::new(- url.to_string(),- filename.to_string(),- cache_dir,- downloading_flag,- model_path_lock,- );- let path = downloader.ensure_model_available().await?;+ let path = ensure_model_file(model_type).await?;match create_session(&path) {Ok(session) => return Ok(LoadedModel { path, session }),