Page MenuHomePhabricator

Phantom revisions in filerevision table due to incorrect rollbacks of queries during early WRITE_NEW phase
Open, Needs TriagePublicPRODUCTION ERROR

Description

Steps to replicate the issue (include links if applicable):

What happens?:

File histories are different.

Zrzut ekranu 2026-09-29 202514.png (1,903×732 px, 142 KB)

Zrzut ekranu 2026-09-29 202340.png (1,898×635 px, 125 KB)

(the Wieralee's action with timestamp 2025-07-25T22:38:35 cannot be found in the user's history)

On this page in Commons
What should have happened instead?:

File history should be consistent.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Earlier today we could see:

Internal error:
[cd9d08ab-6c56-4844-9de9-afc3f2e13b58] 2026-09-29 18:33:12: Fatal exception of type "RuntimeException"

Event Timeline

Ankry renamed this task from Internal error "RuntimeException" while accessing a file in Wikimedia Commons. to Different file history in Wikimedia Commons and plwikisource..Sep 29 2026, 6:47 PM
Ankry updated the task description. (Show Details)

And all pages on Commons transcluding this file can't be opened.

Error is:

	Could not find data for image 'E._T._A._Hoffmann_-_Opowieści.pdf'.
from /srv/mediawiki/php-1.47.0-wmf.21/includes/FileRepo/File/LocalFile.php(552)
#0 /srv/mediawiki/php-1.47.0-wmf.21/includes/FileRepo/File/LocalFile.php(710): MediaWiki\FileRepo\File\LocalFile->loadExtraFromDB()
#1 /srv/mediawiki/php-1.47.0-wmf.21/includes/FileRepo/File/LocalFile.php(1196): MediaWiki\FileRepo\File\LocalFile->load(int)
#2 /srv/mediawiki/php-1.47.0-wmf.21/includes/FileRepo/File/File.php(843): MediaWiki\FileRepo\File\LocalFile->getMetadataItems(array)
#3 /srv/mediawiki/php-1.47.0-wmf.21/extensions/PdfHandler/includes/PdfHandler.php(374): MediaWiki\FileRepo\File\File->getMetadataItem(string)
#4 /srv/mediawiki/php-1.47.0-wmf.21/includes/FileRepo/File/File.php(2099): MediaWiki\Extension\PdfHandler\PdfHandler->formatMetadata(MediaWiki\FileRepo\File\LocalFile, MediaWiki\Context\RequestContext)
#5 /srv/mediawiki/php-1.47.0-wmf.21/includes/Page/ImagePage.php(134): MediaWiki\FileRepo\File\File->formatMetadata(MediaWiki\Context\RequestContext)
#6 /srv/mediawiki/php-1.47.0-wmf.21/includes/Actions/ViewAction.php(71): MediaWiki\Page\ImagePage->view()
#7 /srv/mediawiki/php-1.47.0-wmf.21/includes/Actions/ActionEntryPoint.php(753): MediaWiki\Actions\ViewAction->show()
#8 /srv/mediawiki/php-1.47.0-wmf.21/includes/Actions/ActionEntryPoint.php(511): MediaWiki\Actions\ActionEntryPoint->performAction(MediaWiki\Page\ImagePage, MediaWiki\Title\Title)
#9 /srv/mediawiki/php-1.47.0-wmf.21/includes/Actions/ActionEntryPoint.php(145): MediaWiki\Actions\ActionEntryPoint->performRequest()
#10 /srv/mediawiki/php-1.47.0-wmf.21/includes/MediaWikiEntryPoint.php(180): MediaWiki\Actions\ActionEntryPoint->execute()
#11 /srv/mediawiki/php-1.47.0-wmf.21/index.php(44): MediaWiki\MediaWikiEntryPoint->run()
#12 /srv/mediawiki/w/index.php(3): require(string)
#13 {main}

Ran some AI analysis. These file revisions have the same sha1, which shouldn't be possible is unlikely, which incidentally also makes the metadata logic for PDFs fail, but the actual problem is broader.

