From 4322732b47c1b702502fe43effe6393635fad0c0 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 1 Mar 2026 10:17:03 -0500 Subject: [PATCH] client: fix auth-expiry reconnect loop + improve error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Network.gd — drain packets before handling close (main bug fix): When the server rejects auth.hello it sends an error frame then closes the connection. Godot's WebSocketPeer.poll() can transition directly to STATE_CLOSED while the error packet sits unread in the buffer. The old code returned early on STATE_CLOSED without calling _poll_packets(), so _on_ws_closed() fired DISCONNECTED for the pending auth.hello instead of the real AUTH_FAILED. Auth kept the session token and retried forever. Fix: drain any buffered packets before _on_ws_closed(). Network.gd — fail request() immediately when not connected: Previously request() silently dropped the send but left a dangling pending entry that was never resolved until the next disconnect. Now on_error("DISCONNECTED") is called immediately, giving the caller consistent feedback and keeping _pending clean. main_screen.gd — stay on screen for DISCONNECTED auth errors: A transient network drop during auth.hello was sending the user back to the login screen unnecessarily. Only navigate to login when the session is explicitly rejected (AUTH_FAILED, ACCOUNT_LOCKED, etc.). The "● Reconnecting…" status label already handles the transient case. login_screen.gd — add missing friendly error translations: INVALID_PASSWORD / USER_NOT_FOUND → "Wrong email or password." DISPLAY_NAME_TAKEN, ACCOUNT_LOCKED, AUTH_REQUIRED, AUTH_SERVICE_UNAVAILABLE all now map to clear human-readable strings instead of falling through to the raw server message or error code. 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/Network.gd | 14 ++++++++++++++ Client/origin-client/scenes/login/login_screen.gd | 10 ++++++++-- Client/origin-client/scenes/main/main_screen.gd | 8 ++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Client/origin-client/autoloads/Network.gd b/Client/origin-client/autoloads/Network.gd index 4b2118e..b736f3c 100644 --- a/Client/origin-client/autoloads/Network.gd +++ b/Client/origin-client/autoloads/Network.gd @@ -81,6 +81,14 @@ func _process(delta: float) -> void: WebSocketPeer.STATE_CLOSED: if _state == _State.CONNECTED: + # Drain any packets the server sent just before closing (e.g. an + # auth error response followed immediately by the close frame). + # Without this, both arrive in the same poll() and we return early + # here, so _poll_packets() is skipped and _on_ws_closed() fires + # DISCONNECTED for all pending requests before the real error is + # dispatched — causing auth.hello failures to look like reconnect + # drops and keeping the session token alive indefinitely. + _poll_packets() _on_ws_closed() else: # STATE_CONNECTING → connection attempt failed _schedule_reconnect() @@ -107,6 +115,12 @@ func request( on_error: Callable = Callable()) -> int: _seq += 1 var seq := _seq + if _state != _State.CONNECTED: + # Fail immediately rather than dropping the send silently and leaving a + # dangling pending entry that never gets a response. + if on_error.is_valid(): + on_error.call("DISCONNECTED", "Not connected.") + return seq _pending[seq] = { &"on_reply": on_reply, &"on_error": on_error } _send_raw({ "type": type, "seq": seq, "payload": payload }) return seq diff --git a/Client/origin-client/scenes/login/login_screen.gd b/Client/origin-client/scenes/login/login_screen.gd index 0280ce4..6d369ae 100644 --- a/Client/origin-client/scenes/login/login_screen.gd +++ b/Client/origin-client/scenes/login/login_screen.gd @@ -113,11 +113,17 @@ func _set_enabled(enabled: bool) -> void: func _friendly_error(code: String, message: String) -> String: match code: - "INVALID_CREDENTIALS": return "Wrong email or password." + "INVALID_CREDENTIALS", \ + "INVALID_PASSWORD", \ + "USER_NOT_FOUND": return "Wrong email or password." "EMAIL_TAKEN": return "That email is already in use." + "DISPLAY_NAME_TAKEN": return "That display name is already in use." "WEAK_PASSWORD": return "Password must be at least 8 characters." "INVALID_EMAIL": return "Please enter a valid email address." - "AUTH_FAILED": return "Authentication failed. Please try again." + "ACCOUNT_LOCKED": return "Account locked. Please try again later." + "AUTH_FAILED": return "Session expired. Please sign in again." + "AUTH_REQUIRED": return "Please sign in to continue." + "AUTH_SERVICE_UNAVAILABLE": return "Server unavailable. Please try again shortly." _: return message if not message.is_empty() \ else "Something went wrong (%s)." % code diff --git a/Client/origin-client/scenes/main/main_screen.gd b/Client/origin-client/scenes/main/main_screen.gd index 52efe25..f416fba 100644 --- a/Client/origin-client/scenes/main/main_screen.gd +++ b/Client/origin-client/scenes/main/main_screen.gd @@ -47,8 +47,12 @@ func _update_status() -> void: status_label.modulate = Color(1.0, 0.8, 0.2) -func _on_auth_failed(_error_code: String, _message: String) -> void: - # Session expired or invalidated — return to login. +func _on_auth_failed(error_code: String, _message: String) -> void: + if error_code == "DISCONNECTED": + # Transient drop during auth.hello retry — stay on screen. + # _update_status() already shows "● Reconnecting…" via the disconnected signal. + return + # Session explicitly rejected (expired, revoked, locked out) — go to login. get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn")