CLAUDE: Fix batter not advancing after plays

Root cause: WebSocket handler had stale state reference after
resolve_manual_play() completed. The handler's state object still had
the old batter index, and calling state_manager.update_state()
overwrote the game engine's updated state.

Fix: Re-fetch state from state_manager AFTER resolve_manual_play()
returns, ensuring we get the state with the advanced batter index.

Also improved logging in _prepare_next_play() to show batting_order
for easier debugging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-11-28 22:38:10 -06:00
parent 364c5149a4
commit 450ef830dc
2 changed files with 12 additions and 8 deletions

View File

@ -989,11 +989,10 @@ class GameEngine:
if state.on_third:
state.current_on_base_code |= 4 # Bit 2: third base
logger.debug(
f"Prepared next play: batter={state.current_batter.lineup_id}, "
f"pitcher={state.current_pitcher.lineup_id if state.current_pitcher else None}, "
f"catcher={state.current_catcher.lineup_id if state.current_catcher else None}, "
f"on_base_code={state.current_on_base_code}"
logger.info(
f"Prepared next play: batter lineup_id={state.current_batter.lineup_id}, "
f"batting_order={state.current_batter.batting_order}, "
f"pitcher={state.current_pitcher.lineup_id if state.current_pitcher else None}"
)
async def _batch_save_inning_rolls(self, game_id: UUID) -> None:

View File

@ -546,6 +546,11 @@ def register_handlers(sio: AsyncServer, manager: ConnectionManager) -> None:
hit_location=submission.hit_location,
)
# CRITICAL: Re-fetch state AFTER resolve_manual_play completes
# The game engine updates state (advances batter, etc.) during resolution.
# Using the old state reference would overwrite those updates!
state = state_manager.get_state(game_id)
if state:
# Clear pending roll only AFTER successful validation (one-time use)
state.pending_manual_roll = None
state_manager.update_state(game_id, state)