In my case had changed the $wgMainCacheType to 'CACHE_ACCEL' to enable apcu and opcache in php server itself. I had left $wgSessionCacheType out of the config file at default of 'CACHE_ANYTHING'. In this configuration, the token is stored on the php "server" APCu cache.
## Shared memory settings
$wgMainCacheType = CACHE_ACCEL;
This caused the sort of 'live' in-flight session token to get cleared fairly quickly as APCu cleared its state, which is more for performance and intended to be fairly dynamic.
Thus I'd get the "Sorry! We could not process your edit due to a loss of session data." really quickly and inconsistently, like 30 seconds, 1-2 minutes or maybe 5 mins. This made it really annoying.
Page edits in MediaWiki require the the matching sort of 'live token' to complete. Normally it just gets regenerated constantly if missing, except on submitting edits. I think this was to prevent accidental stale edits from someone who had already logged out, as a security measure.
What was happening was that the browser was fine, but the live token cache object in APCu was getting cleared as hadn't been used soon enough, because I had stopped to edit..., and the server side had no matching token on submit.
What I needed to add was:
$wgSessionCacheType = CACHE_DB;
This causes the session security token to get persisted correctly according to the MediaWiki rules, and not the dynamic object caching rules. Which is explained here: https://www.mediawiki.org/wiki/Manual:$wgSessionCacheType
For proper operation this must be set to a persistent cache, and if
there are multiple servers that might serve a single client's requests
the cache must be shared by all of them.
If $wgMainCacheType is set to CACHE_ACCEL and this is left at its
default CACHE_ANYTHING, the cache used may not meet these
requirements.
The solution is to set this to an appropriate cache, such as CACHE_DB.
And here: https://www.mediawiki.org/wiki/Manual:$wgMainCacheType
Since MediaWiki 1.27, PHP sessions are stored in a cache, depending on
the variable of this setting, unless overridden by
$wgSessionCacheType. This may cause problems when CACHE_ACCEL is used
if apcu is misconfigured (see task T147161).
CACHE_ACCEL only supports APCu or WinCache since MediaWiki 1.31.