Page MenuHomePhabricator

Quality verification for mediawiki_history_incremental_v1 using Iceberg time travel
Open, In Progress, Needs TriagePublic

Description

Prerequisite

This task is blocked on T425729: stable natural keys must be resolved for page and user entities before verification can cover the full table. Until then, the join-based comparison cannot be implemented correctly for those entity types.

Summary

Design and implement a recurring verification step that measures how accurately the daily delta writer (source='events' rows) predicted what the monthly snapshot (source='snapshot') ultimately confirmed as truth.

Approach

wmf.mediawiki_history is the source of truth. After each monthly MWHistorySnapshotMerger run, the table contains both the ground-truth source='snapshot' rows for that month and — preserved via Iceberg time travel — the source='events' rows that the daily writer had accumulated up to that point.

The verification query:

  1. Time-travel read: open the Iceberg snapshot taken immediately before the monthly merge commit. This gives the source='events' rows for the month as they stood at merge time.
  2. Current read: read the live table restricted to source='snapshot' for the same month.
  3. Join on natural key per entity type and compare field by field.

This surfaces:

  • Rows present in events but absent in snapshot (delta writer ingested something the monthly rebuild dropped).
  • Rows present in snapshot but absent in events (late-arriving or lost events the daily writer missed).
  • Field-level deviations for matched rows (e.g. revision_text_bytes, revision_text_bytes_diff, revision_is_identity_reverted — the revert-detection field most likely to diverge because the daily writer uses only a 48-hour window).

Output

A summary report per monthly run:

  • Total events rows vs total snapshot rows for the month
  • Match rate (rows with identical natural key on both sides)
  • Per-column deviation rate for matched rows
  • Highlight columns with highest deviation (expected: revert columns, given the 48-hour window approximation)

Implementation

Prototype in a notebook first, then productionize as a dedicated Airflow task appended to the monthly merge DAG (see Airflow DAG task). The verification task runs after MWHistorySnapshotMerger succeeds and reads the pre-merge Iceberg snapshot via time travel.

Open questions

  • Iceberg snapshot retention policy: time-travel requires the pre-merge snapshot to still exist when verification runs. Agree with stakeholders on minimum retention before wiring this as a DAG dependency.
  • Failure policy: should a high deviation rate fail the DAG or emit a warning only?

Event Timeline

xcollazo updated Other Assignee, added: JAllemandou.
xcollazo added subscribers: APizzata-WMF, JAllemandou.

For seeing this work thru, I am boldly assigning it to @APizzata-WMF, and setting @JAllemandou as co-assignee.

Of course feel free to switch up, and/or reassign as needed, but didn't want to leave it unassigned before my leave.

After a conversation with @JAllemandou we decided to start looking into:

  • joining using wiki_id, revision_id for revisions and event_log_id for pages and users (also checking the synthetic key that is use ind MWH)
  • creating a dashboard that starts tracking events for revisions, pages, users on the daily runs
Mwex changed the task status from Open to In Progress.Jun 22 2026, 10:19 AM

Change #1305625 had a related patch set uploaded (by Joal; author: Joal):

[analytics/refinery/source@master] Update MWH - fail if duplicated revisions

https://gerrit.wikimedia.org/r/1305625

Change #1305625 merged by jenkins-bot:

[analytics/refinery/source@master] Update MWH - fail if duplicated revisions

https://gerrit.wikimedia.org/r/1305625

Change #1305633 had a related patch set uploaded (by Joal; author: Joal):

[analytics/refinery/source@master] Update Inc-MWH splitting SQL into smaller files

https://gerrit.wikimedia.org/r/1305633

With @JAllemandou today we discussed that:

  • a dashboard with just counts of how many event_entity and event_type says enough of the daily runs
  • how to check the difference between the reconcile and the previous version

Will start working on these and update the linked dashboard

a dashboard with just counts of how many event_entity and event_type says enough of the daily runs

this is now available on the dashboard, particularly:

  • selecting only the source='events' rows
  • filtering on the last 30 days of data (event_timestamp> current_date - 30)

Change #1305633 merged by jenkins-bot:

[analytics/refinery/source@master] Update Inc-MWH splitting SQL into smaller files

https://gerrit.wikimedia.org/r/1305633

During the first phase of the analysis @JAllemandou and I noticed the following things:

spark.sql("""select year(event_timestamp), count(*) from apizzata.mediawiki_history_incremental_backup_june_v1 
where source = 'events'
and year(event_timestamp) < 2026
group by 1
order by 1 desc
""").show(500)
+---------------------+--------+
|year(event_timestamp)|count(1)|
+---------------------+--------+
|                 2025|     386|
|                 2024|     278|
|                 2023|     119|
|                 2022|     119|
|                 2021|     112|
|                 2020|      99|
|                 2019|      79|
|                 2018|      90|
|                 2017|      69|
|                 2016|      70|
|                 2015|      58|
|                 2014|      82|
|                 2013|      54|
|                 2012|      74|
|                 2011|      61|
|                 2010|      69|
|                 2009|      99|
|                 2008|     110|
|                 2007|     167|
|                 2006|     170|
|                 2005|      59|
|                 2004|      21|
|                 2003|      37|
|                 2002|       1|
+---------------------+--------+

where`apizzata.mediawiki_history_incremental_backup_june_v1` is a backup of the table containing only June events.

Question: why do we receive events of years before the current?

technical_columns = ['row_update_dt', 'source', 'control_map']
all_columns = spark.sql("select * from wmf_mediawiki.mediawiki_history_incremental_v1").limit(0).schema.names
hashable_columns = [column for column in all_columns if column not in technical_columns]

from pyspark.sql import functions as F
df_snap = spark.sql(f"""
select wiki_id,
 event_entity,
 event_type,
 event_timestamp,
 event_user_id,
 event_user_central_id,
 event_user_text_historical,
 bot_by as event_user_is_bot_by_historical,
 event_user_is_anonymous,
 event_user_is_temporary,
 event_user_is_permanent,
 event_user_registration_timestamp,
 event_user_revision_count,
 event_user_groups_historical,
 event_user_is_cross_wiki,
 user_id,
 user_central_id,
 user_text_historical,
 user_is_anonymous,
 user_is_temporary,
 user_is_permanent,
 user_groups_historical,
 user_is_bot_by_historical,
 user_is_created_by_self,
 user_is_created_by_system,
 user_is_created_by_peer,
 page_id,
 page_title_historical,
 page_namespace_historical,
 page_namespace_is_content_historical,
 page_is_deleted,
 revision_id,
 revision_parent_id,
 revision_minor_edit,
 revision_text_bytes,
 revision_text_bytes_diff,
 revision_text_sha1,
 deleted_parts as revision_deleted_parts,
 revision_is_identity_reverted,
 revision_first_identity_reverting_revision_id,
 revision_seconds_to_identity_revert,
 revision_is_identity_revert,
 revision_is_deleted_by_page_deletion,
 tags as revision_tags,
 event_meta_id from (
select *,ARRAY_SORT(ARRAY_DISTINCT(COALESCE(revision_tags, CAST(ARRAY() AS ARRAY<STRING>)))) AS tags, 
ARRAY_SORT(ARRAY_DISTINCT(COALESCE(event_user_is_bot_by_historical, CAST(ARRAY() AS ARRAY<STRING>)))) AS bot_by,
ARRAY_SORT(ARRAY_DISTINCT(COALESCE(revision_deleted_parts, CAST(ARRAY() AS ARRAY<STRING>)))) AS deleted_parts
from wmf_mediawiki.mediawiki_history_incremental_v1 version as of 5445067113964585564  
and event_entity= 'revision' and source= 'snapshot')
""")
df_snap=df_snap.select('*', F.xxhash64(*hashable_columns).alias('hash'))

df_event = spark.sql("""
select wiki_id,
 event_entity,
 event_type,
 event_timestamp,
 event_user_id,
 event_user_central_id,
 event_user_text_historical,
 bot_by as event_user_is_bot_by_historical,
 event_user_is_anonymous,
 event_user_is_temporary,
 event_user_is_permanent,
 event_user_registration_timestamp,
 event_user_revision_count,
 event_user_groups_historical,
 event_user_is_cross_wiki,
 user_id,
 user_central_id,
 user_text_historical,
 user_is_anonymous,
 user_is_temporary,
 user_is_permanent,
 user_groups_historical,
 user_is_bot_by_historical,
 user_is_created_by_self,
 user_is_created_by_system,
 user_is_created_by_peer,
 page_id,
 page_title_historical,
 page_namespace_historical,
 page_namespace_is_content_historical,
 page_is_deleted,
 revision_id,
 revision_parent_id,
 revision_minor_edit,
 revision_text_bytes,
 revision_text_bytes_diff,
 revision_text_sha1,
 deleted_parts as revision_deleted_parts,
 revision_is_identity_reverted,
 revision_first_identity_reverting_revision_id,
 revision_seconds_to_identity_revert,
 revision_is_identity_revert,
 revision_is_deleted_by_page_deletion,
 tags as revision_tags,
 event_meta_id from (
select *,ARRAY_SORT(ARRAY_DISTINCT(COALESCE(revision_tags, CAST(ARRAY() AS ARRAY<STRING>)))) AS tags, 
ARRAY_SORT(ARRAY_DISTINCT(COALESCE(event_user_is_bot_by_historical, CAST(ARRAY() AS ARRAY<STRING>)))) AS bot_by,
ARRAY_SORT(ARRAY_DISTINCT(COALESCE(revision_deleted_parts, CAST(ARRAY() AS ARRAY<STRING>)))) AS deleted_parts
from apizzata.mediawiki_history_incremental_backup_june_v1 where event_entity= 'revision')
""")
df_event=df_event.select('*', F.xxhash64(*hashable_columns).alias('hash'))

df_snap.createOrReplaceTempView("hash_snap")
df_event.createOrReplaceTempView("hash_event")

where:

  • hash_snap: is a CTE with hashed content columns, where the snapshot_id (5445067113964585564) corresponds to the snapshot creation
  • hash_event: is a CTE with hashed content columns of the june_backup
spark.sql("""
with the_list as(
select event.revision_id as event_rev, snap.revision_id as snap_rev,
event.hash as event_hash, snap.hash as snap_hash,
event.event_user_revision_count as event_event_user_revision_count,
snap.event_user_revision_count as snap_event_user_revision_count,
event.event_user_id as event_user_id
from hash_event event
full outer join hash_snap snap on snap.wiki_id=event.wiki_id and event.revision_id=snap.revision_id and snap.event_user_id=event.event_user_id
where event.revision_id is not null and snap.revision_id is not null 
and event.hash!=snap.hash
),
user_revision_count as (
select event_user_id , (snap_event_user_revision_count-event_event_user_revision_count) as difference_revision_count
from the_list
where not(snap_event_user_revision_count<=> event_event_user_revision_count))
SELECT
  CASE
    WHEN difference_revision_count =-1             THEN '-1'
    WHEN difference_revision_count =-2             THEN '-2'
    WHEN difference_revision_count =-3             THEN '-3'
    WHEN difference_revision_count =-4             THEN '-4'
    WHEN difference_revision_count <= -5 and difference_revision_count > -10            THEN '[-5 -10['
    WHEN difference_revision_count <= -10 and difference_revision_count > -100            THEN '[-10 -100['
    WHEN difference_revision_count <= -100            THEN '<=-100'
    WHEN difference_revision_count <0             THEN '<0'
    WHEN difference_revision_count = 1             THEN '1'
    WHEN difference_revision_count = 2             THEN '2'
    WHEN difference_revision_count = 3             THEN '3'
    WHEN difference_revision_count = 4             THEN '4'
    WHEN difference_revision_count >= 5 and difference_revision_count < 10            THEN '[5-10['
    WHEN difference_revision_count >= 10 and difference_revision_count < 100            THEN '[10-100['
    
    
       else            '>=100'
  END                              AS bucket,
  COUNT(1)                         AS num_users
FROM user_revision_count
GROUP BY 1 
order by 1
""").show(50,truncate=False)
    
    
+----------+---------+
|bucket    |num_users|
+----------+---------+
|-1        |79035303 |
|-2        |5737532  |
|-3        |3119307  |
|-4        |2999320  |
|1         |18647768 |
|2         |11337022 |
|3         |5852111  |
|4         |2901595  |
|<=-100    |1051631  |
|>=100     |28221545 |
|[-10 -100[|265568581|
|[-5 -10[  |10191096 |
|[10-100[  |10854202 |
|[5-10[    |24396913 |
+----------+---------+

Question: for each event_user_id across the 2 different tables show different revisions content for the same revision_id. How come? What's the difference? Why the bucket are so spread?

These questions are not urgent, but the quality verification is a very important step we should not avoid or give less importance o. Knowing what happens, and hopefully the why, makes us trust more the table and the processes built on top.

Let's connect if you need any clarification or another set of eyes!
Thanks a lot for taking this task!

Answering @APizzata-WMF questions:

Q1: events with event_timestamp in past years

Revision rows take event_timestamp from the revision's own timestamp (revision.rev_dt), not from delivery time. So any event carrying a historical rev_dt produces an old event_timestamp.

Looking at the raw stream, these appear to be page imports — Special:Import, transwiki and XML import insert revisions that keep the original rev_timestamp. The pattern is consistent: sequential rev_ids with 2003-2005 timestamps, delivered seconds apart in August 2026, into userspace, with empty comments, and concentrated in a small number of accounts. The largest single one accounts for 21,328 events across 4,136 pages on knwiki. Roughly 60k such events arrived in August across all wikis.

These rows are also transient. The monthly merge deletes source='events' rows with event_timestamp before month-end, so an imported 2003 revision only survives until the next reconcile.

Page rows can carry old timestamps for the same reason, since dt is the domain-event time rather than the delivery time.

Q2: event_user_revision_count deviation

The two sides are measuring different things, so the spread looks reasonable. The events carry MediaWiki's user_editcount (definition) counter as it stood at event time. The snapshot side is computer by monthly MWH by walking the user's revisions. One is a denormalised counter maintained incrementally; the other is a position derived from reconstructed history, and they drift in proportion to how many edits a user has. In the August sample the >= 100 bucket is 621,028 rows from only 137 users, which are bots.

Thus it seems that this column is not comparable and should be excluded from the verification. We should document this difference though, and we should consider for v2 whether we should carry one or the other, but having both in the same column is just confusing...

Verification run

Time travel to the Iceberg snapshot immediately before the monthly merge gives source='events' as the daily writer left it; the live table gives source='snapshot'. Join on (wiki_id, revision_id) and compare column by column. Scope: snapshot 2026-08, revision rows, simplewiki + cawiki + euwiki — 741,607 events rows against 743,893 snapshot rows.

populationrowsshare
both741,60799.69%
snapshot only2,2860.31%
events only00%
columndeviating%
event_user_groups_historical741,607100.00
revision_deleted_parts741,46099.98
event_user_revision_count741,45799.98
page_title_historical24,0173.24
revision_text_bytes_diff13,0271.76
revision_is_identity_reverted4580.06
revision_tags1860.03
everything else00

The revert columns, which we expected to be the worst given the daily writer's bounded view, are at 0.06%. revision_tags is at 0.03% and the residue is mw-reverted, which is the same revert-window story rather than a back-fill gap.

A whole-row hash matched 0% of rows, which is what one always-deviating column does to a hash. The per-column report is the useful instrument until the systematic columns are fixed.

Four defects

page_title_historical — the revision path does not strip the namespace prefix, though the page path does, and MWH stores the bare title with the namespace held separately. All 23,995 non-main-namespace rows deviate; re-applying the strip leaves 1.

event_user_groups_historical — the streams merge MediaWiki's computed groups into the array, while MWH reads user_groups and only has explicit ones. A census across all wikis identifies five: *, user, autoconfirmed, temp, autoextendedconfirmed. The last is wiki-specific and would have been missed on a small sample. Every other group matches closely on both sides. The same issue affects event_entity='user' rows.

revision_deleted_parts — the delta writer writes NULL where MWH writes an empty array. Coalescing drops the deviation from 741,460 to 11, so it looks like purely a representation difference. It still matters, because size() on this column returns a different answer depending on the row's source.

Move-generated revisions — 1,991 of the 2,286 missing rows are in the stream as move. A page move makes MediaWiki insert a null revision, so it reaches the revision table and MWH counts it, but the revision path only reads create and edit. The overall undercount is 0.27%, but it is uneven — 29.6% in euwiki ns 3, 13.6% in cawiki ns 1 — because move frequency varies by namespace.

revision_text_bytes_diff is not a defect: 12,825 of its 13,027 deviating rows are page creates, where the prior revision size is NULL so the diff is NULL, while MWH computes rev_size - 0.

Will send a patch to fix these. After the fixes, we do not expect hashing to solve all of our problems, but we do expect it to be usable to identify >= 95%.

Change #1338971 had a related patch set uploaded (by Xcollazo; author: Xcollazo):

[analytics/refinery/source@master] MWHistoryDeltaWriter: align fields with mediawiki_history

https://gerrit.wikimedia.org/r/1338971

Change #1338971 merged by jenkins-bot:

[analytics/refinery/source@master] MWHistoryDeltaWriter: align fields with mediawiki_history

https://gerrit.wikimedia.org/r/1338971

Notice for users of wmf_mediawiki.mediawiki_history_incremental_v1

1338971: MWHistoryDeltaWriter: align fields with mediawiki_history fixes four fields in the daily writer. The fields now agree with wmf.mediawiki_history. The change affects source='events' rows only. source='snapshot' rows do not change. Rows that the daily writer wrote before the deploy keep the old values until the next monthly reconcile removes them.

1. page_title_historical drops the namespace prefix

Revision rows held the prefixed title. They now hold the bare title, and page_namespace_historical holds the namespace. Page rows already behaved this way.

namespacebeforeafter
1 (Discussió)Discussió:Llac_MarqakölLlac_Marqaköl
14 (Categoria)Categoria:Política_de_Guinea-BissauPolítica_de_Guinea-Bissau

Check any query that joins or filters on page_title_historical for non-main namespaces. A query that added the prefix itself now gets no match.

2. event_user_groups_historical drops the implicit groups

The event streams add the groups that MediaWiki computes. The table now holds explicit groups only. The five removed groups are *, user, autoconfirmed, temp and autoextendedconfirmed.

beforeafter
[bot, sysop, *, user, autoconfirmed][bot, sysop]
[*, user, autoconfirmed][]

A count of users in group user or autoconfirmed now returns zero. Counts for bot, sysop and other explicit groups do not change. event_user_is_bot_by_historical does not change, because bot is an explicit group.

3. revision_deleted_parts uses an empty array, not NULL

A revision with all parts visible held NULL. It now holds an empty array.

revision statebeforeafter
all parts visibleNULL[]
text hidden[text][text]

Use size(revision_deleted_parts) = 0 to find revisions with nothing hidden. A filter on revision_deleted_parts IS NULL no longer matches these rows.

4. Page moves now produce a revision row

MediaWiki writes a null revision for each page move. wmf.mediawiki_history counts that revision, but the daily writer skipped it. The daily writer now reads move events.

Each move adds one event_entity='revision' row with event_type='create', the sha1 of its parent, and revision_text_bytes_diff = 0. The move also keeps its event_entity='page' row, as before.

Revision counts from source='events' rise. In our August sample the rise is 0.27% overall, but it is uneven: 29.6% in euwiki namespace 3 and 13.6% in cawiki namespace 1, because move frequency changes with the namespace. Daily counts now match the monthly. Dashboards that track daily edit volume show a step at the deploy date.

We intend to deploy and backfill this on or around Tueday September 15 2026.

Not sure how much this matters or if it's a simple fix but FYI page protection follows a very similar pattern to page moves (null revision) and when checking this example, I didn't see the page protection event registered either in the source='events' rows.

spark.sql("select revision_id, event_timestamp, revision_text_bytes_diff from wmf_mediawiki.mediawiki_history_incremental_v1 where wiki_id = 'enwiki' and source = 'events' and page_id = 14779244 order by event_timestamp").show(150, False)

+-----------+-------------------+------------------------+
|revision_id|event_timestamp    |revision_text_bytes_diff|
+-----------+-------------------+------------------------+
|1372591488 |2026-09-01 10:55:56|509                     |
|1372593401 |2026-09-01 11:09:51|-509                    |
|1372595778 |2026-09-01 11:27:40|492                     |
|1372595846 |2026-09-01 11:28:12|-492                    |
|1372980354 |2026-09-03 08:56:25|244                     |
|1372983790 |2026-09-03 09:38:50|-244                    |
# MISSING IS revision 1373065385 with a text byte diff of 0
|1373065391 |2026-09-03 21:24:58|27                      |
+-----------+-------------------+------------------------+

Not sure how much this matters or if it's a simple fix but FYI page protection follows a very similar pattern to page moves (null revision)

@Isaac Good catch, thank you. You are right.

Page protection creates a null revision, the same way a page move does. WikiPage::insertNullProtectionRevision inserts it in the revision table, so wmf.mediawiki_history counts it and the daily writer misses it.

We cannot fix this the way we fixed moves. That fix worked because move is already a page_change_kind value, so the event was readily available in page_change_v1. page_change_v1 has no page_change_kind = protection. I think there is an old-style stream that could potentially have this (mediawiki.revision-create), but that would mean a new stream ingest and thus one more MERGE. Perhaps the better approach would be to integrate those events in page_change_v1?

The gap is also wider than protection. MediaWiki core appears to creates null revision in four places: page move (now fixed), page protection (your case), a new version of an existing file (not sure what that means), and an import summary (not sure what that means either).

Something to consider for v2, feel free to add this to the list at T437051: Incremental MediaWiki History v2 - data requests.

CC @Ottomata, we may need to modify page_change_v1 to satisfy this one.

Ya. I think, but am not sure, that page protections are possibly a different event stream. TBD but we def need it.

xcollazo opened https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2642

table_maintenance: Reduce mediawiki_history_incremental_v1 retention from 90 to 45 days

xcollazo merged https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2642

table_maintenance: Reduce mediawiki_history_incremental_v1 retention from 90 to 45 days

xcollazo merged https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2658

incremental_history: bump refinery-job-35 to pickup daily write fixes

With this refinery-job-35 bump we are now ready to rerun all runs since Sept 1 to today, to re-ingest the date since last reconcile.

Airflow reruns from scheduled__2026-09-01T00:00:00+00:00.

xcollazo merged https://gitlab.wikimedia.org/repos/data-engineering/airflow-dags/-/merge_requests/2658

incremental_history: bump refinery-job-35 to pickup daily write fixes

With this refinery-job-35 bump we are now ready to rerun all runs since Sept 1 to today, to re-ingest the date since last reconcile.

Airflow reruns from scheduled__2026-09-01T00:00:00+00:00.

All data re-ingested.

Wait... I forgot to clear the DagProperties, so all the re-runs just reinserted the same data without the fix.

Re-runing with the right refinery-job-35 version now.