Return 404 when Active Storage image variants cannot be processed - #172
Merged
Merged
Conversation
thibaudgg
marked this pull request as ready for review
September 1, 2026 11:57
Blobs can be stored as PNG/JPEG while the bytes are not a format libvips can load. Variant generation then raised Vips::Error from the representations redirect, turning newsletter/Trix image URLs into 500s (AppSignal #458). Rescue that like an unusable blob. Co-authored-by: Thibaud Guillaume-Gentil <thibaud@thibaud.gg>
cursor
Bot
force-pushed
the
cursor/activestorage-vips-representation-c57b
branch
from
September 1, 2026 12:29
e561725 to
acb3c7f
Compare
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.
Why
Production AppSignal exception incident #458 is a
Vips::ErrorfromActiveStorage::Representations::RedirectController#show:Recent traces (tenant
ragedevert, blobs ~9548 and ~9549) 500 while transforming the blob to the newsletter/Trix JPEG variant (resize_to_limit: [1024, 768], matchingapp/views/active_storage/blobs/_blob.html.erb).The blob is stored/named as an image, so Active Storage treats it as representable, but the bytes are not a format libvips can load (corrupt, truncated, or not actually an image). Rails already returns 404 for an invalid variation signature; this extends that to failed image processing.
Upload-time validation alone would not stop the 500s: these blobs already exist, Trix only checks the browser-reported MIME type, and org logos already validate bytes with Vips. This keeps the existing images in place and makes their representation URLs fail closed.
What
ActiveStorage::Representations::BaseController#set_representationafter boot and rescueVips::Error/ImageProcessing::Errornext to the existingInvalidSignaturehandler (head :not_found).after_initialize(notto_prepare+ prepend): the gem controller is not loaded while initializers run, and gem controllers do not reload.Do not merge or deploy from this PR. Leave the AppSignal incident open.