def get_max_valid_indicis(track, current_index):
    """
    Find the invalid timestep and get the trajectory before that step
    """
    states = track["state"]
    assert states["valid"][current_index], "Current index should be valid"
    end = len(states["valid"])
    for i, valid in enumerate(states["valid"][current_index + 1:], current_index + 1):
        if not valid:
            end = i
            break
    return current_index, end

    Find the invalid timestep and get the trajectory before that step
    
metadrive/scenario/parse_object_state.py