Skip to content

fix(responses): report why a bridged response is incomplete - #40833

Closed
shoutoutuoadi325 wants to merge 2 commits into
BerriAI:mainfrom
shoutoutuoadi325:fix/responses-incomplete-details-reason
Closed

shoutoutuoadi325 wants to merge 2 commits into
BerriAI:mainfrom
shoutoutuoadi325:fix/responses-incomplete-details-reason

Conversation

@shoutoutuoadi325

@shoutoutuoadi325 shoutoutuoadi325 commented Sep 12, 2026 •

Copy link
Copy Markdown

TLDR

Problem this solves:

  • /v1/responses through the chat-completions bridge returns status incomplete with incomplete_details null
  • clients read incomplete_details.reason to tell truncation apart from filtering
  • both streaming and non-streaming responses hid the reason

How it solves it:

  • map finish_reason length/content_filter to the matching reason
  • refusal gets a null-reason object since the enum has no entry for it
  • streaming response.completed picks this up from the same transform

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

  1. They send POST https://litellm-domain/v1/responses with input "List the three laws of robotics" and max_output_tokens: 8
  2. The model stops at the token limit and the response arrives with "status": "incomplete"
  3. Their retry logic reads response.incomplete_details.reason to decide whether to re-run with a bigger budget; it reads null and falls into the unknown-reason branch
  4. With stream: true, the response.completed snapshot carries the same null

After: the same request says why it stopped

  1. They send the same POST https://litellm-domain/v1/responses with input "List the three laws of robotics" and max_output_tokens: 8
  2. The response arrives with "status": "incomplete" and "incomplete_details": {"reason": "max_output_tokens"}
  3. Their retry logic sees max_output_tokens and re-runs with a bigger budget
  4. With stream: true, response.completed carries the same reason

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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)

  1. python client.py
  2. stream=False status=incomplete incomplete_details=null
  3. stream=True status=incomplete incomplete_details=null

After (e087174)

  1. python client.py
  2. stream=False status=incomplete incomplete_details={"reason": "max_output_tokens"}
  3. stream=True status=incomplete incomplete_details={"reason": "max_output_tokens"}

Type

🐛 Bug Fix

Caveats (if any)

Low

  • refusal carries a null reason: the Responses API reason enum only has max_output_tokens and content_filter

Copilot AI lite review requested due to automatic review settings September 12, 2026 02:42
@CLAassistant

CLAassistant commented Sep 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves the chat-completions-to-Responses bridge by reporting why a response is incomplete.

  • Maps length to max_output_tokens and content_filter to content_filter.
  • Represents an unnormalized refusal with an incomplete-details object whose reason is null.
  • Adds non-streaming and streaming regression coverage.
  • Removes the explanatory source comment identified in the previous review.

Confidence Score: 5/5

The 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.

Important Files Changed

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

Comment on lines +2139 to +2151
"""
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
"""

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.

P2 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!

@codspeed

codspeed Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing shoutoutuoadi325:fix/responses-incomplete-details-reason (59df95c) with litellm_internal_staging (67dd150)

Open in CodSpeed

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.

🟡 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.completed snapshots.
  • 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_reason here: Choices converts refusal to content_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.

Comment on lines +2156 to +2157
if finish_reason == "refusal":
return IncompleteDetails(reason=None)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +2139 to +2141
"""
Map chat completion finish_reason to the incomplete_details object that
accompanies an "incomplete" status.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +2154 to +2155
if finish_reason == "content_filter":
return IncompleteDetails(reason="content_filter")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve refusal instead of labeling it content-filtered

For provider finish_reason="refusal", Choices normalizes it to content_filter before this helper, so the response incorrectly reports filtering instead of a null reason

Useful? React with 👍 / 👎.

@shoutoutuoadi325
shoutoutuoadi325 force-pushed the fix/responses-incomplete-details-reason branch from fd820c8 to 1b29f53 Compare September 12, 2026 02:54
@shoutoutuoadi325
shoutoutuoadi325 changed the base branch from main to litellm_internal_staging September 12, 2026 02:54
@shoutoutuoadi325
shoutoutuoadi325 requested a review from a team September 12, 2026 02:54
@codecov

codecov Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

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.
@shoutoutuoadi325
shoutoutuoadi325 force-pushed the fix/responses-incomplete-details-reason branch from 1b29f53 to e087174 Compare September 12, 2026 03:15
@shoutoutuoadi325

Copy link
Copy Markdown
Author

@greptileai

@shoutoutuoadi325

Copy link
Copy Markdown
Author

@greptileai

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:52
@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 14:35
@mateo-berri

Copy link
Copy Markdown
Contributor

Thanks for this. Main already reports incomplete_details on bridged responses since #41892 and #44460, streaming included, so I'm closing this as superseded

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.

5 participants