From 7e22d875f6340ecc84e89b5324195e36955dc1d0 Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 21 May 2026 05:53:40 -0400 Subject: [PATCH] =?UTF-8?q?Fix=206:=20=5Ffetch=5Fstate=20race=20=E2=80=94?= =?UTF-8?q?=20=5Fsyncing=20guard=20and=20session-id=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add _syncing: bool flag; _fetch_state() returns immediately if a game.get_state request is already in-flight — prevents multiple concurrent full-sync requests on poor connections or reconnect bursts - _syncing cleared in both success and error callbacks, and in _clear_state() so it resets cleanly when the session ends - _apply_state_from_payload: reject responses whose sessionId doesn't match the current session_id, discarding stale full-state responses that were in-flight when the player left or started a new game Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Game.gd | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index 248e6f0..bbfb29d 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -102,6 +102,7 @@ var opponent_name : String = "" var is_spectating : bool = false var debug_output : bool = false var _state_version : int = -1 +var _syncing : bool = false # true while a game.get_state request is in-flight # ── Lifecycle ───────────────────────────────────────────────────────────────── @@ -117,6 +118,7 @@ func _clear_state() -> void: opponent_name = "" is_spectating = false _state_version = -1 + _syncing = false ## Called on every auth_success (initial login AND reconnects). @@ -312,10 +314,16 @@ func send_ready() -> void: func _fetch_state() -> void: + if _syncing: + return + _syncing = true Network.request("game.get_state", { "sessionId": session_id }, - func(_t: String, p: Variant) -> void: _apply_state_from_payload(p), - func(_c: String, _m: String) -> void: pass) + func(_t: String, p: Variant) -> void: + _syncing = false + _apply_state_from_payload(p), + func(_c: String, _m: String) -> void: + _syncing = false) func send_draw() -> void: @@ -482,6 +490,13 @@ func _apply_state_from_payload(p: Variant) -> void: if debug_output: print("[Game] _apply_state_from_payload: no 'state' key in payload ", JSON.stringify(p)) return + # Discard stale responses that belong to a session we have already left. + var response_sid: String = str(s.get("sessionId", "")) + if not session_id.is_empty() and not response_sid.is_empty() \ + and response_sid != session_id: + if debug_output: + print("[Game] _apply_state_from_payload: ignored stale response for session ", response_sid) + return _state_version = int(s.get("stateVersion", -1)) if debug_output: print("[Game] state applied phase=", s.get("phase","?"),