[Test] Remove dead Bedrock clear_thinking interleaved-thinking-beta assertion#25913
Conversation
…ssertion Drop test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_management. Its assertion 'interleaved-thinking-2025-05-14' in betas cannot hold because anthropic_beta_headers_config.json maps that header to null for the bedrock provider, so filter_and_transform_beta_headers drops it from the auto-added beta set before anthropic_beta is written to the request. The adjacent test_bedrock_invoke_messages_skips_thinking_injection_when_already_enabled already covers the inverse behavior for the same model, so no coverage is lost.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR removes Confidence Score: 4/5Safe to merge but should first restore the two valid thinking-injection assertions before removing the test entirely. The beta assertion being removed is demonstrably dead code (confirmed against production source). However, the PR deletes the entire test rather than trimming just the failing lines, silently dropping the only coverage of the clear_thinking auto-injection path (thinking.type and budget_tokens). That coverage gap is a present concern, not a speculative one, warranting a 4 instead of 5. tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py — the removed test contained valid assertions beyond the failing beta check
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py | Removes the entire test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_management test and the BEDROCK_MIN_THINKING_BUDGET_TOKENS import; the beta assertion in that test was provably dead, but the thinking-injection assertions it also contained were valid and now go uncovered. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["transform_anthropic_messages_request\nclear_thinking_20251015 present,\nno explicit thinking param"] --> B["injected_thinking_for_clear_thinking = True\nadd thinking: enabled + budget_tokens"]
B --> C["beta_set.add('interleaved-thinking-2025-05-14')"]
C --> D["filter_and_transform_beta_headers\nprovider='bedrock'"]
D --> E{"anthropic_beta_headers_config.json\nbedrock mapping?"}
E -- "null → drop" --> F["'interleaved-thinking-2025-05-14'\nNOT in result['anthropic_beta']"]
E -- "value → keep" --> G["header in result['anthropic_beta']"]
subgraph "Removed test asserted F was G"
H["assert 'interleaved-thinking-2025-05-14' in betas ❌ always fails"]
end
subgraph "Valid assertions also removed"
I["assert result['thinking']['type'] == 'enabled' ✓"]
J["assert result['thinking']['budget_tokens'] == MIN ✓"]
end
F --> H
B --> I
B --> J
Comments Outside Diff (1)
-
tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py, line 390-414 (link)Overcorrection drops valid coverage
The two failing lines (
betas = result.get(...)andassert "interleaved-thinking-2025-05-14" in betas) are provably dead for Bedrock, but the assertions above them — thatthinkingis auto-injected withtype == "enabled"andbudget_tokens == BEDROCK_MIN_THINKING_BUDGET_TOKENSwhenclear_thinking_20251015is present without an explicitthinkingparam — are valid and still pass. Removing the whole test leaves the auto-injection path completely uncovered; only the "already-enabled" path is tested by the sibling test.The minimal fix is to keep the test and trim just the two beta lines:
def test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_management(): """ Bedrock requires extended thinking when ``clear_thinking_20251015`` appears in ``context_management`` (Claude Code sends CM without ``thinking``). """ from litellm.constants import BEDROCK_MIN_THINKING_BUDGET_TOKENS from litellm.types.router import GenericLiteLLMParams cfg = AmazonAnthropicClaudeMessagesConfig() optional_params = { "max_tokens": 32000, "stream": False, "context_management": { "edits": [{"type": "clear_thinking_20251015", "keep": "all"}] }, } result = cfg.transform_anthropic_messages_request( model="global.anthropic.claude-sonnet-4-6-v1:0", messages=[{"role": "user", "content": "hi"}], anthropic_messages_optional_request_params=copy.deepcopy(optional_params), litellm_params=GenericLiteLLMParams(), headers={}, ) assert result["thinking"]["type"] == "enabled" assert result["thinking"]["budget_tokens"] == BEDROCK_MIN_THINKING_BUDGET_TOKENS # interleaved-thinking-2025-05-14 is filtered to null for Bedrock in # anthropic_beta_headers_config.json, so it is intentionally absent here. betas = result.get("anthropic_beta") or [] assert "interleaved-thinking-2025-05-14" not in betas
Rule Used: What: Flag any modifications to existing tests and... (source)
Reviews (1): Last reviewed commit: "[Test] Remove dead Bedrock clear_thinkin..." | Re-trigger Greptile
66f0d14
into
litellm_internal_staging
Relevant issues
Summary
Problem
test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_managementintests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.pyhas failed deterministically on every PR since it was introduced. Its final assertion:cannot hold against the current code:
transform_anthropic_messages_requestdoes addinterleaved-thinking-2025-05-14to the in-progress auto-beta set whenclear_thinking_20251015context management triggers a thinking injection (anthropic_claude3_transformation.py:540).filter_and_transform_beta_headers(beta_headers=list(beta_set - user_beta_set), provider="bedrock")is applied.anthropic_beta_headers_config.jsonmaps"interleaved-thinking-2025-05-14": nullunder thebedrockprovider, which means "drop this header".filter_and_transform_beta_headershonors that atlitellm/anthropic_beta_headers_manager.py:268-272.Auto-added betas (anything not in the caller-supplied
anthropic-betaheader) are subject to that filter, soresult["anthropic_beta"]never containsinterleaved-thinking-2025-05-14for a Bedrock request today.betasis always[]under this test's setup and the assertion always fails.The adjacent
test_bedrock_invoke_messages_skips_thinking_injection_when_already_enabled(same file, same modelglobal.anthropic.claude-sonnet-4-6-v1:0) already asserts"interleaved-thinking-2025-05-14" not in betasand carries a comment explaining that the beta "must not be attached" for Claude 4.6/4.7. The two tests contradict each other; the one being removed is the incorrect one.Fix
Delete the failing test and drop the now-unused
BEDROCK_MIN_THINKING_BUDGET_TOKENSimport. No production code changes. Coverage for the clear_thinking injection path is retained by the sibling test.If the product intent is to actually emit
interleaved-thinking-2025-05-14to Bedrock for pre-4.6 Claude 4 models, that is a separate change to bothanthropic_beta_headers_config.json(flipnull→ the header name) and whichever pre-4.6 model the new test should exercise. This PR does not take that position.Testing
uv run pytest tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py— 15 passed (was 15 passed + 1 failing).Type
✅ Test
Screenshots