when going to round_end. the function for round_end should be called. why is this not happening. the state is set t round_end but the function isnt called

import { Game, GameState } from '../types';
import { startGame } from './game';
import { startNewRound } from './rounds';
import { getGame } from './utils';
import { db } from '../config';
import { calculateRoundScores } from './scoring/calculateRoundScores';

const validTransitions: Record<GameState, GameState[]> = {
    lobby: ['round_start'],
    round_start: ['song_submission'],
    song_submission: ['music_playback'],
    music_playback: ['ranking'],
    ranking: ['scoreboard'],
    scoreboard: ['round_end'],
    round_end: ['round_start', 'game_end'],
    game_end: ['lobby'],
};

const stateTransitions: Record<GameState, (gameId: string, gameData: Game, gameRef: FirebaseFirestore.DocumentReference, transaction: FirebaseFirestore.Transaction) => Promise<GameState>> = {
    lobby: async () => 'lobby',
    round_start: async (gameId, gameData, gameRef, transaction) => {
        if (gameData.currentRound === 0) {
            await startGame({ gameId, gameData, transaction });
        }
        await startNewRound({ gameId, gameData, transaction });
        return 'song_submission';
    },
    song_submission: async () => 'song_submission',
    music_playback: async () => 'music_playback',
    ranking: async () => 'ranking',
    scoreboard: async (gameId, gameData, gameRef, transaction) => {
        await calculateRoundScores({ gameId, currentRound: gameData.currentRound });
        return 'round_end';
    },
    round_end: async (gameId, gameData, gameRef, transaction) => {
        console.log("Round end", gameData.currentRound, gameData.totalRounds);
        if (gameData.currentRound >= gameData.totalRounds - 1) {
            console.log("Game ending");
            return 'game_end';
        } else {
            console.log("Starting new round");
            transaction.update(gameRef, { currentRound: gameData.currentRound + 1 });
            await startNewRound({ gameId, gameData: { ...gameData, currentRound: gameData.currentRound + 1 }, transaction });
            return 'round_start';
        }
    },
    game_end: async () => 'game_end',
};

export async function progressGame(data: { gameId: string, gameData?: Game, gameRef?: FirebaseFirestore.DocumentReference }): Promise<GameState> {
    try {
        const { gameId } = data;
        console.log('Progressing game:', { gameId });
        let { gameData, gameRef } = data;

        if (!gameData || !gameRef) {
            ({ gameData, gameRef } = await getGame(gameId));
        }

        console.log('Current game state:', gameData.state);
        const currentState = gameData.state;

        let nextState: GameState;

        await db.runTransaction(async (transaction) => {
            // Perform the state transition and get the next state
            nextState = await stateTransitions[currentState](gameId, gameData, gameRef, transaction);
            console.log('Next state:', nextState);

            // Update the game state
            transaction.update(gameRef, { state: nextState });
        });

        // Verify the state update
        const updatedGameDoc = await gameRef.get();
        const updatedGameData = updatedGameDoc.data() as Game;
        const updatedState = updatedGameData.state;

        if (updatedState !== nextState) {
            console.error(`State update failed. Expected: ${nextState}, Actual: ${updatedState}`);
            throw new Error('Failed to update game state');
        }

        console.log('Game state updated successfully:', updatedState);
        return updatedState;
    } catch (error) {
        console.error('Error progressing game:', error);
        throw error;
    }
}