# Excerpt — promptpotter/application/runner/loop.py
# The single async loop at the heart of every optimization cycle.

while clean_rounds < max_rounds and round_num < HARD_CAP:
    # L1 — generate a population of candidates and score them.
    round_result = await execute_round(
        cycle, round_num, round_eval_data, cb,
        degradation_checks=round_checks, skip_critique=sweep,
    )
    trial_dict = cycle.absorb_round(round_result, round_num)

    if round_result.escalation_signal:
        # The round stalled — close it out and escalate: L2 refines the
        # task framing, and if that stalls too, L3 replans the strategy.
        await close_round(cycle, round_result, trial_dict, round_num, session, cb)
        await escalate_or_stop(cycle, config, session, round_num, cb)
        round_num += 1
        continue

    # A clean round — record it and carry the improvement forward.
    await post_round(cycle, round_result, trial_dict, round_num, config, session, cb)
    round_num += 1
    clean_rounds += 1