For E._T._A._Hoffmann_-_Opowieści.pdf there is one entry in the upload log:
https://quarry.wmcloud.org/query/109755

new file revision table has two revisions, one, the latest, is NOT in the log, but IS marked as the latest/current version of the file in the file table.
https://quarry.wmcloud.org/query/109754

the old table has only 1 entry:
https://quarry.wmcloud.org/query/109756

It seems that until b992592266f we did a write for the new schema into the file revision table, that would not get rolled back when the duplicate content abort (fileexists-no-change) was triggered and now we have a whole bunch (in the thousands) of phantom rows in the new file revision table, that should not have been there.

Another nice example is:
https://pl.wikisource.org/wiki/Plik:2026-03-26_Yamada,_Japan_M6.5_earthquake_shakemap_(USGS).jpg
vs
https://commons.wikimedia.org/wiki/File:2026-03-26_Yamada,_Japan_M6.5_earthquake_shakemap_(USGS).jpg

These file revisions have the same sha1, which shouldn't be possible

SHA1 is broken, so that isn't impossible, although it does seem unlikely in context.

SHA1 is broken, so that isn't impossible, although it does seem unlikely in context.

Unlikely would have been better phrasing yes

Took quite some effort to figure out how to better identify these to assess the scope and i'm still not 100% sure this is a correct query, but

SELECT COUNT(*) AS potential_phantom_rows, COUNT(DISTINCT fr.fr_file) AS affected_files
  FROM filerevision fr
  JOIN file f ON f.file_id = fr.fr_file
  JOIN image img ON img.img_name = f.file_name
  WHERE fr.fr_archive_name = ''
    AND fr.fr_deleted = 0
    AND fr.fr_id BETWEEN 127000000 AND 152500000
    AND NOT ( fr.fr_timestamp = img.img_timestamp AND fr.fr_sha1 = img.img_sha1 );

Comes down to around 255,147 phantom revisions of 18,224 affected file entries between 2025-05-03 and 2026-05-26. Around 0.075% of the files uploaded in that time window.
There's possibly some overlap with the issue T67264: File storage uses (title,timestamp) as a unique key, but this is not unique, I haven't been able to check that.

Some random samples:

file_idfilename
118378010Listed_buildings_on_South_Street,_Leominster_-_geograph.org.uk_-_7639603.jpg
11930867820.05.2025_-_Cerimônia_de_Entrega_da_Ordem_do_Mérito_Cultural_(54534404164).jpg
119466010111003_Wasserturm_Rothenburg_(W).jpg
120091981Audi_A6_Avant_2.4_C6_Night_Blue_Pearl_(4).jpg
120558200Ponies_and_Poppies_at_Birnieknowes_-_geograph.org.uk_-_7789004.jpg
120861531Photoplay_-_1929.10_-_19_-_Marion_Davies.png
68169953Matrix_0111_1000_1000_1001.svg
121871160A_roof_on_the_seafront^_-_geograph.org.uk_-_7836525.jpg
122623273Housel_Cove_-_geograph.org.uk_-_7887849.jpg
123022344Davenwood,_Upper_Stratton_-_geograph.org.uk_-_7899988.jpg
1219687302025-06-28_Scotia_Sea_M6.6_earthquake_shakemap_(USGS).jpg
123871422St._Andrew's_church_(Leinthall_Earls)_-_geograph.org.uk_-_7963922.jpg
37154983Elisa_pizzini.jpg
1236800072025-07-22_Petropavlovsk-Kamchatsky,_Russia_M6_earthquake_shakemap_(USGS).jpg
125400601Arable_at_Neilshill_Farm_-_geograph.org.uk_-_8055828.jpg
126009663CCFC_2010_gala_(4664182692).jpg
1264591652025-07-30_Severo-Kuril’sk,_Russia_M6_earthquake_shakemap_(USGS).jpg
1254349312025-08-14_Lata,_Solomon_Islands_M6.3_earthquake_shakemap_(USGS).jpg
1268367662025-08-31_Asadābād,_Afghanistan_M6_earthquake_intensity_map_(USGS).jpg
1261184432025-08-23_Acajutla,_El_Salvador_M6_earthquake_intensity_map_(USGS).jpg
128179303Lucca,_cimitero_urbano,_arcate_sud,_monumento_ad_albino_giannecchini,_m._1925,_di_renzo_bianchini,_03.jpg
128650551Vila_Nova_de_Foz_Côa_DSC_0132_(54275768953).jpg
1293644112025-09-30_Talisay,_Philippines_M6.9_earthquake_intensity_map_(USGS).jpg
129650122Abertura_da_II_Cúpula_Parlamentar_de_Mudança_Climática_e_Transição_Justa_da_América_Latina_e_do_Caribe_(54702738147).jpg
130390939Портрет_Гойбетера_Ганаева._Село_Гойты._82_года_13.08.1925_г._"Мюрид_Кунта_Хаджи_в_гражданскую_войну_с_белыми_получил_5_ранений".png
130598964Хенд_мейд_(9929761955).jpg
1312595612025-12-06_2025_Hubbard_Glacier_Earthquake_M7_earthquake_intensity_map_(USGS).jpg
131754600Map_of_Kokang_District_of_SR1.svg
131912914Calauag_Rotonda,_Quezon,_Dec_2025_(2).jpg
112829493Wuenheim,_Église_Saint-Gilles.jpg
133230627DSC_4856_(16522654395).jpg
133377586Latvia,_Riga_-_«Круглая_стоянка»_(Рига)_WMID6106873.jpg
1329927892026-01-10_Tobelo,_Indonesia_M6.4_earthquake_shakemap_(USGS).jpg
1338947182026-01-29_South_Sandwich_Islands_region_M6_earthquake_shakemap_(USGS).jpg
135044690SECRETARY-HOLIDAY-2025DP3_1363_(54990150504).jpg
1342791122026-02-04_Kermadec_Islands,_New_Zealand_M6.1_earthquake_shakemap_(USGS).jpg
136105471Hake01.png
136569968TechCrunch_Disrupt_Berlin_2019_-_Day_2_-_MG_156_(49211481532).jpg
136942672Douro_region_logo.svg
1374307052026-03-21_northern_Mid-Atlantic_Ridge_M6.6_earthquake_shakemap_(USGS).jpg
138064250ДАКрО_Р-293-1-86_Іменний_список_допризивників_(1902).pdf
1374307052026-03-21_northern_Mid-Atlantic_Ridge_M6.6_earthquake_shakemap_(USGS).jpg
139063306Am_Hofgarten_1_&_3_-_2026_-_p02.jpg
139555199Fuel_Cell_entering_Building_(7859247416).jpg
140003946Hautklinik_Liebermeisterstraße_25_Tübingen_05.jpg
140233090Ukraine_-_Senator_McCain_and_Ambassador_Pyatt_Visited_Odesa,_Sept._23-24,_2015_(21875256462).jpg
141013559Sungai_Tamborasi,_Kolaka,_Sulawesi_Tenggara.jpg
132640813Child_deaths_from_malaria_number,_ARE.svg

A lot of these seem to have timestamps that are pretty close, which makes me wonder if this also happened for stashed uploads retries or something.

TheDJ renamed this task from Different file history in Wikimedia Commons and plwikisource. to Phantom revisions in filerevision table due to image table migration.Oct 1 2026, 1:03 PM
TheDJ renamed this task from Phantom revisions in filerevision table due to image table migration to Phantom revisions in filerevision table due to incorrect rollbacks of queries during early WRITE_NEW phase.
TheDJ added a subscriber: Ladsgroup.

ping @Ladsgroup and @Zabe making sure this is on your radar.

Aklapper changed the subtype of this task from "Bug Report" to "Production Error".Sat, Oct 24, 12:45 PM
Zabe moved this task from Triage to In progress on the DBA board.

Quick check shows that it doesn't happen after the patches got in. We just need to clean up ~320,000 rows.