Symptom
In the live build, some matches stopped right before the results. The phase timer sat at 00:00 and the results screen never came up, for everyone at the table.
The host phone kept calling ResolveDayEnd every ~32 seconds, and Cloud Code answered match_history_timestamp_required every single time. It happened in two matches, on 25 and 26 November, with the host alive and with the host dead.
Investigation
The match end runs in Cloud Code as a workflow of stages, and the results are only published to the lobby after the Archive stage finishes. Retrying is safe by design: each stage checks what was already done. So the real question was why the retry failed the same way every time.
I reproduced the loop in a test on the development branch. The key was a fake Cloud Save that hands values back exactly like the SDK does: through Newtonsoft with its default settings. With a friendlier fake, the bug does not exist.
Cause
Two bugs stacked on top of each other:
- The first attempt wrote the match summary, then failed while adding the match to each player's history. When Newtonsoft reads JSON, it turns ISO-8601 strings into dates by default; a timestamp read back came out in the server's culture format (
11/26/2026 14:26:11, noT, no time zone) and was rejected. (Fixed on its own in #898.) - On every retry the summary already existed, so the server replayed the end of the archive using the summary read back from Cloud Save, through the same date conversion.
EndedAtUtcarrived in culture format, the history store rejected it, the stage threw, and the results were never published.
A deterministic error inside a stage that gates the UI, plus an automatic retry, is an infinite loop.
Fix
Every summary read in the archiver now goes through one helper that parses JSON with DateParseHandling.None, so the timestamps stay in their ISO round-trip form.
And player history became best-effort. The summary is the source of truth and the rewards were already paid, so a failed history append is logged as an error and the archive goes on. Cleanup errors still propagate.
// History is secondary to finishing the match: this stage gates the
// results, so rethrowing a deterministic error would fail every retry.
try
{
await _historyStore.AppendOnceAsync(ctx, playerId, matchScope, summary.EndedAtUtc);
}
catch (Exception ex)
{
_logger.LogError(ex, "History append failed for {PlayerId}; continuing.", playerId);
}Three regression tests reproduce both defects and failed before the change. The hotfix went to the main branch (the date fix from #898 plus this one, 1,309 server tests passing), with a twin pull request to the development branch.
How to avoid it
- A retry only fixes transient errors. If a stage that gates the UI can fail deterministically, decide what is essential (the summary, the rewards) and what is best-effort (the detailed history).
- Serializer defaults are part of your data contract. With Newtonsoft, use
DateParseHandling.Nonewhenever timestamps make a round trip as text. - Test doubles must lie like the real thing. The fake storage now serializes values the way the SDK does, or the test passes while production loops.
- The same error every 32 seconds is a clue. Repetition with an identical code means deterministic, not flaky.