Repository navigation
Interrupted image rollback can create repeated filename suffixes and stale references #1136
Description
Summary
During transfer-back from Optimole Cloud, an interrupted or overlapping rollback can leave a restored image under a collision-derived filename. A later attempt can create another suffixed filename while the attachment or content still references an earlier name. The rollback is expected to restore one consistent local filename and keep WordPress references aligned. Instead, affected images return broken URLs on the front end, and repeated attempts can worsen the filename divergence.
Customer context
Product / area: Optimole Pro image storage transfer-back / rollback
Version: Optimole version unknown
Environment: WordPress 7.1; PHP 8.1.34
Integration / third party: Hosting filesystem and WordPress media sideload workflow
Reported error / symptom: A backed-up image had a .1.webp suffix; the current local copy has a .1-1.webp suffix while stored references use an earlier filename.
Impact: Front-end images are broken on a live business site.
Reproduction notes
Reported workflow:
- Transfer images between the WordPress site and Optimole Cloud.
- Run transfer-back or rollback, with at least one attempt apparently interrupted or repeated.
- Inspect an image whose earlier stored filename ends in
.1.webp. - Observe a local
.1-1.webpfile while WordPress or page content references an earlier filename. - Load the affected front-end content and observe a broken image.
The exact sequence was not independently reproduced. Missing details include the Optimole version, transfer logs, pre-existing destination files, and whether individual and bulk operations overlapped.
Diagnosis
Conclusion
The rollback path is non-transactional. It moves the downloaded file into uploads before updating the attachment’s stored path. If execution stops in that interval, the moved file remains while database references retain the prior name. A retry requests the same basename and can encounter the orphaned file, allowing another collision suffix. The customer’s observed .1-1.webp file plus stale references matches this reachable failure state. The exact source of the first .1 suffix was not established.
Where this likely occurs
- User-visible surface: Optimole
Image Storagetransfer-back / rollback. inc/media_offload.php—Optml_Media_Offload::rollback_and_update_images()lines 864–979 derives a basename from attachment metadata, downloads the cloud image, and passes that name towp_handle_sideload().inc/media_offload.php—Optml_Media_Offload::rollback_and_update_images()lines 960–1004 moves the file at line 961, then performs image processing before updating_wp_attached_fileat line 1004. Several early-return branches after the move do not remove the moved file.inc/media_offload.php—Optml_Media_Offload::acquire_transfer_lock()lines 1999–2016 uses separate transient read and write operations, so acquisition is not atomic under a concurrent race.inc/media_offload.php—Optml_Media_Offload::move_single_image()lines 2072–2105 invokes attachment processing without acquiring the bulk transfer lock, leaving an individual rollback able to overlap bulk processing.- Git history shows prior fixes in this subsystem, including rollback destination handling in
3e2d769dc57d1b29fb5e26cce4e8660ea1ae7413, attached-file updates ine725f747fe06dd8942fe7e7b08b0e1a1235b1d37, and duplicate-processing locks in thev4.2.11line. No history evidence identifies a verified regression boundary for this behavior.
Engineering notes
The inspected plugin relies on the WordPress sideload workflow for collision naming. WordPress core source was not present in the inspected workspace, so the precise suffix algorithm was not independently verified here. The customer’s filesystem evidence confirms that a collision-derived .1-1.webp file exists. The plugin path itself confirms that filesystem mutation precedes the final attached-file update and lacks rollback of that mutation on interruption. Bulk locking reduces sequential duplicate starts, but individual rollback bypasses that lock, and transient acquisition is a read-then-write operation. The affected Optimole version and rollback logs were unavailable, limiting attribution to one exact execution path.
Test coverage status
tests/test-media.php lines 348–358 cover a successful basic rollback. Lines 360–393 cover rollback-error retry eligibility. Lines 643–741 cover sequential lock acquisition, expiry, ownership, and duplicate scheduling. No relevant coverage was found during inspection for an existing destination filename, interruption after sideload, repeated rollback after partial filesystem mutation, actual concurrent acquisition, or individual-versus-bulk overlap.
What to verify or explore next
- May be worth reproducing rollback with the intended local basename already present and recording the returned sideload path plus attachment metadata.
- May be worth interrupting execution after the sideload move but before
update_attached_file(), then retrying the same attachment. - If reproducible, checking the targeted
tests/test-media.phpsuite across the customer’s installed version and currentv4.2.11may clarify version scope. - May be worth exercising simultaneous individual and bulk rollback for one attachment.
- If the original rollback logs become available through sanctioned diagnostics, checking timestamps around repeated processing of the same attachment may identify the observed trigger.
Unknowns / follow-up
- The customer’s installed Optimole version is unknown.
- The transcript did not include a REST API base, so the shared diagnostic token could not be used; rollback and offload logs were not retrieved.
- HelpScout returned no ticket images or attachments.
- The mechanism that first produced the
.1.webpname is unverified.
Confidence
Confidence: 88/100
Repository inspection confirms a non-transactional rollback sequence: the local file is moved before attachment metadata is updated, while interrupted attempts leave collision files in place for retries. This directly supports the reported suffix cascade and stale-reference state; the exact initial .1 naming source remains unverified.
Source: HelpScout #3436947600
Generated by bug-report-triage (ID: bug-report-triage_6a978341348899.48114182)
Activity
milicavs commentedon Sep 2, 2026
Additional evidence from the customer logs (ticket 3436947600)
The customer supplied
offload.logandrollback.logcovering roughly Dec 2024 to Jul 2026 (the logger writes no year; the sequence below is reconstructed from append order). They confirm the overlapping-process hypothesis directly:Concurrent transfer runs are frequent, on multiple plugin versions:
acquire_transfer_lock()(non-atomic transient get then set) does not prevent it in practice.Shared process meta corrupts run state under concurrency:
Likely permanent data loss for a subset:
Nine attachment IDs (23858, 24291, 24326, 24490, 25681, 25955, 26030, 26065, 26318, 28371) fail with "error getting URL" or "error downloading URL" in both the Oct 2025 and Jul 2026 rollback runs, so their cloud copies are no longer retrievable while the attachments remain flagged as offloaded. A plausible mechanism is a concurrent rollback deleting the cloud copy (
delete_attachment_from_server) after one process succeeded, while the racing process had already failed and leftrollback_errormeta behind.On the
.1suffix: the rollback path can only produce dash suffixes (-1) viawp_handle_sideload/wp_unique_filename. The dot-style.1names predate the logged window and were most likely created outside the plugin (the customer restored cPanel backups alongside plugin-restored copies). The plugin's contribution is compounding them: rolling back an attachment already namedname.1.webponto a disk that already heldname.1.webpproducedname.1-1.webp, with_wp_attached_fileupdated but post content references left stale. We verified on the live site that some images are broken as a result.Suggested hardening: make the transfer lock atomic (e.g.
add_optionwith autoload off, orwp_cache_addsemantics, rather than transient get/set), re-check the offloaded/rolled-back meta immediately before sideload so a second process skips already-processed attachments, and deferdelete_attachment_from_serveruntil the attachment meta verifiably points at the restored local file.pirate-bot commentedon Sep 18, 2026
Another customer reported this via support.
Customers on v4.2.13 experience widespread broken images and unexpected file paths that render pages unusable, matching the stale-reference and collision behavior tracked in issue #1136. The investigation confirmed a concurrency defect in
Optml_Media_Offload::acquire_transfer_lock()withininc/media_offload.php, where separate transient read and write operations allow overlapping transfer requests to bypass locking. Additionally,Optml_Media_Offload::rollback_and_update_images()can move local files before updating final attachment metadata, causing divergent filesystem paths and stored references when interrupted.Source: automated uninstall feedback — optimole-wp, 2026-09-17
Generated by bug-report-triage (ID: bug-report-triage_6aacc587c19912.49927929)
fix: reuse the file left by an interrupted rollback instead of deleti…
milicavs commentedon Oct 20, 2026
🧪 QA steps and test links
When restoring an image from Optimole Cloud to the Media Library is interrupted partway, the next attempt saves it under a new
-1file name and leaves the first copy behind, so the site ends up with diverging file names and stale references. Normal use can't trigger this on demand: it needs a restore request that dies midway, or two transfers that start at the same moment. The steps simulate the crash with a Code Snippet.Requires: a connected Optimole account with Image Storage (offload) available, and the Code Snippets plugin.
Reproduce on Optimole 4.2.17:
qa-photo.jpg(it is offloaded automatically).QA crash first restore, code below, Run snippet everywhere, then Save Changes and Activate.qa-photoand click Restore image to media library. The restore fails.qa-photo-1.jpg, andqa-photo.jpgin the same uploads folder still opens as a leftover copy.qa-photo.jpg, and noqa-photo-1.jpgexists.Edge cases
-1files.Assumption: the crash is simulated just before the restored image's sizes are generated, which is the window the fix covers. A crash at another point may behave differently.
Fix: #1191 (open, draft; no build yet)
fix: make the transfer lock atomic and clean up files left by interru…