Skip to content

fix(gamestore): only remove inactive games and notify the chat - #118

Merged
d-Rickyy-b merged 1 commit into
masterfrom
claude/project-thread-gbpez2-stale-games
Oct 8, 2026
Merged

d-Rickyy-b merged 1 commit into
masterfrom
claude/project-thread-gbpez2-stale-games

Conversation

@d-Rickyy-b

Copy link
Copy Markdown
Owner

Requested by Rico · project thread

Before: the stale-game cleaner removed every game created more than 10 minutes ago, even games still being played. The chat wasn't told, so players' next button press just said "There is no created game!". The cleaner also iterated the game dict from the JobQueue thread while handlers could add or remove games, which can raise RuntimeError: dictionary changed size during iteration.

After: only games where nothing happened for 10 minutes are removed. The chat gets a message that the game ended because of inactivity and can /start a new one.

How:

  • BlackJackGame has a new last_activity timestamp. It is updated when a player joins, the game starts, a card is drawn, or the turn moves to the next player.
  • GameStore.cleanup_stale_games checks last_activity, iterates over a copy of the games, and returns the removed chat ids.
  • The job in bot.py sends each of those chats the new game_ended_inactive string. I added English and German versions; other languages fall back to English. Send errors, such as when the bot was blocked, are logged and don't stop the loop.
  • Games removed for inactivity still don't count towards anyone's stats, same as before.
  • New tests in blackjackbot/tests/gamestore_test.py cover both cases: an inactive game is removed, and an old game that is still active is kept.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5


Generated by Claude Code

@d-Rickyy-b d-Rickyy-b self-assigned this Oct 8, 2026
@coveralls

coveralls commented Oct 8, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 71.505% (+1.1%) from 70.383% — claude/project-thread-gbpez2-stale-games into master

The stale game cleaner measured a game's age from its creation, so any
game older than 10 minutes was removed, even while it was being played.
The chat was never told, and the cleaner iterated the game dict from the
job queue thread while handlers could modify it.

Games now track their last activity (joining, starting, drawing, next
player) and the cleaner removes games that have been inactive for 10
minutes. It iterates over a copy of the games and returns the removed
chat ids, so the job can notify each chat with a translated message.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KouGQtM6VBedfBdNr8WFX5
@d-Rickyy-b
d-Rickyy-b force-pushed the claude/project-thread-gbpez2-stale-games branch from 9068308 to 3144087 Compare October 8, 2026 21:40
@d-Rickyy-b
d-Rickyy-b merged commit 6ee137d into master Oct 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants