Skip to content

Preserve nullable response metadata and tool output fields - #202

Open
memoryttt wants to merge 1 commit into
jamesrochabrun:mainfrom
memoryttt:codex/fix-response-output-fields
Open

memoryttt wants to merge 1 commit into
jamesrochabrun:mainfrom
memoryttt:codex/fix-response-output-fields

Conversation

@memoryttt

Copy link
Copy Markdown

Responses with metadata set to null currently fail to decode because ResponseModel requires a non-optional dictionary. Web search actions decode into an empty struct, silently discarding their query/queries, and image generation results discard output_format. These fields are present in the official Responses schema.

Make metadata optional and expose the documented web-search action fields (type, query, queries, url and pattern) and image outputFormat. Both full responses and streaming output items use these models. Other required ResponseModel fields remain required, and invalid types in the newly exposed fields remain decoding errors.

Source compatibility: ResponseModel.metadata changes from [String: String] to [String: String]?. Callers that access the dictionary directly must use optional chaining or explicitly fall back to an empty dictionary. An existing test now asserts that a supplied empty dictionary remains empty rather than treating it as null.

Validation:

  • Against unmodified 4.6.2 (c757e0b), a response with metadata:null failed with DecodingError.valueNotFound; reflection confirmed that decoded search queries and image output format were discarded.
  • All 101 existing XCTest tests and 7 new Swift Testing methods pass. The final tests use typed property assertions and cover search/page/find actions, streaming output items, png/jpeg/webp, absent/null optional fields, malformed field types, and each of the other required response fields.
  • Full repository SwiftFormat lint and the iOS 18 simulator SDK build pass. The new Swift Testing file is guarded for Swift 6, retaining older compiler support for the existing suite.

Schema references:

Fixtures are synthetic and require no credentials. This does not relax parallel_tool_calls, invent defaults for sparse failed responses, or change unknown-tool decoding policy.

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.

1 participant