Skip to content

fix(responses): report truncation and normalize the translated output shape - #955

Merged
SantiagoDePolonia merged 3 commits into
mainfrom
fix/responses-output-shape
Sep 12, 2026
Merged

SantiagoDePolonia merged 3 commits into
mainfrom
fix/responses-output-shape

Conversation

@SantiagoDePolonia

Copy link
Copy Markdown
Contributor

Three /v1/responses output-shape gaps, all visible on translated (non-native-OpenAI) providers.

Truncation is reported. A turn stopped by max_output_tokens (or a content filter) now returns status: "incomplete" with incomplete_details.reason, and the message item carries status: "incomplete" — chat-translated providers (gemini, groq, deepseek, …) and Anthropic, in both stream and non-stream. core.ResponsesResponse gained the typed incomplete_details field, so native OpenAI's value is no longer dropped either (it previously returned status: "incomplete" with no details).

Empty answers keep text. output_text parts always serialize text, which the OpenAI schema requires; an empty assistant answer used to emit {"type":"output_text","annotations":[]}. The streamed path already did this.

Usage is normalized. The Responses usage object now carries only the OpenAI shape (input_tokens/output_tokens/total_tokens plus *_tokens_details), instead of leaking provider members such as thoughts_token_count, completion_reasoning_tokens or completion_time. Nothing with an OpenAI-shaped home is lost: reasoning tokens stay under output_tokens_details, cached tokens under input_tokens_details (Anthropic's Responses usage now fills both). Provider extras remain in RawUsage, which feeds usage records and cost calculation, and the Anthropic streamed usage payload keeps its cache counts because stream costs are read back from it.

Provider notes: gemini 2.5 flash can return a completely empty stream (no chunk, no finish_reason, no usage) when the whole budget goes to thinking — nothing to map there; that stream still ends completed.

Tested: unit tests for each path (internal/core, internal/providers, internal/providers/anthropic), go test ./... (pre-existing failures only: dashboard assets, a midnight-boundary version-cookie test), make lint clean, API docs regenerated. Live gateway run against anthropic/gemini/groq/openai with max_output_tokens=16, stream and non-stream: all four now report incomplete + max_output_tokens, usage normalized, empty answer serializes "text": "".

… shape

Truncated turns now return status "incomplete" with incomplete_details on chat-translated and Anthropic providers (stream and non-stream), and native OpenAI's incomplete_details is no longer dropped. Empty answers keep the required output_text "text" member, and the Responses usage object stays in the OpenAI shape; provider extras remain in usage records and cost calculation.
@mintlify

mintlify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
gomodel 🟢 Ready View Preview Sep 11, 2026, 10:33 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 05964dd8-fcfe-4881-bc76-76a80736462c

📥 Commits

Reviewing files that changed from the base of the PR and between 1d4ae81 and c5b7a60.

📒 Files selected for processing (17)
  • cmd/gomodel/docs/docs.go
  • docs/openapi.json
  • internal/core/responses.go
  • internal/core/responses_incomplete_test.go
  • internal/core/responses_json.go
  • internal/core/usage_json.go
  • internal/core/usage_json_test.go
  • internal/providers/anthropic/responses.go
  • internal/providers/anthropic/responses_status_test.go
  • internal/providers/responses_converter.go
  • internal/providers/responses_output.go
  • internal/providers/responses_status_test.go
  • internal/providers/responses_stream_status_test.go
  • internal/usage/cached_responses_test.go
  • internal/usage/cost.go
  • tests/contract/testdata/golden/groq/responses.golden.json
  • tests/contract/testdata/golden/xai/responses.golden.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Sep 11, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.29630% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/responses_converter.go 90.90% 1 Missing ⚠️
internal/providers/responses_output.go 94.44% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

Safe to merge.

Reviews (2) · Last reviewed commit: "fix(usage): price Anthropic cache reads ..."

Comment thread internal/core/usage_json.go
@SantiagoDePolonia
SantiagoDePolonia merged commit 071fb8e into main Sep 12, 2026
19 checks passed
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.

2 participants