Skip to content
C.W.K.
Stream
Lesson 04 of 04 · published

Every Loop Has a Cap

~11 min · bounded-loops, failure, recovery, termination

Level 0Cold Iron
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Every Loop Has a Cap

Anvil may iterate, but no loop becomes an unbounded promise. Repeating modes carry hard max_rounds or max_legs values. Each seat turn gets bounded retries with backoff; a contestant that stays dead becomes withdrawn, and the remaining field continues.

Degradation is explicit rather than fatal by default. An Arena reduced to one surviving artifact becomes decided-by-default; a field with no artifact aborts. A judge that remains dead after bounded retries is replaced by a fresh random draw from the remaining participants. If the replacement pool empties, ballots that already landed still count, so the bench may continue with one judge; if nobody can produce a judgment, the run aborts.

Relay's leg cap and every round cap belong to the mode contract and trail. A “no meaningful improvement” declaration can end Relay early, while a hard cap prevents any quality threshold from extending it forever.

Rematch is not another hidden retry. Dad creates a fresh linked run explicitly, preserving the finalized or aborted predecessor and its full trail. Abort remains the general live-run exit and never deletes the failed history.

Bound the attempt, then record the degradation. Empty-field abort, withdrawal, single-judge continuation, decided-by-default, and fresh rematch are distinct outcomes.

Code

Bounded failure paths·python
MAX_ROUNDS = 3


def resolve(artifacts, ballots):
    """Every ending has a name. None of them is "quietly failed"."""
    if not artifacts:
        return "aborted:empty_field"
    if len(artifacts) == 1:
        return "decided_by_default"        # and recorded as such
    if not ballots:
        return "aborted:no_judgment"
    return "decided"


def run_rounds(field, judge):
    trail = []
    for rnd in range(1, MAX_ROUNDS + 1):   # the cap is inside the loop
        field = [a for a in field if judge(a)]
        trail.append({"round": rnd, "survivors": len(field)})
        if len(field) <= 1:
            break
    return field, trail


assert resolve([], []) == "aborted:empty_field"
assert resolve(["A"], []) == "decided_by_default"
assert resolve(["A", "B"], []) == "aborted:no_judgment"

survivors, trail = run_rounds(["A", "B", "C", "D"], lambda a: a < "C")
print(survivors, trail)

External links

Exercise

Trace failure for a two-contestant Arena when one contestant withdraws and two drawn judges fail until no replacement pool remains.
Hint
The field continues, the bench degrades honestly, and every step is recorded.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.