Amazon Ergo 1.0 · Balanced
feature-automatically-downsize-large-images-discourse-cursor
Discourse · Ruby · S · 30–99 lines · 3 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 4 of 9
- Comments published
- 6
- Comments matching a bug
- 4
- Comments not matching
- 2
- Cost of this PR
- $1.284
Published comments (6)
resize_emoji calls downsize with the removed five-argument signature — Custom emoji resizing is broken: every `resize_emoji` job enqueued by `Emoji.create_for` raises `ArgumentError` on the five-argument `OptimizedImage.downsize` call. Update `app/jobs/regular/resize_emoji.rb` to pass one geometry string such as `"100x100"`, and remove the dead old `downsize` definition.
Animated GIF downsizing fails because gifsicle receives a percentage — Large animated GIFs cannot be downsized: `downsize_instructions_animated` passes `80%` to `gifsicle --resize-fit`, which requires `widthxheight` geometry, so all five attempts fail and the oversized original is rejected. Use `FastImage.size` to build pixel geometry for `OptimizedImage.downsize`, falling back to `80%` only when dimensions are unavailable.
Downsizing the original upload discards animation when thumbnail setting is off — With `SiteSetting.allow_animated_thumbnails` disabled, `downsize_instructions` reads only `#{from}[0]` and overwrites the user's original animated GIF with a single frame, permanently discarding its animation. Pass `allow_animation: true` so preserving the uploaded original does not depend on a thumbnail setting.
API URL downloads capped at hardcoded 10MB, ignoring max_image_size_kb — Sites with image limits above 10MB lose previously working API URL uploads because `FileHelper.download` uses a hardcoded cap instead of `SiteSetting.max_image_size_kb`. Pass `SiteSetting.max_image_size_kb.kilobytes` as the download limit.
Upload validation ignores configured per-type size limits — Hardcoding `maxSizeKB` to 10MB lets attachments exceed lower server limits before a full upload is rejected, while blocking valid files on sites configured above 10MB. Restore `Discourse.SiteSettings['max_' + type + '_size_kb']`, applying the 10MB ceiling only when `type === 'image'`.
Downsize loop keeps retrying after conversion failures — Ignoring a `false` return from `OptimizedImage.downsize` sends corrupt or unsupported images through all five conversion attempts, wasting synchronous API request time without changing `tempfile.size`. Stop the loop when conversion fails and handle the error instead of retrying.