Skip to content

fix: catch ORT panics in rfdetr model initialization#3318

Merged
louis030195 merged 1 commit into
mainfrom
fix/3267-ort-panic-rfdetr
May 10, 2026
Merged

fix: catch ORT panics in rfdetr model initialization#3318
louis030195 merged 1 commit into
mainfrom
fix/3267-ort-panic-rfdetr

Conversation

@louis030195

Copy link
Copy Markdown
Collaborator

Problem

RF-DETR model initialization panics when ONNX Runtime fails to initialize. Sentry reports ~174 crashes daily with Failed to initialize ORT API messages 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

  • Add create_session_safe() helper wrapping Session builder in std::panic::catch_unwind
  • Convert panics into proper RedactError::Runtime values
  • Add test ensuring corrupt model files fail gracefully instead of panicking

Confidence: 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)

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

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()

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
```
@louis030195 louis030195 merged commit 24b45a3 into main May 10, 2026
13 of 20 checks passed
@louis030195 louis030195 deleted the fix/3267-ort-panic-rfdetr branch May 10, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant