Repository navigation
refactor(ocr): complete native lifecycle and preserve Azure auth - #40734
Conversation
Greptile SummaryThis PR moves supported OCR execution into the native lifecycle while retaining a Python fallback and preserving Azure Document Intelligence authentication across submission and polling.
Confidence Score: 5/5The PR appears safe to merge, with no outstanding blocking findings at the current tip. The latest test change fully isolates endpoint selection while retaining a decisive assertion that the dedicated Document Intelligence key is used instead of the generic Azure AI key. The previously reported streaming helpers now have complete parameter and return typing. yujonglee-berri accepted the earlier disconnected-completion behavior as intended for a subsequent change, and that thread was resolved. The final-response callback, core callback ownership, and public helper typing threads were manually resolved without explanation; current code also addresses their reported behavior.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/ocr/test_legacy.py | Explicitly supplies the Document Intelligence endpoint so the auth-precedence regression test is independent of developer environment configuration. |
| litellm/llms/azure_ai/ocr/document_intelligence/transformation.py | Resolves Document Intelligence connection settings independently and builds service-specific API-key or Entra authentication. |
| litellm-rust/crates/core/src/ocr/adapters/azure/document_intelligence/polling.rs | Preserves authentication during polling and dispatches post-call handling for the final provider response. |
| litellm-rust/crates/core/src/ocr/lifecycle.rs | Implements native OCR lifecycle sequencing while delegating selected host operations through the bridge. |
| litellm/rust_bridge/ocr_lifecycle.py | Drives native lifecycle suspension and resumption while preserving Python task and exception behavior. |
Reviews (14): Last reviewed commit: "test(ocr): isolate Azure auth precedence..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@greptileai Please re-review the wrapper handoff fixes and new replacement, failure, deferral, context, and identity coverage. |
|
@greptileai please review the current tip after the immutable invocation-kwargs fix and replacement-hook regression coverage. |
|
@greptileai please review |
|
@greptileai Please review 505016e for typed OCR completion handoff, wrapper-owned cleanup, cancellation handling, and deferred callback behavior |
|
@greptileai Please review 1eeaaad: explicit lazy executor import, corrected submit protocol, real-thread context coverage, and Rust fixture isolation |
a060565 to
026fa18
Compare
1eeaaad to
2642fa3
Compare
186d378 to
fcfcdd9
Compare
2642fa3 to
69d45ce
Compare
fcfcdd9 to
a609a0d
Compare
69d45ce to
34743ed
Compare
a609a0d to
985b28a
Compare
34743ed to
12c885d
Compare
985b28a to
9e22e01
Compare
12c885d to
9529d16
Compare
9e22e01 to
64e2a77
Compare
9529d16 to
26eafc4
Compare
64e2a77 to
6f02d84
Compare
26eafc4 to
20cdd87
Compare
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
|
@greptileai Please review current tip 02e150c after Azure auth consolidation, response-cap enforcement, and successful local Clippy and regression tests |
|
@greptileai Please review current tip fa6bdf2 after aligning compiled-wheel OCR tests with explicit GIL module and public validation contracts |
|
@greptileai Please review current tip af77246 after isolating Azure Document Intelligence auth precedence coverage from developer environment configuration |
347b642
into
litellm_internal_staging
TLDR
Problem this solves:
How it solves it:
LITELLM_RUST=0keeps the Python path availableUser Flow
Before: OCR behavior depends on the selected runtime and Azure Document Intelligence can fail with valid credentials
litellm.ocr()orlitellm.aocr()with a supported documentLITELLM_RUST=0selects PythonUnknown operation status: NoneAfter: both runtime choices preserve the public SDK behavior and Azure authentication
litellm.ocr()orlitellm.aocr()with the same supported documentLITELLM_RUST=0selects PythonDesign
This PR replaces the former #40734 / #40676 stack and consolidates #40437 and #40499
Core selects setup, request preparation, provider work, public response construction, deployment processing, metadata finalization, and terminal dispatch. Python performs selected host operations while retaining caller-owned objects, exception identity, and scheduling behavior
The native execution handle exposes
start,resume_value,resume_error, and idempotentclose. An ordinary Python coroutine awaits selected operations in the caller task. Retained Python references participate in garbage collection, and cancellation signals provider work with an awaited termination acknowledgement where requiredAsynchronous native operations are polled once while detached from Python and inside the Tokio runtime. Ready operations complete directly; pending operations retain the same future and use the existing cancellation-aware scheduler. Logging retains only its needed fields, avoiding an extra document copy
Bridge-created OCR loggers check live registrations at each phase. Requests without optional consumers skip deployment hook coroutines, logging executor scheduling, deferred objects, callback context copies, traceback formatting, and logging-only payload conversions. Credentials, limits, cost accounting, timing, response metadata, and context cleanup remain active
Provider responses use a 64 MiB server-side byte limit across OCR, upload, and polling requests.
max_response_bytesmay lower that limit for one call but cannot raise it. Oversized success responses fail without draining the body; upstream errors retain their HTTP status and a bounded diagnostic prefixProvider workflows cover Mistral, Cohere, Azure Mistral, Azure Cohere, Azure Document Intelligence, Vertex Mistral, Vertex DeepSeek, and Reducto
Relevant issues
Supersedes #40676, #40437, and #40499
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Shared setup: run
/tmp/ocr_auth_matrix.pyfrom the repository virtual environment with live provider credentialsBefore (
9132a5343b)Default Rust OCR
.venv/bin/python /tmp/ocr_auth_matrix.py --rust --jobs 4 --delay 0.25Python fallback Azure Document Intelligence
LITELLM_RUST=0 .venv/bin/python /tmp/ocr_auth_matrix.py --jobs 2 --delay 0.75Unknown operation status: NoneAfter (
af77246920)Default Rust OCR
.venv/bin/python /tmp/ocr_auth_matrix.py --rust --case azure-di-env-key --case azure-di-explicit-key --jobs 1 --delay 10Python fallback Azure Document Intelligence
LITELLM_RUST=0 .venv/bin/python /tmp/ocr_auth_matrix.py --case azure-di-env-key --case azure-di-explicit-key --jobs 1 --delay 1Type
Refactoring
Bug Fix
Caveats (if any)
Low
Validation
The current tip passes 201 focused Python OCR, native configuration, and Azure transformation tests. The isolated compiled-wheel suite passes all 183 Rust-extension Python tests. The response-cap regression, WebSocket crypto-provider integration, and all 63 Python bridge library tests pass. Workspace Clippy passes for all targets with warnings denied.
make checkpasses Python formatting, Ruff, type discipline, basedpyright, test-quality budgets, import checks, and generated API checks. Hosted CI is green with 88 passing checks, one intentional skip, and passing patch coverage. Greptile reports 5/5 confidence with no blocking findings, and Veria reports no open security concerns. No lint or coverage thresholds were changedLive matrix runs exercised sync and async requests through default Rust execution and the
LITELLM_RUST=0Python fallback. Rust passed Azure Document Intelligence environment and explicit key cases, plus the previously rate-limited Azure Cohere explicit-key cases. Python passed all four Azure Document Intelligence cases after the port. Subsequent Azure Cohere calls reached provider rate limits after one successful Python requestFinal Attestation