Repository navigation
fix(count_tokens): backport Bedrock Mantle count_tokens fallback to stable/1.103.x - #47743
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
@litereview full |
|
|
|
||
|
|
||
| def _counter(bedrock: _Bedrock) -> BedrockTokenCounter: | ||
| return BedrockTokenCounter(client=AsyncHTTPHandler(transport=httpx.MockTransport(bedrock))) |
There was a problem hiding this comment.
Medium · New backported tests fail on stable/1.103.x: AsyncHTTPHandler(transport=...) and missing e2e/integration helper modules
All three groups of new tests were written against helpers that do not exist on this line. Two of the groups fail before any test runs.
- Unit tests. Both new unit-test files build the client with
AsyncHTTPHandler(transport=httpx.MockTransport(...)):test_bedrock_token_counter.py:41andtest_bedrock_mantle_count_tokens_handler.py:42. On this line,AsyncHTTPHandler.__init__(litellm/llms/custom_httpx/http_handler.py:604) has notransportparameter, so each test fails withTypeError: AsyncHTTPHandler.__init__() got an unexpected keyword argument 'transport'. - Integration test.
tests/integration/providers/test_bedrock_mantle_count_tokens_wire.py:22importsintegration._support.bedrock_runtime_peer. That module is not intests/integration/_support/, so collection fails withModuleNotFoundError. - E2E test.
tests/e2e/llm_translation/test_messages_count_tokens_bedrock_e2e.py:19importse2e_metadata. No such module exists undertests/e2e/, so collection fails withModuleNotFoundError: No module named 'e2e_metadata'.
What happens if this merges: the tests/test_litellm job goes red with 11 failures. Every test that exercises the new Mantle fallback (the runtime-400/404 retry, the non-Claude no-retry rule, the system/tools pass-through on Mantle, and Mantle error status reporting) never actually runs. A later regression in BedrockTokenCounter or BedrockMantleCountTokensHandler on this stable line would go uncaught.
These files were taken as-is from the stable/1.104.x and main picks. To fix them, either adapt them to this line's test harness (for example, build an httpx.AsyncClient(transport=...) and inject it into the handler), or pull in the missing helpers.
Evidence
.venv/bin/python -m pytest tests/test_litellm/llms/bedrock/count_tokens → 11 failed, all with TypeError: AsyncHTTPHandler.__init__() got an unexpected keyword argument 'transport'
pytest --collect-only tests/e2e/llm_translation/test_messages_count_tokens_bedrock_e2e.py → ModuleNotFoundError: No module named 'e2e_metadata'
cd tests && pytest --collect-only integration/providers/test_bedrock_mantle_count_tokens_wire.py → collection error. tests/integration/_support/ contains no bedrock_runtime_peer.py
Latest summary by full · View this review · Reviewed 696e1c3c87ca
…translation_cost_stable_1_103_x # Conflicts: # litellm/model_prices_and_context_window_backup.json # litellm/proxy/hooks/proxy_track_cost_callback.py # litellm/responses/litellm_completion_transformation/streaming_iterator.py # model_prices_and_context_window.json # tests/test_litellm/proxy/hooks/test_proxy_track_cost_callback.py # tests/test_litellm/test_utils.py # uv.lock
Summary
Backport of #45317 and the Bedrock part of #46430 onto
stable/1.103.x. Bedrock Runtime CountTokens rejects newer Claude models with a 400 or 404, so/v1/messages/count_tokensfell back to a local estimate that undercounts. Runtime is still tried first, then Claude models fall back to the Bedrock Mantle Anthropic count_tokens endpoint, and non-Claude models never call Mantle. Same changestable/1.104.xgot in #47634Picks
577d74c1as71118e89, conflicted in the Bedrock counter and tests, resolved by keeping the line's types and moving the two Bedrock tests into the line's tests/test_litellm layout08a24d39asde896efc, conflicted in the Gemini, Vertex and Google endpoint files, resolved by keeping the line's versions and taking onlybedrock_token_counter.pyplus its two Bedrock testsis_mantle_claude_modelhelper fromstable/1.104.x(6a801372) as696e1c3c, applied clean. Main got it from fix(bedrock_mantle): route Claude chat completions to the native Messages endpoint #43646, which is too wide to pick hereThis is a mechanical pick. Tests, Black, the grype sweep, /gauntlet-mini, the live leg and the version bump were skipped, so the 1.103 patch bump is still owed before a release
Linear ticket
Resolves LIT-9563
p0-regression: LIT-9563
Link to Devin session: https://app.devin.ai/sessions/7663d25bd05a4d06b8871043e834b3a0
Open in Devin Desktop: https://app.devin.ai/desktop/session/7663d25bd05a4d06b8871043e834b3a0?variant=devin
Requested by: @mateo-berri