Repository navigation
fix: keep new uploads local while an Image Storage rollback runs - #1174
Merged
Merged
Conversation
During a rollback, offload_media is off but is_offload_enabled() stays true so that already offloaded images keep being served from Optimole. That also kept the upload hooks on, so a new upload was offloaded while everything else was being moved back. generate_image_meta() and the filename deduplication in insert() are now registered only while offload_media is on; they belong together, because insert() renames the attached file for offloaded uploads only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
pirate-bot
requested changes
Oct 11, 2026
Collaborator
There was a problem hiding this comment.
🟡 Changes requested
The rollback gate works, and the new test detects it. Add the missing void return type to the new test method.
Validation details
- Files reviewed: 2/2 changed files.
sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Media::'ran on PHP 8.3.35 with the WP 7.1.3 test library. HEAD printedOK (24 tests, 134 assertions). The base tree failedtest_upload_during_rollback_stays_localattests/test-media.php:362. No run record was emitted for this command.- A source read shows that rollback selects only offloaded attachments. A new local upload is not restored.
- A restored file goes through
wp_handle_sideload()andwp_unique_filename(). It gets a-Nsuffix and does not overwrite the new upload. - The hooks that stay registered return their input for attachments that were not offloaded.
- The security pass found no changed trust boundary.
Untested areas
- An upload during a rollback on a site connected to Optimole was not run. The sandbox is not connected.
- The
insert_legacypath for WordPress before 6.0 was not executed.
🤖 Automated review · run code-review-agent_6acb86a43daef7.46072993.
🤖 Review agent — review posted ✅ on 1714a7e0 · changes requested · 1 finding · 26 min
Run code-review-agent_6acb86a43daef7.46072993 · trail
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three open PRs added tests at the same place in tests/test-media.php, which would conflict as they merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pirate-bot
approved these changes
Oct 11, 2026
Collaborator
There was a problem hiding this comment.
🟢 Approved
The PR passes. The earlier void return type finding is fixed, and the moved test still detects the rollback gate.
Validation details
- Files reviewed: 2/2 changed files.
- The only new commit moves the rollback test and adds
: void. sandbox-phpunit-ab.sh /repo pr-base --filter 'Test_Media::'ran on PHP 8.3.35 at a cleanaed92868checkout. HEAD printedOK (24 tests, 134 assertions). The base tree failedtest_upload_during_rollback_stays_local. No run record was emitted.- The new test order breaks no other
Test_Mediatest. - The checks of
inc/media_offload.phpand the security pass come from run code-review-agent_6acb86a43daef7.46072993, not rerun. That file did not change since then.
Untested areas
- An upload during a rollback on a connected Optimole site was not run. The sandbox is not connected.
- The
insert_legacypath for WordPress before 6.0 was not executed.
🤖 Automated review · run code-review-agent_6acb9630246ff4.31874945.
🤖 Review agent — review posted ✅ on aed92868 · approved · 0 findings · 7 min
Run code-review-agent_6acb9630246ff4.31874945 · trail
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.
Related issue: #1159
While an Image Storage rollback ran, new uploads were still offloaded to Optimole. During a rollback
offload_mediais off, butis_offload_enabled()stays true so that already offloaded images keep being served from Optimole, and that also kept the upload hooks on. New uploads now stay in the media library while a rollback runs.What changed
Optml_Media_Offload::instance()— two hooks are registered only whileoffload_mediais on, not during a rollback:wp_generate_attachment_metadata→generate_image_meta(), which offloads a new upload;wp_insert_attachment_data→insert()/insert_legacy(), the filename deduplication offloaded uploads need because their local files are deleted. It renames the attached file, and onlygenerate_image_meta()maps that name back, so the two must be gated together.Note
Everything that serves offloaded images (URL, srcset, attachment and editor filters) stays registered during the rollback, as before. Bulk offload, single-image moves and the Abilities API call
generate_image_meta()throughupload_and_update_existing_images(), not the hook, so they are unaffected.One narrow side effect to know: an upload made during a rollback keeps its local file. If a not-yet-restored offloaded image with the same file name in the same
uploads/Y/mfolder is restored later in that rollback, WordPress gives the restored file a-1suffix (the #1136 area).Tests
tests/test-media.php: withoffload_mediaoff and a rollback in progress,instance()registers neither hook (but still serves offloaded URLs), and a new upload keeps a localfilein its metadata and on disk. The test fails ondevelopment.QA
On a connected site with offloaded images, start Transfer back from Optimole in
WP Admin → Optimole → Settings → Image Storage.While it runs, upload a new image in
Media → Add New.Expect: the new image's URL points to
wp-content/uploads/…, and the file exists on the server.With Image Storage on and no transfer running, upload another image.
Expect: it is offloaded as before.
Verification (head
aed92868)tests/test-media.phprun alonedevelopmentsourcephpcs,phpstan(build-only include errors excluded locally; CI builds assets first)aed92868(PHPUnit on PHP 8.0–8.3, PHPStan, phpcs, ESLint, Jest, e2e, build)1714a7e0and the follow-up onaed928681714a7e0): changes requested, avoidreturn type on the new test (fixed; the test was also moved away from where two other open PRs add theirs). Round 2 (aed92868): approvedNot proven
🤖 Generated with Claude Code