Sitic added a comment.
This seems to be the recent change that causes the sudden badtoken errors Village pump (technical)#How long does it take for a session timeout? https://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_(technical)&oldid=649751259#How_long_does_it_take_for_a_session_timeout.3F:
The test fetching the edit token at the beginning and end of the run should certainly have not given you the same token each time; even fetching two tokens one second apart should give you two different tokens (but both valid) since the end of October. Since you got the same token hours apart, whatever you're using to fetch the tokens is apparently caching them rather than fetching a new one the second time.
Ideally, your bot should be able to attempt the edit, and if it gets a badtoken error it should automatically fetch a fresh token and retry the edit.
As for the time it takes, the configuration is currently using the default of 1 hour for $wgObjectCacheSessionExpiry. I don't see any recent changes to the timeout, but I do see there was this recent change to session handling that probably made page views no longer reset the session timer. Anomieā 13:05, 3 March 2015 (UTC)
TASK DETAIL https://phabricator.wikimedia.org/T89702
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Sitic Cc: Mpaa, XZise, Aklapper, Sitic, jayvdb, pywikipedia-bugs