Recompress oversized images under Bluesky's blob limit - #1343
Merged
Conversation
Bluesky rejects post embeds whose image blobs exceed 2,000,000 bytes, surfacing as "blob too big" at $.record.embed.images[].image when the record is created. The Cloudflare migration replaced Thumbor's max_bytes filter with a fixed JPEG quality, which no longer guarantees the blob stays under the limit. Because bluesky_url is deterministic, an oversized photo produced the same too-big blob on every Sidekiq retry and could never be shared. Enforce the limit in the uploader: when a fetched image exceeds the blob limit, recompress it as JPEG — dropping quality first, then scaling down — and upload the first result that fits. Images already under the limit are uploaded untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016fUUqvz6wwWoeHJ4DcWncy
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.
Problem
Sharing photos to Bluesky was failing in production with:
Bluesky rejects any post embed whose image blob exceeds 2,000,000 bytes. The failure is reported when the record is created (
uploadBlobitself accepts the blob, so it surfaces later atcreateRecord).The Cloudflare migration replaced Thumbor's
max_bytesfilter — which walked JPEG quality down until the image fit under the limit — with a fixedquality: 80inPhoto#bluesky_url, since Cloudflare has no equivalent filter. For high-detail photos, quality 80 at up to 4000px still produces blobs over 2 MB. And becausebluesky_urlis deterministic, every Sidekiq retry fetched the exact same oversized blob and failed identically — which is why "every time it retries it's getting the same photo."Fix
Enforce the blob limit in the uploader itself (
Bluesky#upload_photo):MAX_BLOB_SIZE(2,000,000 bytes), recompress it as JPEG before uploading.This guarantees the blob converges to a size Bluesky accepts, so oversized photos now share successfully instead of retrying forever.
Testing
Added
spec/lib/bluesky_spec.rbcoverage for:🤖 Generated with Claude Code
https://claude.ai/code/session_016fUUqvz6wwWoeHJ4DcWncy
Generated by Claude Code