Skip to content

verify mime type of images - #5888

Merged
zhao-oai merged 5 commits into
mainfrom
verify-mime-type
Oct 28, 2025
Merged

zhao-oai merged 5 commits into
mainfrom
verify-mime-type

Conversation

@zhao-oai

@zhao-oai zhao-oai commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor

solves: #5675

Block non-image uploads in the view_image workflow. We now confirm the file’s MIME is image/* before building the data URL; otherwise we emit a “unsupported MIME type” error to the model. This stops the agent from sending application/json blobs that the Responses API rejects with 400s.

Screenshot 2025-10-28 at 1 15 10 PM

@pakrym-oai pakrym-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add an integration test

@zhao-oai
zhao-oai enabled auto-merge (squash) October 28, 2025 20:21
@zhao-oai
zhao-oai disabled auto-merge October 28, 2025 20:35
Comment thread codex-rs/core/tests/suite/view_image.rs Resolved

let output_item = mock.single_request().function_call_output(call_id);
let output_text = extract_output_text(&output_item).expect("output text present");
assert_eq!(output_text, "attached local image path");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that's actually not very good. It might be better to respond with error directly as function output instead of separate item but you are not the one that wrote the logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@codex could you take a stab at this

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +401 to +403
let output_item = mock.single_request().function_call_output(call_id);
let output_text = extract_output_text(&output_item).expect("output text present");
assert_eq!(output_text, "attached local image path");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Surface MIME rejection as tool failure

Here we now assert that function_call_output is still "attached local image path" even when the local file was rejected for having a non‑image MIME type. That keeps the view_image handler returning success: true and the usual success string, even though the pending input we send back no longer contains any input_image. The only hint is the placeholder text we injected as a user message, which isn’t structurally tied to the tool call and can be ignored by downstream consumers. All of the other failure paths for this tool (missing file, path is directory, etc.) surface their errors via FunctionCallError::RespondToModel, so orchestration, telemetry, and the model can reliably tell the call failed. With this change MIME failures become silent: the agent continues as if the screenshot is attached while the Responses API request contains no image. We should instead propagate the MIME error through the tool’s function output (success: Some(false) plus the error message) so callers can react, rather than asserting success here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

strange. why did my ping get classified as a review request lol

@zhao-oai
zhao-oai merged commit 3611350 into main Oct 28, 2025
@zhao-oai
zhao-oai deleted the verify-mime-type branch October 28, 2025 21:52
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 28, 2025
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.

3 participants