Fix action_log duplicate key: increment NextActionSequence before serializing

SaveStateAsync was serializing GameState BEFORE incrementing NextActionSequence,
so the written StateJson always had the pre-increment value. Every subsequent
request read the same NextActionSequence and computed the same SequenceNumber,
causing duplicate key violations on IX_action_logs_GameSessionId_SequenceNumber
even in purely sequential scenarios (e.g. P2 places then P1 places).

Fix: increment NextActionSequence first, then serialize, so the persisted JSON
always reflects the sequence number that was just consumed.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-07 18:30:26 -05:00
co-authored by Claude Happy
parent ece3eaa3be
commit 0af6b61999
@@ -64,9 +64,8 @@ internal abstract class GameHandlerBase
string? payloadJson,
CancellationToken ct)
{
var seqNum = state.NextActionSequence++; // increment before serialize so the saved JSON reflects the consumed number
session.StateJson = GameEngine.Serialize(state);
var seqNum = state.NextActionSequence++;
gameDb.ActionLogs.Add(new GameActionLog
{
GameSessionId = session.Id,