feat(image-gen): support Codex image inputs (salvage #55828) - #57017
Merged
kshitijk4poor merged 3 commits intoJul 2, 2026
Merged
Conversation
… codex backend Replace the plugin-local _IMAGE_MAGIC_MIME table + _sniff_image_mime body with a delegation to agent.image_routing._sniff_mime_from_bytes, the canonical magic-byte sniffer already used across the codebase, then gate its result to the raster formats gpt-image-2's Responses input_image actually accepts (png/jpeg/gif/webp). The shared sniffer also recognizes SVG/TIFF/ICO; without the allowlist those would pass local validation and be rejected server-side with an opaque HTTP 400. Gating locally fails them cleanly as invalid_image_input. Adds a regression test for SVG rejection. Follow-up on top of @CrazyBoyM's NousResearch#55828.
kshitijk4poor
enabled auto-merge (rebase)
July 2, 2026 11:36
This was referenced Jul 2, 2026
This was referenced Aug 3, 2026
19 tasks
iainlane
added a commit
to iainlane/hermes-agent
that referenced
this pull request
Aug 15, 2026
The Codex backend grew its own source-image handling when image-to-image landed in NousResearch#57017, duplicating the read denylist and magic-byte validation the sanctioned resolver already enforces. It also carries two constraints the resolver can now express directly: gpt-image-2's input_image caps at 25MB and accepts raster PNG/JPEG/GIF/WEBP only, so a BMP or an oversized file has to fail locally rather than as an opaque HTTP 400. Replace _sniff_image_mime, _data_url_to_input_image_url and _local_image_to_data_url with one resolve_source_to_url_sync() call carrying the cap and the format allowlist. Public URLs pass through for the API to fetch; local files and data: URIs are re-encoded under the sniffed MIME, so a mislabelled header cannot reach the API claiming a type gpt-image-2 will reject. Neither constraint had test coverage before; both are now pinned at the resolver and through the provider.
iainlane
added a commit
to iainlane/hermes-agent
that referenced
this pull request
Aug 16, 2026
The Codex backend grew its own source-image handling when image-to-image landed in NousResearch#57017, duplicating the read denylist and magic-byte validation the sanctioned resolver already enforces. It also carries two constraints the resolver can now express directly: gpt-image-2's input_image caps at 25MB and accepts raster PNG/JPEG/GIF/WEBP only, so a BMP or an oversized file has to fail locally rather than as an opaque HTTP 400. Replace _sniff_image_mime, _data_url_to_input_image_url and _local_image_to_data_url with one resolve_source_to_url_sync() call carrying the cap and the format allowlist. Public URLs pass through for the API to fetch; local files and data: URIs are re-encoded under the sniffed MIME, so a mislabelled header cannot reach the API claiming a type gpt-image-2 will reject. Neither constraint had test coverage before; both are now pinned at the resolver and through the provider.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
openai-codex(Codex OAuth) image-gen backend can now do image-to-image / reference-image editing — it previously hard-rejected anyimage_url/reference_image_urlsand advertised text-only.Salvage of @CrazyBoyM's #55828 onto current
main, with one follow-up commit that reuses the shared magic-byte sniffer and gates it to the raster formats gpt-image-2 actually accepts.Changes
plugins/image_gen/openai-codex/__init__.py:image_url+reference_image_urls; attach them as Responsesinput_imagecontent parts alongside the prompt.normalize_reference_images(...), clamp to 16 (same cap as the API-key OpenAI path).agent.file_safetyread guard before inlining.modalities: ["text","image"]/max_reference_images: 16only now that the path is wired.agent.image_routing._sniff_mime_from_bytes(drops a duplicated format table) and gate the result topng/jpeg/gif/webp— the raster set gpt-image-2'sinput_imageaccepts — so SVG/TIFF/ICO fail locally with a clearinvalid_image_inputerror instead of an opaque server-side 400.tests/plugins/image_gen/test_openai_codex_provider.py: payload shape with source+reference images, capability metadata, non-image + SVG rejection, 16-image clamp.Validation
tests/plugins/image_gen/test_openai_codex_provider.py+ dispatchtests/plugins/image_gen/.txt/nonexistent/fake-magic-byte/SVG/TIFF rejectedinvalid_image_input; refs clamp 20→16; text-to-image regression clean;.env/auth.jsonblocked by read guard (no credential exfil)Fixes #21661.
Fixes #36737.
Closes #55828. Commits cherry-picked from @CrazyBoyM with authorship preserved.