Fix custom lobby staying in Started state after game ends

Add CustomLobbyStatus.Completed; in FinalizeGameAsync, query the lobby
linked via GameSessionId and set Status=Completed when the game ends.
This removes finished games from the active-games browser (list_active
only returns Started lobbies) and from the admin "active" count.

Admin page: add Completed filter option, dark badge, include Started
lobbies in the always-loaded set so stale in-progress games are visible.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-19 13:27:39 -04:00
co-authored by Claude Happy
parent efcd693d60
commit 6fd1b07ab2
3 changed files with 14 additions and 2 deletions
@@ -161,6 +161,13 @@ internal abstract class GameHandlerBase
session.WinCondition = winCondition;
session.EndedAt = DateTimeOffset.UtcNow;
// Mark the linked custom lobby as Completed so it disappears from the active-games
// browser. Ranked sessions have no linked lobby; the query safely returns null.
var linkedLobby = await gameDb.CustomLobbies
.FirstOrDefaultAsync(l => l.GameSessionId == session.Id, ct);
if (linkedLobby != null && linkedLobby.Status == CustomLobbyStatus.Started)
linkedLobby.Status = CustomLobbyStatus.Completed;
// Save game session status FIRST — this must succeed before we touch ELO.
// If identity DB fails below, the session is still correctly marked Completed
// so players won't be stuck in a ghost match on next login.