Repository navigation
fix(rust-bridge): keep proxy /v1/messages calls on Rust when a cache or shared session is configured - #47811
fix(rust-bridge): keep proxy /v1/messages calls on Rust when a cache or shared session is configured#47811mateo-berri wants to merge 6 commits into
Conversation
…or shared session is configured Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
bugbot run |
|
@litereview code-review |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning
Comparing |
|
…so streams stay on Rust Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
| if fields.get("stream") is not True or stream_timeout is None: | ||
| return kwargs | ||
| return {**kwargs, "timeout": stream_timeout} | ||
| return {**{key: value for key, value in kwargs.items() if key != "stream_timeout"}, "timeout": stream_timeout} |
There was a problem hiding this comment.
High · Streamed /v1/messages calls are killed once total stream time exceeds stream_timeout
- An admin enables
LITELLM_RUST=trueand sets a deploymentstream_timeout(for example 60s). The router forwardsstream_timeouton every streamedanthropic_messagescall through_STREAM_TIMEOUT_AWARE_GENERIC_HANDLERS. - A client sends a streamed POST to
/v1/messagesfor an Anthropic model, and generation takes longer than 60s. _native_kwargsnow removesstream_timeoutfrom the kwargs it gives the detectors and moves its value intotimeout.timeout_variantsno longer fires, so the call goes to Rust instead of Python. The PR description says streamed cells are deferred and stay on Python, but this change moves them.- Rust Messages passes
timeoutto reqwestRequestBuilder::timeout, which limits the whole request including the body (litellm-rust/crates/http/src/outbound.rs). Python treatsstream_timeoutas a per-read limit on a live stream (CompletionTimeout.for_stream,StreamKind.LIVE). A healthy stream that keeps sending chunks still fails withAPIConnectionError: error decoding response bodyonce its total time passesstream_timeout.
The smallest fix is to revert the _native_kwargs change so streams with stream_timeout stay on Python, as the PR description promises. Streams can move to Rust once Rust supports a per-read stream timeout.
Evidence
Local repro against a stub SSE upstream that sends 12 events 0.4s apart (about 5s total). The call was litellm.anthropic_messages(..., stream=True, timeout=30.0, stream_timeout=1.5) with LITELLM_RUST=true.
Base _native_kwargs monkeypatched in: OK chunks 11 5.87 <AnthropicMessagesStreamingResponse>. The call stayed on Python and finished.
PR head _native_kwargs: ERR APIConnectionError litellm.APIConnectionError: upstream network error: error decoding response body. The call went to Rust and was cut off by the 1.5s total deadline.
Same head without stream_timeout: OK chunks 13 6.18 <litellm.rust_bridge.execution.AsyncStream>. This confirms Rust serves the stream fine without the deadline.
Routing check: old kwargs give ['timeout_variants'] Rollout.PYTHON_ONLY. New kwargs give [] Rollout.RUST_OPT_IN.
send() in inference-messages/src/handler.rs -> OutboundRequest::send -> builder.timeout(timeout). reqwest applies this as a total deadline that covers reading the response body.
The PR changes test_native_streams_are_bounded_by_stream_timeout to assert resolved["timeout"] == 0.5. That locks in the total-deadline behavior and does not check per-read semantics.
Latest summary by code-review · View this review · Reviewed 487242006ace
There was a problem hiding this comment.
Agreed, Rust applies timeout to the whole stream. Reverted in 976f7ca, streams with stream_timeout stay on Python until Rust gets a per-read limit
There was a problem hiding this comment.
Finding withdrawn
Thanks for the revert. The current code fixes the issue I reported.
- At head
976f7ca280, the PR no longer changes_native_kwargsinlitellm/messages/dispatch.py. The diff for that file now removes only theRESPONSE_CACHEdetector. _native_kwargscopiesstream_timeoutintotimeoutbut leaves thestream_timeoutkey in place.- For a streamed call, that key triggers
detectors.timeout_variants(streaming(request) and present(request, "stream_timeout")), which routes the call to Python. - Python then applies
stream_timeoutas a per-read limit, so Rust's total-request reqwest deadline no longer cuts off healthy long streams.
Evidence
Current _native_kwargs: return {**kwargs, "timeout": stream_timeout}, which keeps the stream_timeout key.
Local run at head: _native_kwargs({'stream': True}, {'stream': True, 'timeout': 30.0, 'stream_timeout': 1.5}) -> {'stream': True, 'timeout': 1.5, 'stream_timeout': 1.5}; detectors.timeout_variants(...) -> True.
litellm/rust_bridge/detectors.py:53-58: timeout_variants fires on streaming(request) and present(request, "stream_timeout").
The PR diff no longer modifies test_native_streams_are_bounded_by_stream_timeout.
pytest tests/test_litellm_rust/messages/test_dispatch.py -k "stream_timeout or TIMEOUT or proxy_cache": 4 passed.
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed 976f7ca28022 · View follow-up
…timeout so streams stay on Rust" This reverts commit 4872420.
|
@litereview code-review |
|
@litereview code-review |
[Medium impact] The reviewed changes appear safe to merge SummaryKeeps cached Messages calls on Rust, ignores the proxy’s shared session when checking for caller-owned clients, and restores DeepSeek and Vertex AI eligibility The latest changes update three browser tests to type the guardrail name before deletion. Those names match the modal’s confirmation field. No new actionable issues were found The earlier unnumbered finding is fixed.
Reviews (4) · Last reviewed commit: "test(e2e): type the guardrail name befor..." · Reviewed by Greptile |
…lout rules Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
…_rust_messages_routing
|
@litereview code-review |
|
bugbot run |
…l UI specs Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 4ff9ee6. Configure here.
|
@litellm-stampbot |
litellm-stampbot: risk highNot approved at Rules (
Cursor Bugbot: Medium Risk at Pushes do not re-run this check. Comment |
Since the catalog routing refactors landed, a LiteLLM proxy with a response cache configured sends every /v1/messages call to the Python path even when Rust is turned on, and DeepSeek and Vertex AI Claude messages stopped reaching Rust at all. This PR puts those calls back on Rust, which is what turned the scheduled CircleCI
integration-providersjob red on mainDetails
TLDR
Problem this solves:
integration-providersred on main in every scheduled run since 91444How it solves it:
User Flow
Before: an admin runs the proxy with
LITELLM_RUST=trueand Redis caching, and /v1/messages never reaches Rustcache: truewith Redis in config.yaml and starts the proxy withLITELLM_RUST=trueAfter: the same request is served by Rust
LITELLM_RUST=truebootAffected release
Regression on main since #46714 and #46750, not yet in a release
CircleCI on main
integration-providers: pipeline 91442 at 5c341e7 (workflow)integrationworkflow was rerun from failed twice (4b4e006e, c8a9d03e). Every claimed non-stream cell passed in all three providers runs, and every providers cell still red in the last run (job 2266409) is also red on main Earlier runs 91466 at 2b7c7fd, 91465 at 1f43c93 and 91464 at 976f7ca were supersededFailing test ids this PR claims (non-stream cells):
test_rust_anthropic_safeguards_beta_wire(sdk, raw, deepseek, vertex, malformed, duplicated, null cells)test_rust_anthropic_safeguards_beta_chaos(worker sigkill, proxy shutdown)test_idle_upstream_keepalive_edges_wire,test_idle_upstream_keepalive_override_wiretest_idle_upstream_reconnect_rust_messages_wire,test_vertex_credentials_source_wire::test_rust_messages_route_loads_a_claude_key_file_and_names_unloadable_credentialsCulprit: 730db4d (#46714) and 0ccae7a (#46750), both merged 2026-10-20
Mechanism:
admit_native()cache check withdetectors.response_cache, which fires wheneverlitellm.cacheis set. The Rust Messages host already serves Python-owned and native caches throughcache::configure, so the old decline only covered caches with no backend, and the new detector moved every cached proxy call to Pythondetectors.caller_clientalso fires onshared_session, which the proxy passes on every call. Native replaces that pool with its own client, so it is not a caller-owned transportRUST_OPT_INrule to{"anthropic"}, dropping DeepSeek and Vertex AI Claude even though its own description keeps only non-Claude Vertex on Python, which theTarget.MESSAGESrule already handlesAlso fixed here,
e2e_ui_testingin theintegrationworkflow on main. Last green at 01:12 UTC on 2026-10-21, red with the guardrail delete failures in every run from 03:12 UTC at 0e24bbb (job [2265974]([REDACTED SECRET]/gh/BerriAI/litellm/2265974)) through 08:12 UTC at 66c8f5b (job [2266188]([REDACTED SECRET]/gh/BerriAI/litellm/2266188))guardrails.spec.ts"Delete a guardrail", "Create a Presidio guardrail, see it in team settings, and delete it", andpresidioUserStory.spec.ts"masks PII sent from the Playground and shows the run in Logs" (its fixture teardown deletes the guardrail)DeleteResourceModalwithrequiredConfirmation, which keeps Delete disabled until the exact name is typed. That PR meant to add the typed-name step, but the three specs still click Delete straight awayelement is not enabledDeferred to a later run (still red on main, not claimed here):
Streamed Messages cells (
[stream],-streamparams of the files above). The router passesstream_timeouton proxy streams andFeature.TIMEOUT_VARIANTSkeeps them on Python. Rust appliestimeoutas a deadline for the whole stream while Python treatsstream_timeoutas a per-read limit, so they move back only once Rust gets a per-read stream timeouttest_bedrock_converse_lookaround_regex_wire::test_a_base_model_in_the_request_body_only_ever_loosens, a schema diff unrelated to routingGemini sampling, long-decode, fragmented-stream and function-call cells, Bedrock runtime chat cell,
integration-managementOne-off cells on the PR pipeline that pass on main and in the runs around them, left to the deflake automation.
test_config_overrides::test_cyberark_incremental_update_encrypts_reloads_on_restart_and_delete_clearsfailed once in integration-security job 2266368 and passed all 234 tests on rerun job 2266399.test_signoz_delivery::test_terminating_the_proxy_right_after_a_burst_flushes_every_span_before_exitfailed once in extensions job 2266398.test_bedrock_batch_retrieve_reports_lifecycle_status_in_orderfailed once in providers job 2266374 and passed on reruntest_anthropic_messages_pre_content_retry_wiredropped-attempt usage cells, which log('failure', 0, 0)for the dropped attempt now and then. It failed once in providers job 2266397 and reproduces at the main merge base locally too (1 in 9 runs), so it predates this PRThe
[stream]cells oftest_peer_outage_mid_safeguards_burst_relays_each_verdict_once_and_recovers, which stay on Python with the other streamed Messages cells aboveintegration-extensions, wheretest_guardrail_effects::test_concurrent_disconnects_during_a_guardrail_outage_each_record_exactly_one_verdictfails on main (jobs 2266138, 2266158, 2266209) the same way it fails on this branchPre-Submission checklist
Screenshots / Proof of Fix
QA ran at the tip 2b7c7fd (After) against 66c8f5b (Before, run from its own worktree with
PYTHONPATHpinned to it), each a real proxy with--num_workers 2,LITELLM_RUST=true, Redis caching on, real Anthropic and DeepSeek calls, no mocks. An earlier round on 473e1a4 gave the same results. The tip 4ff9ee6 only adds the e2e spec change on top of 2b7c7fd, and the After leg rerun on 4ff9ee6 matched row for row (Rust header on both Messages models, sameidon cache hits 2 and 3). The spec change itself is proven bye2e_ui_testingpassing in the PR pipelinex-litellm-rustx-litellm-rust: truex-litellm-rustx-litellm-rust: trueidid, served by RustHeadline case, config is
cache: truewithcache_params.type: redisplus the two modelsCache hits keep working on the Rust path
Caveats (if any)
Medium
Type
🐛 Bug Fix
Link to Devin session: https://app.devin.ai/sessions/5d9b22d00ab943099f1c0384682fce7e
Open in Devin Desktop: https://app.devin.ai/desktop/session/5d9b22d00ab943099f1c0384682fce7e?variant=devin
Requested by: @mateo-berri
Note
Medium Risk
Changes core Rust vs Python routing for the messages API on cached proxy traffic and additional providers; behavior shift is intentional but affects production request paths.
Overview
Fixes a regression where proxy
/v1/messagestraffic with Rust enabled was incorrectly routed to Python when a response cache or the proxy’sshared_sessionwas in play, and where DeepSeek and Vertex AI messages no longer opted into the Rust path.Routing:
Feature.RESPONSE_CACHEis dropped from messages Python-only feature detection so a configured cache does not force the Python handler (Rust already participates in cache configuration).caller_clientnow keys only on an explicit callerclient, notshared_session. The messagesRUST_OPT_INrule again includesdeepseekandvertex_aialongsideanthropic.Tests: Unit/dispatch tests cover cache + shared session staying on native; guardrail E2E deletes type the guardrail name into the delete confirmation field before confirming.
Reviewed by Cursor Bugbot for commit 4ff9ee6. Bugbot is set up for automated code reviews on this repo. Configure here.