Repository navigation
fix(rust_bridge): keep Messages, token counter and tokenizer routes on Python - #42517
Merged
Merged
Conversation
…th is ready Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
yujonglee-berri
enabled auto-merge (squash)
September 22, 2026 18:55
yujonglee-berri
approved these changes
Sep 22, 2026
Contributor
Author
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
4 of 6 tasks
4 of 6 tasks
yujonglee-berri
added a commit
that referenced
this pull request
Sep 22, 2026
…plicitly #42517 made the Messages, token counter and tokenizer routes Python-only, so tests/test_litellm_rust silently exercised the Python path or failed outright. Each suite now prepends a RUST_OPT_IN rule for its route, keeping native coverage without changing the shipped default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yujonglee-berri
added a commit
that referenced
this pull request
Sep 22, 2026
…ive backend (#42530) * refactor(rust): align the cache crates with Python and activate every backend The cache port had drifted: lifecycle and Redis-only operations sat on `BaseCache`, counters were pinned to `f64`, each semantic backend defined its own embedder and prompt handling, and only the in-memory backend could be selected natively. - Split `disconnect` and `test_connection` out of `BaseCache` into optional capabilities, implemented only where the Python class defines them, and give every Redis-only operation its own capability trait. - Decouple counters from the stored value type, so one backend can serve both responses and counters as Python's `RedisCache` does. - Share one `Embedder` and prompt contract in `litellm_cache::semantic`, and make the Redis and Valkey semantic backends generic over their codec. - Port the Python operations that were missing: `async_refresh_ttl`, `async_rpush_and_trim`, `async_set_cache_pipeline_with_ttls`, the DualCache pipeline, sadd, bulk delete and TTL reads, and the semantic-similarity write-back. - Take the HTTP client from the host pool in the GCS, S3 and Azure backends. - Activate all nine backends through the Rust catalog, whose rules all stay `PYTHON_ONLY`, and route the `Cache` facade's storage calls to the native runtime when one is selected. - Give every crate the same layout, move all tests to `tests/` on rstest, and add the shared `litellm-cache-testing` contract suite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix: freeze native cache request kwargs and batch entries for type discipline Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: declare semantic lookup methods in the native stub Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(rust): align the cache crates with Python and activate every backend The cache port had drifted: lifecycle and Redis-only operations sat on `BaseCache`, counters were pinned to `f64`, each semantic backend defined its own embedder and prompt handling, and only the in-memory backend could be selected natively. - Split `disconnect` and `test_connection` out of `BaseCache` into optional capabilities, implemented only where the Python class defines them, and give every Redis-only operation its own capability trait. - Decouple counters from the stored value type, so one backend can serve both responses and counters as Python's `RedisCache` does. - Share one `Embedder` and prompt contract in `litellm_cache::semantic`, and make the Redis and Valkey semantic backends generic over their codec. - Port the Python operations that were missing: `async_refresh_ttl`, `async_rpush_and_trim`, `async_set_cache_pipeline_with_ttls`, the DualCache pipeline, sadd, bulk delete and TTL reads, and the semantic-similarity write-back. - Take the HTTP client from the host pool in the GCS, S3 and Azure backends. - Activate all nine backends through the Rust catalog, whose rules all stay `PYTHON_ONLY`, and route the `Cache` facade's storage calls to the native runtime when one is selected. - Give every crate the same layout, move all tests to `tests/` on rstest, and add the shared `litellm-cache-testing` contract suite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix: freeze native cache request kwargs and batch entries for type discipline Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: declare semantic lookup methods in the native stub Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(rust): opt the native Messages and tokenizer suites into Rust explicitly #42517 made the Messages, token counter and tokenizer routes Python-only, so tests/test_litellm_rust silently exercised the Python path or failed outright. Each suite now prepends a RUST_OPT_IN rule for its route, keeping native coverage without changing the shipped default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(rust): pop one at a time in the Redis 6 lpop pipeline and drop explanatory comments Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
3 of 5 tasks
yuneng-berri
added a commit
that referenced
this pull request
Sep 26, 2026
* fix: apply configured cache_control_injection_points beside client cache_control marks (#41956) (cherry picked from commit d8267d5) * fix(token_counter): count replayed redacted_thinking blocks so prompt_caching keeps pinning (#42069) (cherry picked from commit 0e7cf51) * fix(mcp): return camelCase tool keys from /v1/mcp/tools after the SDK 2 upgrade (#42352) (cherry picked from commit 5eb4e30) * fix(rust_bridge): keep the Messages route on Python until the Rust path is ready (#42517) rc/1.103.0 has no token counter or tokenizer routes in the catalog, so only the Messages rule moves to PYTHON_ONLY (cherry picked from commit 85ed18e) * fix(proxy): stop leaking periodic tasks on every DB config reload (#42784) (cherry picked from commit fc87a06) --------- Co-authored-by: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
5 tasks done
4 of 6 tasks
jsvisa
added a commit
to jsvisa/litellm
that referenced
this pull request
Nov 11, 2026
Token counter and tokenizer were shipped as RUST_OPT_IN in BerriAI#42174 and moved back to PYTHON_ONLY the same day in BerriAI#42517, whose actual bug was Messages dropping the Anthropic beta inference header. The tokenizer rollback was precautionary, bundled with the Messages fix, and never revisited. The native implementation and its parity tests have been green since, and the spend-tracking caller already falls back to Python counting on RuntimeError and ValueError. RUST_OPT_IN stays default-off, so nothing changes for callers that do not set LITELLM_RUST. Signed-off-by: Delweng <delweng@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
LITELLM_RUST=1,/v1/messageswas dispatched to the Rust pathcontext_management: Extra inputs are not permittedHow it solves it:
Route.MESSAGESgoes back toRollout.PYTHON_ONLYin the route catalogRoute.TOKEN_COUNTERandRoute.TOKENIZERalso move toPYTHON_ONLYLITELLM_RUSTsaysUser Flow
Before: a Claude Code user on a proxy running with
LITELLM_RUST=1gets a 400 as soon as the client sends a compaction editclaude-opus-4-8with"context_management": {"edits": [{"type": "compact_20260112"}]}context_management: Extra inputs are not permittedAfter: the same request succeeds
msg_...response and Claude Code continuesRelevant issues
Follow-up to #42509, which only improved the error text for this case. The unscoped opt-in was introduced in 1a52bae (#41885)
Affected release
Regression since v1.103.0-rc.1, only when
LITELLM_RUST=1is set. No stable release contains the opt-in ruleLinear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Shared setup: proxy started with
LITELLM_RUST=trueand this config, real Anthropic keyRequest body
compact.json{"model":"claude-opus-4-8","max_tokens":32,"messages":[{"role":"user","content":"Reply with the single word ok"}],"context_management":{"edits":[{"type":"compact_20260112"}]}}Before (4bcdaf3)
curl -s -w "\nHTTP %{http_code}\n" localhost:4014/v1/messages -H "Authorization: Bearer sk-1234" -H "content-type: application/json" -d @compact.jsonAfter (0179256)
curl -s -w "\nHTTP %{http_code}\n" localhost:4013/v1/messages -H "Authorization: Bearer sk-1234" -H "content-type: application/json" -d @compact.jsonHeadful Claude Code before/after (same proxies, same Rust setting) is in the PR comment below
Unit check:
tests/test_litellm/rust_bridge/test_catalog.pypasses at the tip (1400 tests) and 378 cases fail when the catalog change is reverted with the updated test in placeType
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/dce6d3c521044e60bd6a40b4284b6016
Open in Devin Desktop: https://app.devin.ai/desktop/session/dce6d3c521044e60bd6a40b4284b6016?variant=devin