litellm/litellm-rust/crates/python-bridge
Yujong Lee 80b6ab73b7 refactor(rust): run Python hooks and host calls as async fns on the caller's task
The Python driver was a hand-written continuation machine: every hook and
host call returned a step, the driver parked a resume function in a Pending
slot, and the hook chain kept per-phase state to pick up where it stopped.
This replaces that with one async body per call, polled only from the
caller's Python task through a new PythonTask primitive. Hooks and host
calls are plain async fns that await Python awaitables through
PythonTask::settle, so the caller's task and contextvars context still run
every hook of a call, and the core coroutine stays as it is.

HookStep, HostStep, HookResume, HostResume and the Pending enum are gone.
The hook chain is a loop over boxed async hooks. The legacy callback
adapter awaits its deployment hooks and failure handlers in place, and the
cache binding awaits the Python cache the same way.

The handle shares the binding, hooks and keyword view with the body through
a lock released around native steps and stream boundaries, so GC traversal
still reaches retained Python objects while a call waits on the runtime or
on its consumer. A new driver test pins that an abandoned stream retained
by a hook is collected.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-12 01:02:47 +00:00
..
benches refactor(rust): add types and core-utils crates, unify the provider error 2026-09-17 22:01:14 -07:00
src refactor(rust): run Python hooks and host calls as async fns on the caller's task 2026-10-12 01:02:47 +00:00
tests refactor(rust): add types and core-utils crates, unify the provider error 2026-09-17 22:01:14 -07:00
AGENTS.md docs(agents): ban semicolons and colons in human-facing text (#45684) 2026-10-09 16:36:32 -07:00
build.rs feat: package Rust OCR bridge in LiteLLM wheel (#31267) 2026-06-25 12:32:55 -07:00
Cargo.toml refactor(rust): give Messages configs typed litellm params (#45611) 2026-10-09 16:29:45 -07:00
preflight_contract.json refactor(rust): move credential inheritance and the SDK limits out of the legacy callback crate into a driver preflight (#43259) 2026-09-26 01:09:36 +00:00