The /tmp/mw-cache-* directory and files created by multiversion/MWConfigCacheGenerator.php are intended to be owned by the www-data user. If, for example, a maintenance script is run by the mwdeploy user (without using using mwscript), MWConfigCacheGenerator may either fail to update files in /tmp/mw-cache-*, generating a warning like:
PHP Warning: rename(/tmp/conf2-aawiki.json7MDvB9,/tmp/mw-cache-1.38.0-wmf.2/conf2-aawiki.json): Permission denied in /srv/mediawiki/multiversion/MWConfigCacheGenerator.php on line 327
or if the directory doesn't exist, it will be created and owned by mwdeploy, leaving it unwriteable by www-data.
For T295304 I have the need to run rebuildLocalisationCache.php directly as the mwdeploy user. The www-data user doesn't have permission to write where rebuildLocalisationCache.php needs to write.
Proposal: Don't call MWConfigCacheGenerator::writeToStaticCache unless the effective user is www-data. This will avoid warnings and prevent unintended ownership of /tmp/mw-cache*.
An alternate proposal is to only try to update /tmp/mw-cache* when PHP_SAPI === 'fpm-fcgi'. However, that might make it hard to test changes to multiversion/MWConfigCacheGenerator.php.