Skip to content

feat(rust-bridge): extend native dispatch foundation to chat completions, responses, and messages - #42805

Merged
yujonglee-berri merged 7 commits into
mainfrom
litellm_native_dispatch_chat_responses_messages
Sep 23, 2026
Merged

yujonglee-berri merged 7 commits into
mainfrom
litellm_native_dispatch_chat_responses_messages

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Chat completions and Responses had no explicit catalog rule, only the implicit Python default
  • Their Python bindings named native completion/acompletion/responses/aresponses that the extension never exported
  • Chat completions and Messages dispatch boundaries had no behavioral tests

How it solves it:

  • Explicit PYTHON_ONLY catalog rules for CHAT_COMPLETIONS and RESPONSES, matching embeddings and Messages
  • Declining native completion/acompletion/responses/aresponses scaffolds, same shape as embeddings (feat(embeddings): add native dispatch foundation #42799)
  • _native.pyi declarations for the four new exports
  • Dispatch tests for chat completions and Messages, modeled on the embeddings tests
  • Fixes the stubtest failure rust-wheel has had on main since feat(embeddings): add native dispatch foundation #42799: runtime parameter names and __all__ now match _native.pyi

Routes left Python-only after this PR: chat completions, Responses, Messages, embeddings. None of them ships a native rollout. The existing keyword-style chat_completions/achat_completions native functions and the Responses WebSocket connection are untouched. No provider-native execution is added

User Flow

Before: a developer calls any of the three routes and gets the Python result

  1. They send POST https://litellm-domain/v1/chat/completions, POST https://litellm-domain/v1/responses, or POST https://litellm-domain/v1/messages
  2. The Python implementation handles the request and the response comes back unchanged

After: the same calls return the same Python results

  1. They send the same three requests
  2. The Python implementation still handles every request, now under explicit Python-only catalog rules; nothing visible changes

Relevant issues

Follows #42799

Affected release

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

This PR is foundation only: no user-visible behavior changes and no provider calls are added, so there is no live before/after to capture. Validation at the tip (b1fa7dd), merge base dc14e76:

Before (dc14e76)

  1. python -c "from litellm.rust_bridge import _native; _native.completion" fails with AttributeError: module has no attribute 'completion' (same for acompletion, responses, aresponses)

After (b1fa7dd)

  1. python -I -m mypy.stubtest --mypy-config-file tests/test_litellm/rust_bridge/stubtest.ini litellm.rust_bridge._native on a fresh maturin develop build: Success: no issues found in 1 module (main fails with 19 errors on the embeddings exports)
  2. maturin develop then python -c "from litellm.rust_bridge import _native; _native.completion({}, (), {})" raises RustBridgeDeclined: native chat completions route is not implemented (same shape for the other three)
  3. LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync pytest tests/test_litellm/chat_completions tests/test_litellm/messages tests/test_litellm/rust_bridge tests/test_litellm/responses/test_dispatch.py tests/test_litellm/embeddings: all pass except one preexisting tenacity import error in test_responses_with_retries_uses_the_dispatch_entrypoint, unrelated to this change
  4. cargo fmt --all --check, cargo clippy -p litellm-python-bridge --all-targets, cargo test -p litellm-python-bridge routes:: (39 passed) clean
  5. ruff format/ruff check and basedpyright clean on every changed Python file

Type

🆕 New Feature
✅ Test

Caveats (if any)

Low

  • Native scaffolds only decline; a real route machine is follow-up work
  • Catalog rules restate the existing Python default, so runtime behavior is identical

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

yujonglee-berri and others added 3 commits September 23, 2026 21:24
…ings

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>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The dispatch behavior appears sound, but the required fallback coverage must be completed before merging

Findings

  1. P2 Fallback Coverage Is Incomplete ▶

Summary

This PR explicitly keeps chat completions and Responses on Python, exports declining native scaffolds for both routes, updates extension typing, and adds chat-completions and Messages dispatch coverage

  • Registers completion, acompletion, responses, and aresponses in the PyO3 module
  • Adds matching request and response declarations to the native stub
  • Adds explicit PYTHON_ONLY catalog entries without changing current route selection
  • Adds focused dispatch and argument-projection tests
  • Still needs the repository-required module-missing fallback coverage for the newly exposed routes

Reviews (1) · Last reviewed commit: "refactor(rust-bridge): keep secret manag..."

Comment thread litellm-rust/crates/python-bridge/src/lib.rs
@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_native_dispatch_chat_responses_messages (b1fa7dd) with main (49d0ece)

Open in CodSpeed

yujonglee-berri and others added 4 commits September 23, 2026 21:35
…e surface

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…eddings in the stub

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>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@yujonglee-berri
yujonglee-berri enabled auto-merge (squash) September 23, 2026 21:41
@yujonglee-berri
yujonglee-berri merged commit 170eb7f into main Sep 23, 2026
100 checks passed
@yujonglee-berri
yujonglee-berri deleted the litellm_native_dispatch_chat_responses_messages branch September 23, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant