From 0af6b61999d36083b0d2ac5b52a91fce9c7a9c6c Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 7 Mar 2026 18:30:26 -0500 Subject: [PATCH] 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 Co-Authored-By: Happy --- Server/src/SOR.Game/Handlers/GameHandlerBase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Server/src/SOR.Game/Handlers/GameHandlerBase.cs b/Server/src/SOR.Game/Handlers/GameHandlerBase.cs index bb6dc2a..0d014c5 100644 --- a/Server/src/SOR.Game/Handlers/GameHandlerBase.cs +++ b/Server/src/SOR.Game/Handlers/GameHandlerBase.cs @@ -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,