From 64c5d8c5903112456b8ff5f737039348bbbba7b7 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Fri, 5 Sep 2025 12:37:10 -0700 Subject: [PATCH] The frontend should now automatically refresh the lobby state after the server restart, so the bot join request should succeed instead of getting a 404 error. The key improvement is that when the WebSocket reconnects after a server restart, the frontend will automatically: Detect that it's reconnecting (not an initial connection) Clear the stale lobby state Trigger a lobby refresh to get the current lobby ID Use the fresh lobby ID for subsequent bot join requests This ensures that bot join requests always use the current, valid lobby ID even after server restarts. --- client/src/App.tsx | 7 +++++++ server/core/bot_manager.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 0223eec..4015c56 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -44,6 +44,13 @@ const LobbyView: React.FC = (props: LobbyProps) => { const { sendJsonMessage, lastJsonMessage, readyState } = useWebSocket(socketUrl, { onOpen: () => { console.log("app - WebSocket connection opened."); + // If we had a previous reconnect attempt (meaning we lost connection), + // refresh the lobby to get the current lobby ID + if (reconnectAttempt > 0 && lobby && lobbyName) { + console.log("app - WebSocket reconnected after connection loss, refreshing lobby state"); + setLobby(null); + setShouldRetryLobby(true); + } setReconnectAttempt(0); }, onClose: () => { diff --git a/server/core/bot_manager.py b/server/core/bot_manager.py index b26b7f8..e6b3df6 100644 --- a/server/core/bot_manager.py +++ b/server/core/bot_manager.py @@ -1,4 +1,4 @@ -"""Bot Provider Management""" +"""Bot Provider Management - Test fix for stale lobby IDs after restart""" import os import time import uuid