Skip to content

refactor(native): discover providers at shared dispatch boundaries - #39939

Closed
yujonglee-berri wants to merge 7 commits into
litellm_native_request_contextfrom
litellm_native_chat_eligibility
Closed

yujonglee-berri wants to merge 7 commits into
litellm_native_request_contextfrom
litellm_native_chat_eligibility

Conversation

@yujonglee-berri

@yujonglee-berri yujonglee-berri commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Generic admission rejected supported native OCR formats

How it solves it:

  • Make private admission pure and provider-aware

User Flow

Before: the SDK request can violate this layer contract.

  1. They request Azure Document Intelligence native output.
  2. A generic format rule declines the request.

After: the same request follows one predictable contract.

  1. They send the same provider-specific request.
  2. Pure admission accepts the selected provider native format.

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • Focused tests covering this change pass locally
  • All required CI/CD checks pass
  • This PR is isolated to one stack responsibility
  • Greptile Confidence Score is at least 4/5

Stack

39928 -> 39913 -> 39923 -> 39941 -> 39939 -> 39484 -> 39986 -> 40054 -> 40055 -> 40056 -> 39765

Layer 5 of 11.

Screenshots / Proof of Fix

After (e5060f8838df1aa6ca2a54473e58cda191cebec2)

  1. Rust admission tests and strict Clippy: passed
  2. UV_PYTHON=3.12 make check: passed
  3. Final stack Rust workspace and strict Clippy: passed

No paid-provider calls were used for deterministic validation.

Type

Bug Fix

Caveats (if any)

Medium

  • Provider execution remains in later stack layers.

Final Attestation

  • Tests cover this layer intended contracts and edge cases

@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_native_chat_eligibility (35f3894) with litellm_native_request_context (905c5cb)1

Open in CodSpeed

Footnotes

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

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

LiteLLM Rust workflow

Workflow completed successfully for 792d8da10fd86cbfc7cc73c297d546e76329cbd1

View workflow run

@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 7a101d4 to 405deac Compare September 5, 2026 21:19
@yujonglee-berri yujonglee-berri changed the title refactor(native): move chat eligibility checks into Rust refactor(native): discover providers at shared dispatch boundaries Sep 5, 2026
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 405deac to 660722e Compare September 6, 2026 00:37
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 660722e to 019080e Compare September 6, 2026 01:08
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 019080e to 27a51f0 Compare September 6, 2026 01:49
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 27a51f0 to 9e0832c Compare September 6, 2026 04:41
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 9e0832c to 0ad7ae3 Compare September 6, 2026 06:19
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 0ad7ae3 to 840963b Compare September 6, 2026 06:35
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 840963b to 152d041 Compare September 6, 2026 07:55
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch 2 times, most recently from d43fcc4 to 7899a93 Compare September 6, 2026 08:33
@yujonglee-berri
yujonglee-berri marked this pull request as ready for review September 6, 2026 14:14
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 7899a93 to ae2e895 Compare September 6, 2026 14:21
@yujonglee-berri
yujonglee-berri requested a review from a team September 6, 2026 14:21
@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes native-route admission and fallback dispatch for chat completions, messages, OCR, transcription, and Responses WebSockets

  • Adds provider-aware Rust preflight checks and shared Python dispatch primitives
  • Moves native preparation and fallback ownership to shared endpoint boundaries
  • Preserves Azure Document Intelligence native OCR data within the normalized response
  • Introduces two test-name regressions and repository-guideline violations in changed Python code

Confidence Score: 4/5

The dispatch refactor appears behaviorally sound, but explicit repository requirements and accidentally uncollected tests must be fixed before merging

No blocking runtime failure was established, but two tests silently stop running and changed provider handlers violate the repository’s source-comment and immutability requirements

Files Needing Attention: tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py, litellm/llms/anthropic/chat/handler.py, litellm/llms/bedrock/chat/converse_handler.py

Important Files Changed

Filename Overview
litellm/rust_bridge/runtime.py Introduces shared endpoint selection, preflight, fallback, and upstream-error mapping
litellm/rust_bridge/chat_completions.py Moves native chat discovery and request preparation to the shared completion boundary
litellm/rust_bridge/messages.py Adds public Messages dispatch with provider-aware preflight and Python fallback
litellm/ocr/main.py Moves OCR native preparation into the public dispatch path while supporting provider-native response preservation
litellm/rust_bridge/transcription.py Adds shared transcription preparation and required-native handling for Bedrock
tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py Two renamed test functions no longer match pytest collection conventions
litellm/llms/anthropic/chat/handler.py Removes local native dispatch but adds prohibited commentary and parameter rebinding
litellm/llms/bedrock/chat/converse_handler.py Removes local native dispatch while introducing prohibited comments, parameter rebinding, and mutation

Reviews (1): Last reviewed commit: 7899a93 | Re-trigger Greptile



def test_has_agentic_completion_hook_detection(monkeypatch):
def testhas_agentic_completion_hook_detection(monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests are no longer collected

Both renamed functions miss pytest's test_ prefix, violating the requirement that modified tests preserve coverage and requiring correction before merge

Rule Used: What: Flag any modifications to existing tests and... (source)

Comment on lines +369 to +374
def build_request() -> tuple[dict, dict]: # mutable-ok: rewritten in place downstream
"""Translate the request the Python way, returning `(headers, data)`.

The pair stays mutable because the streaming path rewrites it in
place (`data["stream"] = True`) before sending.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Disallowed source commentary

The new request-building docstring and headings explain ordinary code, violating the repository's source-comment policy and requiring removal before merge

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

python_client: Final = (
client if isinstance(client, HTTPHandler) else _get_httpx_client(params={"timeout": timeout})
)
if client is None or not isinstance(client, HTTPHandler):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Parameters are rebound

The changed handlers reassign client and timeout and mutate _params, violating the repository's immutability requirement and requiring correction before merge

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from ae2e895 to e5060f8 Compare September 6, 2026 14:32
@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from e5060f8 to 792d8da Compare September 6, 2026 15:23
else initial_headers
)
log_details: Final[NativePreCallDetails] = {
"complete_input_dict": {"model": ctx.model, "messages": ctx.messages, **params},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: Bedrock credentials are copied into pre-call logs

For Bedrock deployments, params contains transport fields such as aws_access_key_id, aws_secret_access_key, aws_session_token, and aws_web_identity_token. Expanding it into complete_input_dict sends those values verbatim to pre-call callbacks, so an authenticated user can trigger disclosure of the deployment's AWS credentials into configured observability systems. Build the logging payload from the provider request body or redact all transport-only fields first; the same issue occurs in litellm/rust_bridge/transcription.py:253.

@veria-ai

veria-ai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

PR overview

This PR refactors native request handling so providers are discovered at shared dispatch boundaries, including the Rust bridge paths for chat completions and transcription.

A significant issue remains: authenticated Bedrock requests can cause AWS credentials and session tokens to be copied into pre-call callback payloads and configured observability systems. No reported issues have yet been addressed, so the credential-handling problem remains unresolved.

Open issues (1)

Fixed/addressed: 0 · PR risk: 7/10

@yujonglee-berri
yujonglee-berri force-pushed the litellm_native_chat_eligibility branch from 792d8da to 35f3894 Compare September 7, 2026 17:43
@yujonglee-berri

Copy link
Copy Markdown
Contributor Author

Closing; stack is being cleaned up.

@yujonglee-berri
yujonglee-berri deleted the litellm_native_chat_eligibility branch September 16, 2026 18:05
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