Skip to content

fix(apicompat): scope additional tools parsing#4341

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
wp-a:codex/additional-tools-discriminator
Jul 15, 2026
Merged

fix(apicompat): scope additional tools parsing#4341
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
wp-a:codex/additional-tools-discriminator

Conversation

@wp-a

@wp-a wp-a commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Restrict tools decoding in Responses input items to objects whose type is actually additional_tools.

Problem

EffectiveResponsesTools scans the Responses input array for Codex additional_tools items. A normal message object can legally contain unrelated extension fields. If such an object contains a non-array field named tools, the current scanner tries to decode it as []ResponsesTool before 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 of tools even for objects that were not additional_tools items.

Fix

  • Decode only the type discriminator first.
  • Skip non-additional_tools objects before touching their tools field.
  • Decode and validate tools only for actual additional_tools items.

Malformed tools on a real additional_tools item still returns the existing contextual error. No request conversion refactor is included.

Verification

  • Confirmed the non-target-item regression test fails on the base revision with cannot unmarshal string into ... []apicompat.ResponsesTool.
  • Added the complementary assertion that malformed actual additional_tools items are still rejected.
  • go test ./internal/pkg/apicompat -run 'TestEffectiveResponsesTools_(IgnoresMalformedToolsOnNonAdditionalItem|RejectsMalformedAdditionalTools)' -count=1
  • go test ./internal/pkg/apicompat -count=1
  • go test ./... -count=1
  • go vet ./...
  • git diff --check upstream/main..HEAD

@wp-a
wp-a marked this pull request as ready for review July 15, 2026 06:45
@Wei-Shaw
Wei-Shaw merged commit 80560e4 into Wei-Shaw:main Jul 15, 2026
8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants