fix: validate Leonardo downloads and preserve image formats - #2344
Open
gargsajal9 wants to merge 1 commit into
Open
gargsajal9 wants to merge 1 commit into
gargsajal9 wants to merge 1 commit into
Conversation
Reject failed image downloads and unrecognized nonimage payloads. Preserve native response bytes while deriving artifact format and MIME metadata from the existing core helper. Add deterministic driver, tool, task-memory, and file-save regressions with real PNG/JPEG decoding and blocked provider network access. Related to griptape-ai#1901; the original reported incident remains unconfirmed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Describe your changes
Leonardo image downloads were returned without checking their HTTP status, and both generation paths labeled every payload as PNG. Deterministic regressions demonstrate that HTTP error bodies could become image artifacts and real JPEG bytes received incorrect format/MIME metadata.
This change:
raise_for_status()before consuming a downloaded response.get_mime_type(bytes)helper to detect the native image subtype and explicitly reject unrecognized/nonimage bodies.PromptImageGenerationTool, including real PNG/JPEG decoding and artifact → task memory →FileManagerTool→ temporary-file persistence. Tool dependency installation is explicitly disabled.Validation
All provider HTTP is mocked; no live Leonardo/OpenAI/model API or real Agent/ComfyUI run was performed. Signature detection is not full corruption validation. Explicitly saving JPEG bytes as
dog.pngdoes not convert them to PNG.Prepared with GitHub Copilot assistance, attributed in the commit trailer.
Issue ticket number and link
Related to #1901 — #1901
The reporter's original incident is not confirmed reproduced or resolved: no failing output, download response, or save-activity trace is available. This PR addresses the demonstrated local driver defects without asserting that they caused that incident.