fix(apicompat): scope additional tools parsing#4341
Merged
Wei-Shaw merged 1 commit intoJul 15, 2026
Conversation
wp-a
marked this pull request as ready for review
July 15, 2026 06:45
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Restrict
toolsdecoding in Responses input items to objects whose type is actuallyadditional_tools.Problem
EffectiveResponsesToolsscans the Responses input array for Codexadditional_toolsitems. A normal message object can legally contain unrelated extension fields. If such an object contains a non-array field namedtools, the current scanner tries to decode it as[]ResponsesToolbefore checking the item type and rejects the entire request.Root cause
Each object was decoded into a combined
{type, tools}structure in one pass. JSON decoding therefore validated the shape oftoolseven for objects that were notadditional_toolsitems.Fix
typediscriminator first.additional_toolsobjects before touching theirtoolsfield.toolsonly for actualadditional_toolsitems.Malformed
toolson a realadditional_toolsitem still returns the existing contextual error. No request conversion refactor is included.Verification
cannot unmarshal string into ... []apicompat.ResponsesTool.additional_toolsitems are still rejected.go test ./internal/pkg/apicompat -run 'TestEffectiveResponsesTools_(IgnoresMalformedToolsOnNonAdditionalItem|RejectsMalformedAdditionalTools)' -count=1go test ./internal/pkg/apicompat -count=1go test ./... -count=1go vet ./...git diff --check upstream/main..HEAD