Skip to content

[Test] Remove dead Bedrock clear_thinking interleaved-thinking-beta assertion#25913

Merged
yuneng-berri merged 1 commit intolitellm_internal_stagingfrom
litellm_dropDeadBedrockThinkingBetaTest
Apr 16, 2026
Merged

[Test] Remove dead Bedrock clear_thinking interleaved-thinking-beta assertion#25913
yuneng-berri merged 1 commit intolitellm_internal_stagingfrom
litellm_dropDeadBedrockThinkingBetaTest

Conversation

@yuneng-berri
Copy link
Copy Markdown
Collaborator

Relevant issues

Summary

Problem

test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_management in tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py has failed deterministically on every PR since it was introduced. Its final assertion:

betas = result.get("anthropic_beta") or []
assert "interleaved-thinking-2025-05-14" in betas

cannot hold against the current code:

  1. transform_anthropic_messages_request does add interleaved-thinking-2025-05-14 to the in-progress auto-beta set when clear_thinking_20251015 context management triggers a thinking injection (anthropic_claude3_transformation.py:540).
  2. Immediately after, filter_and_transform_beta_headers(beta_headers=list(beta_set - user_beta_set), provider="bedrock") is applied.
  3. anthropic_beta_headers_config.json maps "interleaved-thinking-2025-05-14": null under the bedrock provider, which means "drop this header". filter_and_transform_beta_headers honors that at litellm/anthropic_beta_headers_manager.py:268-272.

Auto-added betas (anything not in the caller-supplied anthropic-beta header) are subject to that filter, so result["anthropic_beta"] never contains interleaved-thinking-2025-05-14 for a Bedrock request today. betas is 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 model global.anthropic.claude-sonnet-4-6-v1:0) already asserts "interleaved-thinking-2025-05-14" not in betas and 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_TOKENS import. 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-14 to Bedrock for pre-4.6 Claude 4 models, that is a separate change to both anthropic_beta_headers_config.json (flip null → 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

…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.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 16, 2026 9:47pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR removes test_bedrock_invoke_messages_injects_thinking_for_clear_thinking_context_management and its associated BEDROCK_MIN_THINKING_BUDGET_TOKENS import from the Bedrock Claude 3 transformation test file. The test's final assertion ("interleaved-thinking-2025-05-14" in betas) always fails because filter_and_transform_beta_headers drops that beta header for Bedrock (it maps to null in anthropic_beta_headers_config.json), making the test permanently broken. The PR description and diff are accurate, but the fix overcorrects by removing the entire test instead of just the two failing beta lines — leaving the clear_thinking auto-injection path (thinking type and budget_tokens) uncovered.

Confidence Score: 4/5

Safe 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

Important Files Changed

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
Loading

Comments Outside Diff (1)

  1. tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py, line 390-414 (link)

    P2 Overcorrection drops valid coverage

    The two failing lines (betas = result.get(...) and assert "interleaved-thinking-2025-05-14" in betas) are provably dead for Bedrock, but the assertions above them — that thinking is auto-injected with type == "enabled" and budget_tokens == BEDROCK_MIN_THINKING_BUDGET_TOKENS when clear_thinking_20251015 is present without an explicit thinking param — 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

@yuneng-berri yuneng-berri merged commit 66f0d14 into litellm_internal_staging Apr 16, 2026
96 of 100 checks passed
@yuneng-berri yuneng-berri deleted the litellm_dropDeadBedrockThinkingBetaTest branch April 16, 2026 22:38
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.

2 participants