Skip to content

fix: validate Leonardo downloads and preserve image formats - #2344

Open
gargsajal9 wants to merge 1 commit into
griptape-ai:mainfrom
gargsajal9:gargsajal9-leonardo-fix-and-e2e
Open

gargsajal9 wants to merge 1 commit into
griptape-ai:mainfrom
gargsajal9:gargsajal9-leonardo-fix-and-e2e

Conversation

@gargsajal9

Copy link
Copy Markdown

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:

  • Calls raise_for_status() before consuming a downloaded response.
  • Shares artifact construction between text-to-image and image variation, using the existing core get_mime_type(bytes) helper to detect the native image subtype and explicitly reject unrecognized/nonimage bodies.
  • Preserves the original downloaded bytes, requested dimensions, model, and joined prompt metadata. No transcoding or new runtime dependency is introduced.
  • Adds network-blocked regressions for both public driver paths and PromptImageGenerationTool, including real PNG/JPEG decoding and artifact → task memory → FileManagerTool → temporary-file persistence. Tool dependency installation is explicitly disabled.

Validation

  • Targeted Leonardo suite: 53 passed. Covers HTTP 403/404/500; HTTP-200 empty, HTML, JSON, unknown binary, and PDF bodies; absent/misleading/generic Content-Type; PNG/JPEG byte/format/MIME consistency; and six local save/full-decode cases.
  • Ruff lint and format checks on both modified files passed.
  • Pyright on the Leonardo driver passed with 0 errors/warnings.
  • PNG/JPEG artifact construction also succeeds with Pillow imports blocked. Pillow is used only for full decoding in tests.

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.png does 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.

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

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant