fix(openai): normalize Anthropic content blocks in chat completions r… - #68
Merged
Merged
Conversation
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 08:34
aab475e to
2595ef7
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 08:34 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 08:50
2595ef7 to
72e11c7
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 08:50 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 09:26
72e11c7 to
7697da2
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 09:26 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 09:41
7697da2 to
c7dc851
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 09:41 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 09:43
c7dc851 to
9962676
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 09:43 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 10:20
9962676 to
ac6f698
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 10:20 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 20, 2026 12:33
ac6f698 to
a8b3d6c
Compare
guojn1
had a problem deploying
to
external_collaborator
September 20, 2026 12:33 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 21, 2026 01:58 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 21, 2026 01:59
ef5da2e to
a8b3d6c
Compare
guojn1
had a problem deploying
to
external_collaborator
September 21, 2026 01:59 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 22, 2026 12:56 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 22, 2026 13:12
fe32dd5 to
8ef7679
Compare
guojn1
had a problem deploying
to
external_collaborator
September 22, 2026 13:12 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 23, 2026 01:42
8ef7679 to
438b843
Compare
guojn1
had a problem deploying
to
external_collaborator
September 23, 2026 01:42 — with
GitHub Actions
Failure
…equests Gateway may forward Anthropic-format content blocks (thinking, tool_use) inside assistant message content arrays to the OpenAI /v1/chat/completions endpoint. The OpenAI deserializer only accepts text and refusal part types, causing a 400 error. Add middleware to convert Anthropic blocks before deserialization: thinking -> reasoning_content, tool_use -> tool_calls. Only touches assistant messages whose content array contains type=thinking or type=tool_use. Standard OpenAI requests pass through unchanged.
…blocks Address PR review findings on the Anthropic content-block compat middleware: - F1: reject cross combinations of partially-translated messages whose ordering cannot be proven: existing tool_calls with residual thinking, and existing reasoning_content with residual tool_use (unified into check_mixed_format_conflicts, replacing the R1/R2 pair) - F2: reject unknown/unsupported block types (e.g. server_tool_use) instead of silently dropping them when the content array is replaced - F3: require tool_use input to be present and an object; require string payloads for text/thinking/refusal blocks, with the block index reported in the error - F4: merge multiple refusal blocks with a newline instead of keeping only the last one - tests: 14 new unit tests for the converter and the conflict policy, plus 9 middleware integration tests against a live echo server (end-to-end conversion, pure-OpenAI passthrough, invalid-JSON passthrough, F1/F2/F3 rejections, idempotency, 413 body limit)
…ing it Review v4 R1 (P2): a non-null, non-array tool_calls value (object, string, number, bool) on an assistant message with residual Anthropic blocks was treated as 'no existing calls' by the mixed-format check, so the converted tool_calls insert silently deleted the original field — normalizing a gateway format error into a valid-looking request. Distinguish the structural type up front: missing/null/empty array means no existing calls, a non-empty array enters the conflict policy, anything else is rejected with 400 naming messages[i].tool_calls. Route regression tests: object/string/number/bool all return 400; null and empty array still convert; non-empty legal arrays keep the existing mixed-format conflict behavior.
…t converter - Reject text after tool_use: OpenAI content field cannot preserve post-call text ordering - Reject thinking after text before first tool_use: flat reasoning path would lose ordering - Stop swallowing serde_json::to_string errors on tool_use arguments - Remove user input (id/type) from error messages, use block index - rustfmt formatting pass
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 29, 2026 07:56
438b843 to
d0dc628
Compare
guojn1
had a problem deploying
to
external_collaborator
September 29, 2026 07:56 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 29, 2026 10:00 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 30, 2026 03:10 — with
GitHub Actions
Failure
guojn1
force-pushed
the
DingoRouter-base-1
branch
from
September 30, 2026 04:10
067cfdc to
bef1db8
Compare
guojn1
had a problem deploying
to
external_collaborator
September 30, 2026 04:10 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 30, 2026 06:31 — with
GitHub Actions
Failure
guojn1
had a problem deploying
to
external_collaborator
September 30, 2026 07:06 — with
GitHub Actions
Failure
githubgxll
approved these changes
Sep 30, 2026
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…equests
Gateway may forward Anthropic-format content blocks (thinking, tool_use) inside assistant message content arrays to the OpenAI /v1/chat/completions endpoint. The OpenAI deserializer only accepts text and refusal part types, causing a 400 error. Add middleware to convert Anthropic blocks before deserialization: thinking -> reasoning_content, tool_use -> tool_calls.
Only touches assistant messages whose content array contains type=thinking or type=tool_use. Standard OpenAI requests pass through unchanged.
Overview:
Details:
Where should the reviewer start?
Related Issues
🔗 This PR is linked to an issue:
🚫 This PR is NOT linked to an issue: