From 2a37f9074670e1c19592ff43b644690c479c25b3 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 31 Mar 2026 13:25:09 -0400 Subject: [PATCH] Add 20-second sync watchdog to fix random hung init screen If sync_complete or sync_failed never fires (e.g. background refresh _is_syncing guard eats the start_sync call and signals were already emitted before init_screen connected them, or a server request is in-flight with no reply), the player was silently stranded with no retry path and had to relaunch. Adds a SYNC_TIMEOUT_SEC = 20 watchdog timer started in _do_sync() and reset on each sync_progress page. If it fires, surfaces the retry button with a "Timed out" message. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/init/init_screen.gd | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Client/origin-client/scenes/init/init_screen.gd b/Client/origin-client/scenes/init/init_screen.gd index 39065e1..537a1aa 100644 --- a/Client/origin-client/scenes/init/init_screen.gd +++ b/Client/origin-client/scenes/init/init_screen.gd @@ -14,6 +14,8 @@ const PLATFORM := "web" # TODO: detect at runtime for native builds. ## Seconds before we give up waiting for version.check and proceed to sync. const VERSION_CHECK_TIMEOUT_SEC := 8.0 +## Seconds of no sync progress before we give up and show the retry button. +const SYNC_TIMEOUT_SEC := 20.0 @onready var status_label : Label = %StatusLabel @onready var progress_bar : ProgressBar = %ProgressBar @@ -29,6 +31,8 @@ var _version_gen : int = 0 var _expected_total : int = 1 ## Tween used for the indeterminate pulse while checking for updates. var _pulse_tween : Tween = null +## SceneTree timer that fires if the sync hangs with no progress. +var _sync_timeout : SceneTreeTimer = null # ── Lifecycle ───────────────────────────────────────────────────────────────── @@ -141,6 +145,7 @@ func _do_sync() -> void: else: _set_status("Downloading card database…") progress_bar.value = 5.0 + _start_sync_timeout() ContentCache.start_sync() BoardTemplateCache.fetch() # parallel fire-and-forget; ready before lobby screen opens @@ -150,9 +155,11 @@ func _on_sync_progress(fetched_total: int) -> void: _expected_total = max(_expected_total, fetched_total) var pct := 5.0 + 80.0 * float(fetched_total) / float(_expected_total) progress_bar.value = clampf(pct, 5.0, 85.0) + _start_sync_timeout() # reset on each page received so we time out from last activity func _on_sync_complete(_total: int) -> void: + _sync_timeout = null progress_bar.value = 90.0 _check_active_session() @@ -217,6 +224,7 @@ func _go_to_main() -> void: func _on_sync_failed(error: String) -> void: + _sync_timeout = null _stop_pulse() _set_status("Sync failed: %s" % error) retry_btn.visible = true @@ -242,3 +250,16 @@ func _stop_pulse() -> void: if _pulse_tween: _pulse_tween.kill() _pulse_tween = null + + +## Start (or restart) the sync watchdog. If no progress arrives within +## SYNC_TIMEOUT_SEC, surface the retry button so the user isn't stranded. +func _start_sync_timeout() -> void: + _sync_timeout = get_tree().create_timer(SYNC_TIMEOUT_SEC) + _sync_timeout.timeout.connect(func() -> void: + if not is_inside_tree() or _sync_timeout == null: + return + _sync_timeout = null + push_warning("InitScreen: sync timed out — showing retry") + _on_sync_failed("Timed out — tap Retry to try again."), + CONNECT_ONE_SHOT)