Skip to content

Fix Responses assistant history content compatibility#6

Merged
Futureppo merged 2 commits into
mainfrom
codex
Jul 13, 2026
Merged

Fix Responses assistant history content compatibility#6
Futureppo merged 2 commits into
mainfrom
codex

Conversation

@Futureppo

Copy link
Copy Markdown
Owner

Motivation

  • Second-turn POST /v1/responses requests that included prior assistant messages with output_text content parts could be rejected by the upstream Grok CLI with a 422 deserialize error; the compatibility layer must normalize assistant message content to the upstream-expected shape.

Description

  • Normalize message content when preparing Responses requests by updating sanitizeInputItem to call sanitizeMessageContent, and implement sanitizeMessageContent to rewrite content parts with type == "output_text" to "input_text".
  • Add a regression test TestPrepareCompatibleResponsesRewritesAssistantOutputTextHistory to verify assistant history output_text parts are rewritten to input_text in PrepareCompatibleResponses.

Testing

  • Ran go test ./internal/openai ./internal/server and go test ./..., and all tests passed.

Codex Task

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/openai/responses_compat.go Outdated
Comment on lines +205 to +207
if String(out, "type", "") == "message" {
out["content"] = sanitizeMessageContent(out["content"])
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)
		}
	}

@Futureppo Futureppo merged commit 62a11f5 into main Jul 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant