Page MenuHomePhabricator

PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson failed to encode "wgPageAssessments": Malformed UTF-8 characters
Open, HighPublicPRODUCTION ERROR

Description

Error
  • mwversion: 1.47.0-wmf.11
  • timestamp: 2026-07-21T18:43:43.841Z
  • phpversion: 8.3.32
  • reqId: 1ef566d0-5fdc-46c0-9ab4-3c0a46963374
  • Find reqId in Logstash
normalized_message
[{reqId}] {exception_url}   PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded
FrameLocationCall
from/srv/mediawiki/php-1.47.0-wmf.11/includes/ResourceLoader/Context.php(484)
#0[internal function]MediaWiki\Exception\MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.47.0-wmf.11/includes/ResourceLoader/Context.php(484)trigger_error(string, int)
#2/srv/mediawiki/php-1.47.0-wmf.11/includes/ResourceLoader/ClientHtml.php(297)MediaWiki\ResourceLoader\Context->encodeJson(array)
#3/srv/mediawiki/php-1.47.0-wmf.11/includes/Output/OutputPage.php(3709)MediaWiki\ResourceLoader\ClientHtml->getHeadHtml(string)
#4/srv/mediawiki/php-1.47.0-wmf.11/includes/Skin/Skin.php(691)MediaWiki\Output\OutputPage->headElement(MediaWiki\Skins\Vector\SkinVector22)
#5/srv/mediawiki/php-1.47.0-wmf.11/includes/Output/OutputPage.php(3101)MediaWiki\Skin\Skin->outputPageFinal(MediaWiki\Output\OutputPage)
#6/srv/mediawiki/php-1.47.0-wmf.11/includes/Actions/ActionEntryPoint.php(162)MediaWiki\Output\OutputPage->output(bool)
#7/srv/mediawiki/php-1.47.0-wmf.11/includes/MediaWikiEntryPoint.php(180)MediaWiki\Actions\ActionEntryPoint->execute()
#8/srv/mediawiki/php-1.47.0-wmf.11/index.php(44)MediaWiki\MediaWikiEntryPoint->run()
#9/srv/mediawiki/w/index.php(3)require(string)
#10{main}
Impact/Notes

The rate has increased a lot recently

growthovertime.png (586×268 px, 14 KB)

Details

Request URL
https://ne.wikipedia.org/w/index.php?diff=*&oldid=*&title=*&useparsoid=*
Related Changes in Gerrit:

Event Timeline

Claude's analysis:

Root cause

The malformed UTF-8 is a corrupted JSON object key in the wgPageAssessments config var emitted into <head>. The value is a project-keyed map, e.g. {"नेपाल":{"class":"क","importance":null}}, and one of those keys is not valid UTF-8, so json_encode() of the whole mw.config blob fails in ResourceLoader\Context::encodeJson() — taking out the entire head-config for the page.

The bad key comes from PageAssessmentsStore::cleanProjectTitle(), which ended with:

return substr( $project, 0, 255 );

pap_project_title is VARCHAR(255) under DEFAULT CHARSET=binary, i.e. a 255-byte column. substr() is byte-based, so a project title longer than 255 bytes (≈85 Devanagari characters) is sliced mid-codepoint, storing malformed UTF-8. PageAssessmentsStore::getAllAssessments() then uses that stored pap_project_title as a JSON object key → encodeJson fails.

Why the rate jumped (July 1–2)

Two changes turned a latent data-corruption bug into a high-rate production error, and both were live once the 1.47.0-wmf.9 train reached the Wikipedias:

  • d793dab (2026-06-06) — made getAllAssessments() keyed by project title, so the corrupt title becomes a JSON key.
  • 6ebacd2 (2026-06-17, T374761: PageAssessments should specify WikiProjects as config variable) — added OutputPageHooks, which emits wgPageAssessments into <head> on every ordinary article view with assessments. Before this, the var was not present on normal page views, so the corruption had essentially no surface there.

The PageAssessments extension had no commits between 6ebacd2 (June 17) and July 14, so wmf.9 (branch cut June 30) already pinned both changes. Per the wmf.9 deployment blocker T423918: 1.47.0-wmf.9 deployment blockers, the rollout was:

  • group1 (non-Wikipedia wikis): 2026-07-01
  • group2 (all Wikipedias, incl. ne.wikipedia): 2026-07-02

That exactly matches the onset of the spike. (wmf.11, cited in the report above, is simply the version that happened to be running when the task was filed on July 21; the regression itself shipped with wmf.9.)

This all adds up. T330173: page_assessments table uses an inadequate VARBINARY length for pa_class/pa_importance is for fixing the DB storage. It sounds like until that happens (DB changes take a while…), we should force UTF-8 encoding and/or use mb_sbtr() instead of substr() for the truncation.

The spike in warnings should I hope be mostly gone now that the related fix for T374761 has hit group 2.

Krinkle renamed this task from PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded to PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson failed to encode "wgPageAssessments": Malformed UTF-8 characters.Jul 24 2026, 11:55 PM

Change #1316312 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] ResourceLoader: Improve encodeJson() warning to mention bad key

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

Change #1316312 merged by jenkins-bot:

[mediawiki/core@master] ResourceLoader: Improve encodeJson() warning to mention bad key

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

Still seeing this error for newiki following group2 deployment of wmf.13 today, albeit at a low rate.