fix(anthropic): fix clear_thinking retry body after thinking strip - #27514
fix(anthropic): fix clear_thinking retry body after thinking strip#27514mchtech wants to merge 1 commit into
Conversation
- restore top-level thinking when invalid-signature retry keeps clear_thinking_20251015 - keep the fix scoped to Anthropic Messages passthrough retry handling - avoid carrying manual budget_tokens into adaptive thinking retries - add behavior coverage for enabled, adaptive, disabled, missing, and non-adaptive cases
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR overrides
Confidence Score: 4/5The change is narrow and well-guarded: the restore only fires for adaptive-thinking models with a clear_thinking edit present, and the base-class strip still runs unconditionally before any restore attempt. The logic correctly handles all edge cases tested (enabled, adaptive without budget, disabled, missing, no clear-thinking edit, non-adaptive model). The not has_active_thinking guard will always be True in the primary retry path because the base class always removes thinking for invalid-signature errors, making it a purely defensive check. The call site discards the return value and relies on in-place mutation, which is consistent with the base class but is an implicit contract. No files require special attention; the transformation file is the only meaningful change and its scope is tightly controlled.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/messages/transformation.py | Adds transform_anthropic_messages_request_on_http_error override that restores top-level thinking config after the base class strips it, restricted to adaptive-thinking models with a clear_thinking edit present. |
| tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py | Adds five new mock-only tests and a shared helper covering all branch outcomes of the new retry transform: enabled/adaptive restore, disabled/missing no-restore, no-clear-thinking no-restore, and non-adaptive-model no-restore. |
Reviews (1): Last reviewed commit: "fix(anthropic): fix clear_thinking retry..." | Re-trigger Greptile
|
@mchtech — could you add a screenshot or short video showing that this change works as expected? It really helps reviewers verify the fix quickly. Thanks! |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |

Summary
clear_thinking_20251015budget_tokensinto adaptive thinking retriesFixes #27512
Related: #25867 added the same
clear_thinking_20251015request-contract guard for Bedrock. This PR covers the Anthropic Messages passthrough retry path, where the retry cleanup can remove top-levelthinkingwhile leavingclear_thinking_20251015in place.Tests
Result:
72 passed