Skip to content

Sanitize Responses message content for assistant history and images#7

Closed
Futureppo wants to merge 1 commit into
mainfrom
codex-86x45i
Closed

Sanitize Responses message content for assistant history and images#7
Futureppo wants to merge 1 commit into
mainfrom
codex-86x45i

Conversation

@Futureppo

Copy link
Copy Markdown
Owner

Summary

  • Normalize assistant message history content parts from output_text to upstream-compatible input_text.
  • Avoid adding an explicit content: null field when a message item has no content key.
  • Rewrite Anthropic-style message image blocks (type: image with source) to Responses-compatible input_image parts before forwarding upstream.
  • Add regression coverage for assistant output text, missing content, and Anthropic-style image content.

Testing

  • go test ./internal/openai ./internal/anthropic ./internal/server
  • go test ./...

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 message content sanitization for OpenAI-compatible responses, specifically converting assistant output_text to input_text and rewriting Anthropic-style image content (both URL and base64 sources) into standard input_image payloads. Feedback on the changes suggests validating that both data and media_type are non-empty when processing base64 image sources to prevent generating invalid data URLs.

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 on lines +246 to +247
case "base64":
url = "data:" + String(source, "media_type", "") + ";base64," + String(source, "data", "")

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

When source type is base64, if data or media_type is empty or missing, url will be constructed as an invalid data URL (e.g., "data:;base64,"), which is not empty and thus bypasses the url == "" check. This will result in sending an invalid image payload upstream. We should validate that both data and media_type are non-empty before constructing the data URL.

Suggested change
case "base64":
url = "data:" + String(source, "media_type", "") + ";base64," + String(source, "data", "")
case "base64":
data := String(source, "data", "")
mediaType := String(source, "media_type", "")
if data == "" || mediaType == "" {
return nil
}
url = "data:" + mediaType + ";base64," + data

@Futureppo Futureppo closed this Jul 13, 2026
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