Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a sanitization step for input messages in the OpenAI compatibility layer, rewriting output_text content types to input_text, and adds a corresponding unit test. The review feedback correctly identifies a potential issue where messages lacking a content field (e.g., those with only tool calls) would have content: null explicitly set, potentially causing serialization or validation errors. A code suggestion is provided to only sanitize and assign content if it is present and non-nil.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if String(out, "type", "") == "message" { | ||
| out["content"] = sanitizeMessageContent(out["content"]) | ||
| } |
There was a problem hiding this comment.
If the content key is not present in the message (for example, an assistant message that only contains tool_calls), calling sanitizeMessageContent(out["content"]) will return nil, and assigning it back to out["content"] will explicitly insert "content": nil into the map. This can cause serialization issues or upstream validation errors (e.g., if the upstream schema does not allow null for content or expects it to be omitted).
We should only sanitize and assign content if it is actually present and not nil.
if String(out, "type", "") == "message" {
if content, ok := out["content"]; ok && content != nil {
out["content"] = sanitizeMessageContent(content)
}
}
Motivation
POST /v1/responsesrequests that included prior assistant messages withoutput_textcontent parts could be rejected by the upstream Grok CLI with a422deserialize error; the compatibility layer must normalize assistant message content to the upstream-expected shape.Description
sanitizeInputItemto callsanitizeMessageContent, and implementsanitizeMessageContentto rewrite content parts withtype == "output_text"to"input_text".TestPrepareCompatibleResponsesRewritesAssistantOutputTextHistoryto verify assistant historyoutput_textparts are rewritten toinput_textinPrepareCompatibleResponses.Testing
go test ./internal/openai ./internal/serverandgo test ./..., and all tests passed.Codex Task