litellm/litellm-rust/crates/host
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
..
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): centralize host execution and compose callbacks (#43515) 2026-09-28 19:20:27 +00:00
AGENTS.md refactor(rust): run Python hooks and host calls as async fns on the caller's task 2026-10-12 01:02:47 +00:00
Cargo.toml refactor(rust): share call lifecycle across route-owned inference (#43461) 2026-09-27 16:05:30 -07:00