Skip to content

feat: allow caller-controlled ORT loading - #1

Closed
AnthonyRonning wants to merge 1 commit into
mainfrom
opensecret/caller-controlled-ort-loading
Closed

feat: allow caller-controlled ORT loading#1
AnthonyRonning wants to merge 1 commit into
mainfrom
opensecret/caller-controlled-ort-loading

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Jul 21, 2026

Copy link
Copy Markdown

Summary

  • add a loader-neutral ocr-ort feature for applications that already manage ONNX Runtime linking/loading
  • keep the existing ocr feature backward-compatible by continuing to enable dynamic loading
  • preserve the existing gpu feature dynamic-loader behavior
  • move only OCR feature gates and documentation; parser and inference algorithms are unchanged

Validation

  • cargo fmt --all -- --check
  • cargo check --locked --no-default-features --features ocr-ort --lib
  • cargo check --locked --no-default-features --features ocr --lib
  • cargo check --locked --no-default-features --features gpu --lib
  • feature-tree assertions confirm ocr-ort does not enable load-dynamic/disable-linking and legacy ocr does
  • focused OCR tests and example checks pass under both loader policies

A broad upstream target still encounters the existing fax argument-type failure in test_ccitt_decoder_diagnosis under both the new and legacy configurations; this PR intentionally leaves that unrelated test untouched.

Summary by CodeRabbit

  • New Features

    • Added the ocr-ort feature for native ONNX Runtime OCR with caller-controlled linking and loader settings.
    • Updated OCR and GPU configurations to support runtime ONNX Runtime loading.
    • OCR fallback now reports a typed unavailable reason without crashing or returning silent empty output.
  • Documentation

    • Expanded OCR setup, runtime loading, linked builds, environment configuration, and WebAssembly guidance.
    • Clarified feature selection and troubleshooting instructions.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The OCR feature graph now separates native ORT support from dynamic loading. Rust, FFI, Python, examples, documentation, and OCR tests use ocr-ort, while legacy ocr retains dynamic runtime loading.

Changes

OCR feature split

