Skip to content

fix(utils): keep nested thinking when dropping top-level thinking - #37624

Closed
xiehuanyi wants to merge 5 commits into
BerriAI:mainfrom
xiehuanyi:bugfix/drop-params-message-thinking
Closed

xiehuanyi wants to merge 5 commits into
BerriAI:mainfrom
xiehuanyi:bugfix/drop-params-message-thinking

Conversation

@xiehuanyi

@xiehuanyi xiehuanyi commented Aug 20, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • Bare drops can corrupt reasoning history during fallback

How it solves it:

  • Drop request keys without traversing nested conversation content

Explicit nested paths keep their existing deletion behavior. The shared helper uses read-only Mapping and Sequence interfaces and builds each result without rebinding mutable accumulators. Both optional-parameter processing and the Anthropic Messages handler use it

User Flow

Before: reasoning history can lose fields when a fallback drops unsupported parameters

  1. Configure a fallback with additional_drop_params: ["thinking"]
  2. Send a conversation containing earlier thinking blocks
  3. The provider rejects history whose thinking fields were removed

After: dropping a request option preserves reasoning history

  1. Configure the same fallback with additional_drop_params: ["thinking"]
  2. Send the same conversation containing earlier thinking blocks
  3. The request option is removed while the historical thinking fields remain

Relevant issues

Fixes #37479

Validation

The branch now includes the upstream trace-contract correction for agent names and framework fields. The current required checks pass, and rust-test now passes. The optional OSV scan still reports an existing development dependency advisory

220 Python tests pass across the nested-drop and HTTP-handler files. All 114 tests in the Rust traces crate also pass, including the result-contract case that failed in the previous CI run. The repository make check passes, including formatting, Ruff, strict-rule budgets, type discipline, test quality, type checking, circular imports, and import safety. Disabling bare-key deletion makes two focused regression cases fail

Pre-Submission checklist

  • Meaningful regression tests included
  • Affected tests and local pre-commit checks pass
  • Current-head required CI checks complete
  • Current-head Greptile confidence is at least 4/5

Type

Bug Fix

Caveats

Low

  • Live provider fallback behavior has not been exercised

High

  • Optional OSV check reports existing braces 3.0.3 vulnerability

The dependency manifests match main. The scanner reports no fixed version for GHSA-vfj7-8cjw-p6xm. OSV is outside main's required status checks, and #44347 tracks the repository-wide exception

Bare additional_drop_params keys should only remove request-level
params. Conversation history and tool payloads that reuse the same
field name must stay intact so Anthropic fallback routing does not 400.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 20, 2026 11:03
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR changes additional parameter dropping so bare names remove only top-level request fields while explicit nested paths retain their existing behavior

  • Adds a shared helper that protects conversation payloads during bare drops
  • Uses the helper in optional-parameter processing and the Anthropic Messages HTTP path
  • Adds regression coverage for thinking blocks, tool fields, and explicit nested paths

Confidence Score: 4/5

The PR appears safe to merge after addressing the non-blocking payload typing issue

The request transformation preserves conversation thinking fields while retaining explicit nested deletion, with no blocking behavioral or security failure established

Files Needing Attention: litellm/litellm_core_utils/dot_notation_indexing.py, tests/test_litellm/test_nested_drop_params.py

Important Files Changed

Filename Overview
litellm/litellm_core_utils/dot_notation_indexing.py Adds the shared top-level-aware drop helper; behavior is focused, but its coarse payload typing violates repository conventions
litellm/utils.py Replaces nested-only deletion with the shared helper after provider parameter mapping
litellm/llms/custom_httpx/llm_http_handler.py Applies the shared helper before transforming Anthropic Messages requests
litellm/_lazy_imports_registry.py Registers the new helper for lazy access through litellm.utils
tests/test_litellm/test_nested_drop_params.py Adds focused regression cases, with one newly introduced unparameterized dict annotation
tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py Extends handler coverage to verify conversation-history thinking content survives top-level drops

Reviews (1): Last reviewed commit: "fix(utils): keep nested thinking when dr..." | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes additional_drop_params so dropping a bare key like thinking only removes the top-level request parameter, without corrupting conversation-history content blocks used by Anthropic fallbacks

Changes:

  • Introduces apply_additional_drop_params() to scope bare-key drops to the top-level request while still honoring explicit nested JSONPath drops
  • Wires the new drop behavior into optional params handling and the Anthropic Messages HTTP handler
  • Adds regression tests covering message-history thinking blocks, tool fields named thinking, and explicit nested drops

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_litellm/test_nested_drop_params.py Adds focused regression tests ensuring bare drops do not strip messages[].content[].thinking
tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py Extends Anthropic Messages handler regression to verify history thinking blocks survive bare drops
litellm/utils.py Switches additional drop handling to apply_additional_drop_params() for consistent bare and nested behavior
litellm/llms/custom_httpx/llm_http_handler.py Applies apply_additional_drop_params() before Anthropic provider transform runs
litellm/litellm_core_utils/dot_notation_indexing.py Implements apply_additional_drop_params() with special handling for conversation payload keys
litellm/_lazy_imports_registry.py Registers apply_additional_drop_params for lazy import resolution

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread litellm/utils.py Resolved
The helper is loaded through the lazy getattr path, so the
TYPE_CHECKING name was an F401 that blew the strict-rule budget.

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing xiehuanyi:bugfix/drop-params-message-thinking (5144d8b) with main (cb00dbe)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (09313bc) during the generation of this report, so cb00dbe was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:43
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:01
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 15:01
@xiehuanyi xiehuanyi closed this Oct 6, 2026
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.

additional_drop_params strips fields from message content blocks, not just top-level request params

4 participants