fix: catch ORT panics in rfdetr model initialization#3318
Merged
Conversation
Fixes #3317 The RF-DETR adapter was calling `Session::builder()` without panic handling. When ONNX Runtime initialization fails (e.g., missing drivers, corrupted binary, ABI mismatch), the crate panics instead of returning a proper error. This causes Sentry to report ~174 crashes daily: 'Failed to initialize ORT API'. The speaker module already has proper panic handling via `catch_panic_into_error`. This fix applies the same pattern to RF-DETR, converting panics into `RedactError::Runtime` so initialization failures are reported gracefully. ### Changes - Add `create_session_safe()` helper that wraps `Session::builder()` in panic handling - Replace unsafe direct calls with the safe wrapper - Add test ensuring corrupt model files return errors instead of panicking ### Verification ``` running 6 tests test adapters::rfdetr::tests::corrupt_model_file_returns_runtime_error ... ok test adapters::rfdetr::tests::default_path_lives_under_screenpipe_dir ... ok test adapters::rfdetr::tests::expected_sha256_is_64_hex_chars ... ok test adapters::rfdetr::tests::hex_sha256_matches_known_value ... ok test adapters::rfdetr::tests::missing_model_path_is_unavailable ... ok test adapters::rfdetr::tests::ensure_model_present_passes_through_when_file_already_correct ... ok test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RF-DETR model initialization panics when ONNX Runtime fails to initialize. Sentry reports ~174 crashes daily with
Failed to initialize ORT APImessages on macOS and Linux when drivers are missing or binaries are corrupted.Root cause
The RF-DETR adapter calls
ort::session::Session::builder()without panic wrapping. When ONNX Runtime API initialization panics, the error bubbles directly to the tokio runtime, gets captured by Sentry, and terminates the task.The speaker module already has proper panic handling but RF-DETR replicates the old pattern.
Fix
create_session_safe()helper wrapping Session builder instd::panic::catch_unwindRedactError::RuntimevaluesConfidence: 9/10
Root cause is obvious from code inspection. The pattern is well-established in the codebase (speaker module). Panic wrapping is mechanical. All tests pass.
Verification (Tier T1)
Sources (multi-source)
Sentry: SCREENPIPE-APP-9X/9Y (174 combined ORT panics in last 24h) | GitHub issue: #3317 | Code inspection: rfdetr.rs unprotected Session::builder()