Skip to content

fix handling of ResponseApplyPatchToolCall in completion bridge - #20913

Merged
13 commits merged into
BerriAI:litellm_oss_staging_02_18_2026from
jtsaw:fix/completion-bridge-apply-patch-tool-call
Feb 18, 2026
Merged

fix handling of ResponseApplyPatchToolCall in completion bridge#20913
13 commits merged into
BerriAI:litellm_oss_staging_02_18_2026from
jtsaw:fix/completion-bridge-apply-patch-tool-call

Conversation

@jtsaw

@jtsaw jtsaw commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #20905

CI failures seem unrelated to my changes..

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

@vercel

vercel Bot commented Feb 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 13, 2026 1:33am

Request Review

@jtsaw
jtsaw marked this pull request as ready for review February 11, 2026 01:56
@greptile-apps

greptile-apps Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Fixes a bug where litellm.completion() with a responses/ model prefix crashed when the model returned apply_patch_call output items (e.g., from GPT-5 Codex). The bridge now handles ResponseApplyPatchToolCall by converting it to a ChatCompletions-style tool call with name="apply_patch" and the file operation serialized as JSON in function.arguments.

  • Added ResponseApplyPatchToolCall handling in _convert_response_output_to_choices following the existing ResponseFunctionToolCall pattern
  • Added a regression test that verifies the tool call conversion end-to-end using mocks

Confidence Score: 4/5

  • This PR is safe to merge — it adds a new elif branch with no impact on existing code paths.
  • The change is a straightforward addition of a new elif branch in an existing type-dispatch chain. It follows the established pattern exactly, uses json.dumps (already imported), and the test is comprehensive and mock-only. The only reason this isn't a 5 is that the apply_patch function name is hardcoded rather than derived from the item type, which could diverge from OpenAI's naming if it changes — though this is a minor concern.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/completion_extras/litellm_responses_transformation/transformation.py Adds handling for ResponseApplyPatchToolCall in _convert_response_output_to_choices, converting it to a ChatCompletions-style tool call with name="apply_patch" and the operation serialized as JSON. Clean implementation following the existing pattern for ResponseFunctionToolCall. Minor whitespace cleanup.
tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py Adds a comprehensive regression test for the ResponseApplyPatchToolCall conversion. Uses only mocks — no real network calls. Verifies the tool call structure, operation serialization, and finish reason. Also includes minor whitespace normalization in existing tests.

@greptile-apps greptile-apps Bot 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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@yuneng-jiang

Copy link
Copy Markdown
Contributor

@Sameerlite can you take a look at this when you get a chance?

@Sameerlite Sameerlite 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.

nit

# The operation (create_file / update_file / delete_file) is
# serialised as JSON so it appears in function.arguments, just
# like any other tool call.
operation_dict = item.operation.model_dump()

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.

Add this in as a method in LiteLLMCompletionResponsesConfig and use it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed @Sameerlite

@ghost

ghost commented Feb 13, 2026

Copy link
Copy Markdown

@jtsaw can you fix the linting error?

@jtsaw
jtsaw force-pushed the fix/completion-bridge-apply-patch-tool-call branch from b111a4e to c7bc025 Compare February 13, 2026 00:56
@jtsaw

jtsaw commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

@jtsaw can you fix the linting error?

actually I'm not sure how to fix these lint errors...

  • the completion_extras/litellm_responses_transformation/transformation.py:230:9: PLR0915 Too many statements (60 > 50) seems to be in all new PRs and is unrelated to my changes
  • the proxy/_experimental/mcp_server/mcp_server_manager.py:34:31: F401 [*] litellm.constants.MCP_NPM_CACHE_DIR imported but unused is also unrelated since that file is not modified here.

@krrishdholakia

@ghost
ghost changed the base branch from main to litellm_oss_staging_02_18_2026 February 18, 2026 05:10
@ghost
ghost merged commit 8d5db4f into BerriAI:litellm_oss_staging_02_18_2026 Feb 18, 2026
5 of 18 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…iAI#20913)

* fix handling of ResponseApplyPatchToolCall in completion bridge

* refactor

* style: fix black formatting

* fix: clean up lint errors in test file (unused imports, print statements, formatting)

* refactor: extract _map_optional_params_to_responses_api to fix PLR0915

* what

* this linter cannot be me

* revert cause idk what's going on

* weird

* idk why this got removed

* revert more stuff

* revert pt 3
This pull request was closed.
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.

[Bug]: Responses-to-ChatCompletions bridge silently drops apply_patch_call output items

3 participants