Layer / File(s) Summary
Cargo feature contract
Cargo.toml
Adds ocr-ort, removes dependency-level dynamic loading, and explicitly enables dynamic loading for ocr and gpu.
Native OCR compilation path
src/lib.rs, src/ocr/*, src/document.rs, src/extractors/auto.rs, src/error.rs
Moves native OCR module, backend, extraction, fallback, and error gates from ocr to ocr-ort.
OCR bindings and example gates
src/ffi.rs, src/python.rs, examples/ocr_scanned_pdf.rs
Compiles OCR FFI, Python bindings, and the example under ocr-ort.
Documentation and test gates
docs/*, tests/*
Documents dynamic versus linked ORT setup and updates OCR test compilation gates to ocr-ort.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: yfedoseev

Poem

A rabbit hops through feature lines,
Splitting loaders, paths, and signs.
ORT blooms where OCR-ORT grows,
Docs and tests now follow those flows.
“Hop hop!” says Bun, “the gates align!”

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding caller-controlled ONNX Runtime loading via the new OCR feature split.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch opensecret/caller-controlled-ort-loading

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/python.rs (1)

2351-2364: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Align disabled-path guidance with the ocr/ocr-ort feature split.

  • src/python.rs#L2351-L2364: explain that the ocr package extra enables ocr-ort, while direct source builds can select ocr-ort.
  • examples/ocr_scanned_pdf.rs#L44-L48: document both ocr dynamic loading and ocr-ort caller-managed linking, with matching commands.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/python.rs` around lines 2351 - 2364, The disabled OCR path guidance in
src/python.rs lines 2351-2364 must explain that the ocr package extra enables
ocr-ort, while direct source builds may select ocr-ort; update the documentation
without changing the extraction logic. Also update examples/ocr_scanned_pdf.rs
lines 44-48 to document both ocr dynamic loading and ocr-ort caller-managed
linking, including matching commands.
src/extractors/auto.rs (1)

1027-1051: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the stale feature documentation.

These implementations now use ocr-ort, but nearby docs still say prefetching and OCR are controlled by ocr. Standalone ocr-ort builds therefore receive incorrect setup guidance. Update those references, mentioning ocr only as the compatibility alias if appropriate.

Suggested wording update
-/// ... no-op without the `ocr` feature ...
+/// ... no-op without the `ocr-ort` feature ...
-/// With `ocr` the ONNX ...
+/// With `ocr-ort` the ONNX ...
-/// was compiled with the `ocr` feature ...
+/// was compiled with the `ocr-ort` feature ...
-/// attempted only with the `ocr` feature ...
+/// attempted only with the `ocr-ort` feature ...

Also applies to: 1069-1069, 1212-1213

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/extractors/auto.rs` around lines 1027 - 1051, Update the nearby feature
documentation associated with the OCR model prefetch/setup code and the
additional references around the later affected sections to identify `ocr-ort`
as the controlling feature. Mention `ocr` only as a compatibility alias where
needed, and ensure standalone `ocr-ort` builds receive correct setup guidance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_ccitt_decoder_diagnosis.rs`:
- Line 2: Isolate the failing test_ccitt_decoder_diagnosis module instead of
enabling it through the broad ocr-ort feature gate. Either correct its
argument-type mismatch or add a separate exclusion/ignore so the native OCR test
lane remains unaffected when ocr-ort is enabled.

---

Outside diff comments:
In `@src/extractors/auto.rs`:
- Around line 1027-1051: Update the nearby feature documentation associated with
the OCR model prefetch/setup code and the additional references around the later
affected sections to identify `ocr-ort` as the controlling feature. Mention
`ocr` only as a compatibility alias where needed, and ensure standalone
`ocr-ort` builds receive correct setup guidance.

In `@src/python.rs`:
- Around line 2351-2364: The disabled OCR path guidance in src/python.rs lines
2351-2364 must explain that the ocr package extra enables ocr-ort, while direct
source builds may select ocr-ort; update the documentation without changing the
extraction logic. Also update examples/ocr_scanned_pdf.rs lines 44-48 to
document both ocr dynamic loading and ocr-ort caller-managed linking, including
matching commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f68977b7-0f78-437a-8031-32863593bc20

📥 Commits

Reviewing files that changed from the base of the PR and between fec4efa and b1a9901.

📒 Files selected for processing (32)
  • Cargo.toml
  • docs/OCR_GUIDE.md
  • docs/getting-started-rust.md
  • examples/ocr_scanned_pdf.rs
  • src/document.rs
  • src/error.rs
  • src/extractors/auto.rs
  • src/ffi.rs
  • src/lib.rs
  • src/ocr/backend.rs
  • src/ocr/error.rs
  • src/python.rs
  • tests/test_alice_wonderland.rs
  • tests/test_auto_hybrid_text_image_520.rs
  • tests/test_auto_ocr_image_519.rs
  • tests/test_auto_ocr_multilang_519.rs
  • tests/test_ccitt_decoder_diagnosis.rs
  • tests/test_ccitt_edge_cases.rs
  • tests/test_ccitt_params_extraction.rs
  • tests/test_full_extraction.rs
  • tests/test_image_filters.rs
  • tests/test_ocr.rs
  • tests/test_ocr_inference.rs
  • tests/test_ocr_integration.rs
  • tests/test_ocr_module.rs
  • tests/test_ocr_page_detection.rs
  • tests/test_ocr_scanned_document.rs
  • tests/test_ocr_with_models.rs
  • tests/test_pdf_ccitt_params.rs
  • tests/test_prefetch_models_519.rs
  • tests/test_pride_prejudice.rs
  • tests/test_stream_filters.rs

@@ -1,5 +1,5 @@
#![allow(warnings)]
#[cfg(feature = "ocr")]
#[cfg(feature = "ocr-ort")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Isolate the known failing CCITT test before enabling it here.

The PR notes that test_ccitt_decoder_diagnosis still has an argument-type failure. This gate now includes that failing module whenever ocr-ort is enabled, preventing the native OCR test lane from passing. Fix the mismatch or exclude/ignore this diagnostic test separately.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_ccitt_decoder_diagnosis.rs` at line 2, Isolate the failing
test_ccitt_decoder_diagnosis module instead of enabling it through the broad
ocr-ort feature gate. Either correct its argument-type mismatch or add a
separate exclusion/ignore so the native OCR test lane remains unaffected when
ocr-ort is enabled.

@AnthonyRonning

Copy link
Copy Markdown
Author

Superseded by #2. This first branch was based on upstream main and would have imported 43 unpublished commits beyond v0.3.74. The replacement maintenance PR is based directly on the peeled v0.3.74 release commit and contains only the loader-policy change.

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