mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-02 01:28:38 +00:00
* refactor(rust-bridge): require the native extension _native ships in every wheel and the sdist will not install without it, yet the bridge loaded it optionally and carried None paths that could fail open for fork safety, exception mapping and OTLP errors. Delete loader.py and import _native directly. Tests inject a fake module through NativeBinding(source=...) or with_source() instead of patching the loader The install smoke checks now verify the compiled module, and tests fail instead of skipping when _native is missing. The interactions spec canary installs the project so it has the extension Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ci): build Rust bridge in Windows smoke tests --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
4.3 KiB
4.3 KiB
Ownership
- This package owns
- choosing Rust or Python for each call, and falling back to Python when Rust is unavailable
- Python public API compatibility at the native boundary
- projecting Python settings into the values Rust reads
- the Python bindings handed to the Rust bridge
- It does not own
- provider execution, which is Rust core
- CPython runtime mechanics, which is
litellm-host-python - legacy callback sharing and dispatch policy, which is
callbacks-legacy-python
host/holds the modules Rust imports by name to read Python-owned state.host/AGENTS.mdstates that contract
Routing
catalog.pydecides, the detectors describe the request,dispatch.pyapplies the decision- Shared detectors live in
detectors.py; route-only detectors live in<route>/detectors.py - The first matching rule wins. A context no rule matches stays on Python
- Every Python-only exclusion for a route (a
targetsorfeaturesrule) sits above any Rust rule for that route - A route whose Python side is
NO_PYTHONresolves toRUST_REQUIREDfor every context it can producetests/test_litellm_rust/test_public_entries.pymarks such a routepython=None, so dropping a route's Python changes its entries, its rules and that field together
- A detector reads the same inputs the legacy Python path reads, so the catalog and the fallback agree on which requests need Python
- A route's context, its target as well as its features, reads
NativeCall.resolved, so an argument counts the same whether it came by position, by keyword or as a signature default - A route's sync and async dispatches read different detector maps when the legacy handlers differ: Messages runs pre-request hooks, web search interception and interceptors only on async calls, and the sync Responses handler runs the deployment hook itself
- A route's context, its target as well as its features, reads
- A detector that raises keeps the call on Python.
PublicDispatchlogs it and never fails the call over routing catalog.RULESis rollout policy with no tests of its own. Tests pass the rules they need, so check these invariants by review wheneverRULESchanges
Public entries
- Every route serves
a<entry>(...),<entry>(..., a<entry>=True)anda<entry>(..., a<entry>=True)the same way, handing native one identicalNativeCallwith no async flag on the async binding tests/test_litellm_rust/test_public_entries.pyholds this for every route in its table, so a new public route gets a row there
Execution
execution.pyowns generic inline execution, stream iteration and the step classes Rust constructs- Native entrypoints return an unstarted
Execution.execution.synchronousorexecution.asynchronoushands it to the caller throughrunordrive, so Rust never names a Python driver or stream class - Keep one driver, implementing generator-style
send(send(None)starts),throwand idempotentclose - Generic steps and suspension handling never depend on LiteLLM response metadata. Public stream construction,
_hidden_paramsand header compatibility stay in the product wrappers, and generic stream heads stay opaque - Await each selected suspension in the caller's task, so hooks keep their thread, loop and context
- Return a final awaitable as a value instead of awaiting it implicitly
- Closing, cancellation and
GeneratorExitrelease the execution without replaying provider work or starting more callbacks
Fallback
- Native admission may pick Python before execution starts
- A failure after execution starts is terminal and never triggers fallback
- Creating an unstarted native coroutine acquires no clients or credentials and captures no execution context
Native extension
_nativeships in every wheel and the sdist builds it, so it is always importable- Import it with
from litellm.rust_bridge import _nativeand use the attributes_native.pyideclares - Never add a
Nonebranch,getattrdefault or stand-in class for a missing extension
Verification
- Check cross-language behavior against a freshly installed extension, covering unstarted-call release, setup ordering, exception identity, sync and async streams, cancellation and GC
- Keep
_native.pyiaccurate about which APIs return a Future and which return a coroutine - Unit tests of this package live in
tests/unit/rust_bridge/, end-to-end Rust path tests intests/test_litellm_rust/