Repository navigation
fix(responses): report why a bridged response is incomplete - #40833
shoutoutuoadi325 wants to merge 2 commits into
Conversation
Greptile SummaryThis PR improves the chat-completions-to-Responses bridge by reporting why a response is incomplete.
Confidence Score: 5/5The PR appears safe to merge, with the previous repository-style violation now fully addressed and no new actionable issues identified. The latest revision only removes the explanatory comment flagged previously; the finish-reason mapping and its streaming and non-streaming tests remain intact.
|
| Filename | Overview |
|---|---|
| litellm/responses/litellm_completion_transformation/transformation.py | Maps chat-completion finish reasons into Responses API incomplete details; the latest change removes the previously flagged explanatory comment. |
| tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py | Adds coverage for completed, truncated, filtered, and refusal response transformations. |
| tests/test_litellm/responses/litellm_completion_transformation/test_streaming_iterator_transformation.py | Verifies that a truncated stream’s completed event includes the max-output-tokens reason. |
Reviews (3): Last reviewed commit: "fix(responses): remove leftover inline c..." | Re-trigger Greptile
| """ | ||
| Map chat completion finish_reason to the incomplete_details object that | ||
| accompanies an "incomplete" status. | ||
|
|
||
| "refusal" maps to an incomplete status but has no matching reason in the | ||
| Responses API enum, so it gets a null reason rather than no object at all. | ||
|
|
||
| Args: | ||
| finish_reason: The finish_reason from a chat completion response | ||
|
|
||
| Returns: | ||
| IncompleteDetails for finish reasons that map to "incomplete", None otherwise | ||
| """ |
There was a problem hiding this comment.
Unnecessary explanatory comments
This straightforward mapping and its tests add explanatory docstrings, violating the repository’s no-comments requirement. Remove them before merging
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
🟡 Changes recommended
The refusal mapping uses the wrong finish-reason source, and its expected null reason lacks test coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR fixes incomplete-reason reporting in the chat-completions-to-Responses bridge for streaming and non-streaming responses.
Changes:
- Maps finish reasons to
incomplete_details.reason. - Applies mappings to streamed
response.completedsnapshots. - Adds regression tests.
File summaries
| File | Summary | Review notes |
|---|---|---|
tests/test_litellm/responses/litellm_completion_transformation/test_streaming_iterator_transformation.py |
Tests streamed completion details. | — |
tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py |
Tests non-streaming reason mappings. | — |
litellm/responses/litellm_completion_transformation/transformation.py |
Adds incomplete-reason mapping. | Moderate (1 vote): use native_finish_reason for refusal handling. Nit (2 votes): add an assertion for refusal with a null reason. |
Review details
Suppressed comments (1)
litellm/responses/litellm_completion_transformation/transformation.py:2284
- Use
native_finish_reasonhere:Choicesconvertsrefusaltocontent_filter, so this call returns the wrong non-null reason; add a regression assertion
incomplete_details=LiteLLMCompletionResponsesConfig._map_chat_completion_finish_reason_to_incomplete_details(
finish_reason
),
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if finish_reason == "refusal": | ||
| return IncompleteDetails(reason=None) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd820c852d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| """ | ||
| Map chat completion finish_reason to the incomplete_details object that | ||
| accompanies an "incomplete" status. |
There was a problem hiding this comment.
Remove the prohibited explanatory docstrings
This mapping and the new tests are clear from their code, so these explanatory docstrings violate the repository's no-comments guideline; remove them
AGENTS.md reference: AGENTS.md:L1-L1
Useful? React with 👍 / 👎.
| if finish_reason == "content_filter": | ||
| return IncompleteDetails(reason="content_filter") |
fd820c8 to
1b29f53
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
A /v1/responses request served through the chat-completions bridge came back with status incomplete but incomplete_details null whenever the provider hit its token limit or filtered the output. OpenAI pairs every incomplete status with a reason, so the null left the bridge's truncations unexplained. Map the finish_reason to that reason: length to max_output_tokens, content_filter to content_filter, refusal to a null reason since the Responses API enum has no entry for it. The streaming response.completed event goes through the same transform as the non-streaming response, so both surfaces pick this up from the one change.
1b29f53 to
e087174
Compare
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer using the OpenAI SDK against the gateway's /v1/responses for a model the gateway serves over a chat-completions backend gets truncation with no explanation
After: the same request says why it stopped
Relevant issues
Self-contained. Noticed while reading the bridge after #37710 fixed the same gap in the other direction (responses-native → chat completions).
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Shared setup: a one-file OpenAI-compatible server on 127.0.0.1:8123 whose POST /v1/chat/completions always finishes with finish_reason "length" (streaming sends the same finish_reason in the last chunk); the client calls
litellm.aresponses(model="openai/gpt-4o", use_chat_completions_api=True, api_base="http://127.0.0.1:8123/v1", ...)twice, once non-streaming and once streaming, and prints status and incomplete_details. Real HTTP end to end, no mocks.Before (13df85c)
python client.pystream=False status=incomplete incomplete_details=nullstream=True status=incomplete incomplete_details=nullAfter (e087174)
python client.pystream=False status=incomplete incomplete_details={"reason": "max_output_tokens"}stream=True status=incomplete incomplete_details={"reason": "max_output_tokens"}Type
🐛 Bug Fix
Caveats (if any)
Low