Skip to content

Conversation

Copy link

Copilot AI commented Dec 21, 2025

Refactored three while True: loops in the mirror selection and fetching logic to use explicit bounded iterations, eliminating potential infinite loops.

Changes

select_mirror() in dynamic_round_robin.py:

  • Replaced while True: with for _ in range(max_iterations) where max_iterations is computed from the weighted round-robin algorithm parameters
  • Added RuntimeError when max iterations exceeded (indicates algorithm bug)

fetch_beatmap_zip_data() and fetch_beatmap_background_image() in __init__.py:

  • Replaced while True: with bounded loop using max_iterations = max_attempts * 2
  • Track actual_attempts separately from loop iterations to handle skipped iterations when same mirror is selected consecutively
  • Early exit when actual_attempts >= max_attempts

Before/After

# Before
while True:
    mirror = selector.select_mirror()
    if mirror is prev_mirror:
        continue
    num_attempts += 1
    if num_attempts > max_attempts:
        return None
    # ... fetch logic

# After  
max_iterations = max_attempts * 2
actual_attempts = 0
for _ in range(max_iterations):
    if actual_attempts >= max_attempts:
        break
    mirror = selector.select_mirror()
    if mirror is prev_mirror:
        continue
    actual_attempts += 1
    # ... fetch logic

All functionality preserved with explicit termination guarantees.

Original prompt

Please refactor the repo to use more static patterns, e.g. allowing us to remove while True: for the weighting


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 21, 2025 00:45
Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com>
Co-authored-by: cmyui <17343631+cmyui@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor repo to use more static patterns Replace while True loops with bounded iteration patterns Dec 21, 2025
Copilot AI requested a review from cmyui December 21, 2025 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants