def fix_nextprog(forest_halos):
    """
    Walks the descendants of a single forest to generate the `NextProgenitor`
    field.

    Parameters
    ----------

    forest_halos : Numpy structured array with data structure defined by
                  :py:mod:`astro3D.genesis.utils.treefrog_to_lhalo.get_LHalo_datastruct`
        The halos within a single forest.

    Returns
    ----------

    forest_halos : Numpy structured array with data structure defined by
                  :py:mod:`astro3D.genesis.utils.treefrog_to_lhalo.get_LHalo_datastruct`
        The forest halos with updated ``NextProgenitor`` field.
    """
    all_descendants = forest_halos['Descendant'][:]
    for ii, d in enumerate(all_descendants):
        if d == ii:
            continue
        curr = forest_halos['FirstProgenitor'][d]
        if curr == ii:
            continue
        while forest_halos['NextProgenitor'][curr] != -1:
            curr = forest_halos['NextProgenitor'][curr]
        assert forest_halos['NextProgenitor'][curr] == -1
        forest_halos['NextProgenitor'][curr] = ii
    return forest_halos
