Skip to content

refactor(rust): formalize legacy callback contract - #41885

Merged
yujonglee-berri merged 13 commits into
mainfrom
litellm_rust_callback_contract
Sep 18, 2026
Merged

yujonglee-berri merged 13 commits into
mainfrom
litellm_rust_callback_contract

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor
  • Introduce a typed, route-neutral contract for legacy Python callbacks
  • Route OCR lifecycle handling through the shared callback contract
  • Expand Rust and Python coverage for callback payloads, lifecycle behavior, and edge cases

Link to Devin session: https://app.devin.ai/sessions/2f296a111dc8492e9b14c3254927c683
Open in Devin Desktop: https://app.devin.ai/desktop/session/2f296a111dc8492e9b14c3254927c683?variant=devin
Requested by: @yujonglee-berri

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_rust_callback_contract (ba6b22c) with main (b0887b6)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (bc6b540) during the generation of this report, so b0887b6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

This PR is not safe to merge until resolved OCR provider credentials are kept out of callback-visible logging state and the test rule violation is corrected

Findings

  1. P1 Security Provider key exposed ▶
  2. P2 Mutable test state ▶

Summary

This PR formalizes the Rust-to-Python legacy callback contract, routes OCR through the shared lifecycle, introduces typed secret handling, and expands lifecycle and payload coverage

  • Centralizes borrowed Python callback functions behind a typed Rust contract
  • Moves OCR startup, request, response, success, and failure handling through the shared lifecycle
  • Adds property and integration coverage for callback payload identity, mutation, failure handling, and deferred logging
  • Introduces a callback-visible provider-key exposure that must be removed before merge

Reviews (1) · Last reviewed commit: "test(rust): fix request count and header..."

@yujonglee-berri yujonglee-berri added the rust Pull requests that update rust code label Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.21739% with 80 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/rust_bridge/lifecycle.py 44.18% 48 Missing ⚠️
litellm/rust_bridge/legacy_callbacks.py 68.04% 31 Missing ⚠️
litellm/rust_bridge/messages/route_host.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

yujonglee-berri and others added 12 commits September 18, 2026 15:43
Every legacy callback call from callbacks-legacy now goes through one typed
Python shim, litellm.rust_bridge.legacy_callbacks, the only Python module
the crate reaches. Before, the crate called Logging methods, litellm.utils
hooks, the logging worker, the executor and several litellm globals
directly, and its tests retyped those signatures by hand, so an outdated
fake could accept a call the real code rejects. python_contract.json lists
each shim function's parameters: a Python test pins it to the real
signatures and a Rust test pins it to the Rust enum.

The lifecycle contract changes to match the Python @client wrapper:
- the driver emits CallEvent::Started before begin, so every host sees one
  start time
- RequestContext carries the route-resolved api_key, so legacy pre_call and
  post_call receive it, and post_call's additional_args match the Python OCR
  path
- Passthrough and its re-aliasing are gone
- async deployment hooks always run, and the "no callbacks" shortcut that
  skipped the logging payload is removed, as in the Python path

The OCR api_key is a SecretValue from the wire request onward, so Debug
output upstream of the callback contract cannot leak it.

host-python's RouteHost now classifies native failures once through
classify, and host ops return HostOpError. The OCR route host keeps main's
public errors by sending both through the existing Python map_failure.
…acts

The payload boundary of callbacks-legacy gets a model-based proptest: for any
JSON body, caller keywords and callback edit, keywords the route sends unchanged
reach pre_call as the caller's own objects, and the wire is the body pre_call
received as the callback left it. A parametrized test pins that a keyword the
bridge never reads keeps its identity through setup, the deployment hook,
check_limits and prepare.

Behaviour owned by the real Logging object is pinned end to end in the OCR
tests: a hypothesis version of the body property over HTTP, sync hooks seeing no
running event loop, retained payloads staying intact after the call, success
callbacks sharing one standard logging payload, and state stashed before a
blocking deployment hook raises reaching both failure callback families
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…to the Machine trait

core/src/machine was route-neutral runtime code sitting among route surfaces, and the workspace had two modules named machine. It now lives in litellm-host beside the contract it implements, so core only holds routes. The OCR conversion from MachineFault moves to litellm-llms because the orphan rule no longer allows it in core
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@yujonglee-berri
yujonglee-berri force-pushed the litellm_rust_callback_contract branch from e9e0d46 to 41873e2 Compare September 18, 2026 22:47
Comment thread litellm/rust_bridge/lifecycle.py Dismissed
Replace the module-level LATEST_EDITS list with per-example callback
registry isolation, and import litellm names with from-imports in the
legacy callback shim so the module uses one import style.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@yujonglee-berri
yujonglee-berri merged commit 018f640 into main Sep 18, 2026
89 of 91 checks passed
@yujonglee-berri
yujonglee-berri deleted the litellm_rust_callback_contract branch September 18, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants