broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(phase, events, seed):
    payload = list(range(seed, seed * 2 + 2))
    r = {'credits': int(phase=='usable'), 'lease': seed, 'inflight': [seed], 'queue': payload[:], 'stale_records': [], 'sent': []}
    frames = []
    observed = []
    table = {('none', 'grant'): ('usable', 'record_grant'), ('usable', 'spend_last'): ('exhausted', 'send_one'), ('exhausted', 'payload'): ('exhausted', 'backpressure'), ('usable', 'revoke'): ('usable', 'continue'), ('revoked', 'inflight_ack'): ('revoked', 'retire_inflight'), ('revoked', 'new_grant'): ('usable', 'replace_lease'), ('usable', 'lease_expired'): ('expired', 'stop_new_sends'), ('expired', 'old_grant'): ('expired', 'reject_stale'), ('exhausted', 'refresh'): ('usable', 'record_grant'), ('none', 'ack'): ('none', 'reject_unsolicited')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_grant':
            r['credits']=len(payload)
        elif action == 'send_one':
            r['credits']-=1; r['sent'].append(r['queue'].pop(0)) if r['queue'] else None
        elif action == 'backpressure':
            frames.append(['BLOCKED',len(r['queue'])])
        elif action == 'stop_new_sends':
            r['credits']=0
        elif action == 'retire_inflight':
            r['inflight']=[]
        elif action == 'replace_lease':
            r['lease']=seed+1; r['credits']=len(payload)
        elif action == 'reject_stale':
            frames.append(['STALE',seed])
        elif action == 'reject_unsolicited':
            frames.append(['UNSOLICITED_ACK',seed])
        elif action == 'send_all':
            r['sent'].extend(r['queue']); r['queue']=[]
        elif action == 'drop':
            r['queue']=[]
        elif action == 'discard_inflight':
            r['inflight']=[]; r['queue']=[]
        elif action == 'grant_credit':
            r['credits']+=1
        elif action == 'merge_lease':
            r['credits']+=len(payload)
        elif action == 'record_ack':
            r['stale_records'].append(seed)
        elif action == 'double_grant':
            r['credits']=2*len(payload)
        elif action == 'send_probe':
            r['sent'].append('probe')
        elif action == 'continue':
            r['sent'].extend(r['queue'])
        else:
            if action not in ("wait", "ignore", "keep", "retain", "keep_peer", "keep_offer", "keep_hold", "keep_batch", "retain_staging", "keep_staging", "keep_local_owner", "keep_old_session", "keep_address", "keep_old_expiry", "ignore_conflict", "keep_service", "keep_subscription", "retain_shadow", "keep_live", "keep_suspicion", "keep_roles", "keep_staged"):
                frames.append([action, payload[:]])
        observed.append(json.loads(json.dumps({"phase": phase, "registers": r, "frames": frames})))
    return observed
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 3]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 2, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 1]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 1]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 3, 'lease': 2, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': [['BLOCKED', 2]]}, {'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': [['BLOCKED', 2]]}, {'phase': 'exhausted', 'registers': {'credits': 2, 'lease': 1, 'inflight': [1], 'queue': [3], 'stale_records': [], 'sent': [1, 2]}, 'frames': [['BLOCKED', 2]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 4]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 3, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 2]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 2]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 3, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'exhausted', 'registers': {'credits': 3, 'lease': 2, 'inflight': [2], 'queue': [4, 5], 'stale_records': [], 'sent': [2, 3]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [4, 5], 'stale_records': [], 'sent': [2, 3]}, 'frames': [['BLOCKED', 3]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 5]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 3]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 3]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'exhausted', 'registers': {'credits': 4, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 6]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 4]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 4]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant', 'spend_last'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 5, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired', 'old_grant'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'exhausted', 'registers': {'credits': 5, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5], ['STALE', 4]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 7]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 5]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 5]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant', 'spend_last', 'refresh'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 6, 'lease': 6, 'inflight': [], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired', 'old_grant', 'old_grant'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'exhausted', 'registers': {'credits': 6, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6], ['STALE', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6], ['STALE', 5], ['STALE', 5]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(phase, events, seed):
    payload = list(range(seed, seed * 2 + 2))
    r = {'credits': int(phase=='usable'), 'lease': seed, 'inflight': [seed], 'queue': payload[:], 'stale_records': [], 'sent': []}
    frames = []
    observed = []
    table = {('none', 'grant'): ('usable', 'record_grant'), ('usable', 'spend_last'): ('exhausted', 'send_one'), ('exhausted', 'payload'): ('exhausted', 'backpressure'), ('usable', 'revoke'): ('revoked', 'discard_inflight'), ('revoked', 'inflight_ack'): ('revoked', 'retire_inflight'), ('revoked', 'new_grant'): ('usable', 'replace_lease'), ('usable', 'lease_expired'): ('expired', 'stop_new_sends'), ('expired', 'old_grant'): ('expired', 'reject_stale'), ('exhausted', 'refresh'): ('usable', 'record_grant'), ('none', 'ack'): ('none', 'reject_unsolicited')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_grant':
            r['credits']=len(payload)
        elif action == 'send_one':
            r['credits']-=1; r['sent'].append(r['queue'].pop(0)) if r['queue'] else None
        elif action == 'backpressure':
            frames.append(['BLOCKED',len(r['queue'])])
        elif action == 'stop_new_sends':
            r['credits']=0
        elif action == 'retire_inflight':
            r['inflight']=[]
        elif action == 'replace_lease':
            r['lease']=seed+1; r['credits']=len(payload)
        elif action == 'reject_stale':
            frames.append(['STALE',seed])
        elif action == 'reject_unsolicited':
            frames.append(['UNSOLICITED_ACK',seed])
        elif action == 'send_all':
            r['sent'].extend(r['queue']); r['queue']=[]
        elif action == 'drop':
            r['queue']=[]
        elif action == 'discard_inflight':
            r['inflight']=[]; r['queue']=[]
        elif action == 'grant_credit':
            r['credits']+=1
        elif action == 'merge_lease':
            r['credits']+=len(payload)
        elif action == 'record_ack':
            r['stale_records'].append(seed)
        elif action == 'double_grant':
            r['credits']=2*len(payload)
        elif action == 'send_probe':
            r['sent'].append('probe')
        elif action == 'continue':
            r['sent'].extend(r['queue'])
        else:
            if action not in ("wait", "ignore", "keep", "retain", "keep_peer", "keep_offer", "keep_hold", "keep_batch", "retain_staging", "keep_staging", "keep_local_owner", "keep_old_session", "keep_address", "keep_old_expiry", "ignore_conflict", "keep_service", "keep_subscription", "retain_shadow", "keep_live", "keep_suspicion", "keep_roles", "keep_staged"):
                frames.append([action, payload[:]])
        observed.append(json.loads(json.dumps({"phase": phase, "registers": r, "frames": frames})))
    return observed
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 3]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 2, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 1]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 1]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant'], [{'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 1, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 3, 'lease': 2, 'inflight': [], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': [['BLOCKED', 2]]}, {'phase': 'usable', 'registers': {'credits': 3, 'lease': 1, 'inflight': [1], 'queue': [2, 3], 'stale_records': [], 'sent': [1]}, 'frames': [['BLOCKED', 2]]}, {'phase': 'exhausted', 'registers': {'credits': 2, 'lease': 1, 'inflight': [1], 'queue': [3], 'stale_records': [], 'sent': [1, 2]}, 'frames': [['BLOCKED', 2]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 1, 'inflight': [1], 'queue': [1, 2, 3], 'stale_records': [], 'sent': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 4]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 3, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 2]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 2]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke'], [{'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 2, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 3, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [3, 4, 5], 'stale_records': [], 'sent': [2]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'exhausted', 'registers': {'credits': 3, 'lease': 2, 'inflight': [2], 'queue': [4, 5], 'stale_records': [], 'sent': [2, 3]}, 'frames': [['BLOCKED', 3]]}, {'phase': 'usable', 'registers': {'credits': 4, 'lease': 2, 'inflight': [2], 'queue': [4, 5], 'stale_records': [], 'sent': [2, 3]}, 'frames': [['BLOCKED', 3]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 2, 'inflight': [2], 'queue': [2, 3, 4, 5], 'stale_records': [], 'sent': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 5]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 3]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 3]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant'], [{'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 3, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 4, 'inflight': [], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [4, 5, 6, 7], 'stale_records': [], 'sent': [3]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'exhausted', 'registers': {'credits': 4, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'usable', 'registers': {'credits': 5, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [5, 6, 7], 'stale_records': [], 'sent': [3, 4]}, 'frames': [['BLOCKED', 4]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 3, 'inflight': [3], 'queue': [3, 4, 5, 6, 7], 'stale_records': [], 'sent': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 6]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 4]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 4]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant', 'spend_last'], [{'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 4, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 5, 'inflight': [], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 5, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired', 'old_grant'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [5, 6, 7, 8, 9], 'stale_records': [], 'sent': [4]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'exhausted', 'registers': {'credits': 5, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'usable', 'registers': {'credits': 6, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [6, 7, 8, 9], 'stale_records': [], 'sent': [4, 5]}, 'frames': [['BLOCKED', 5], ['STALE', 4]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 4, 'inflight': [4], 'queue': [4, 5, 6, 7, 8, 9], 'stale_records': [], 'sent': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('none/grant', 'none', ['grant'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/spend_last', 'usable', ['spend_last'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}]), ('exhausted/payload', 'exhausted', ['payload'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['BLOCKED', 7]]}]), ('usable/revoke', 'usable', ['revoke'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/inflight_ack', 'revoked', ['inflight_ack'], [{'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('revoked/new_grant', 'revoked', ['new_grant'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('usable/lease_expired', 'usable', ['lease_expired'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('expired/old_grant', 'expired', ['old_grant'], [{'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['STALE', 5]]}]), ('exhausted/refresh', 'exhausted', ['refresh'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}]), ('none/ack', 'none', ['ack'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['UNSOLICITED_ACK', 5]]}]), ('ordered trace 0', 'none', ['grant', 'revoke', 'inflight_ack', 'new_grant', 'revoke', 'new_grant', 'spend_last', 'refresh'], [{'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 5, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'revoked', 'registers': {'credits': 0, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 6, 'lease': 6, 'inflight': [], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 6, 'inflight': [], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}]), ('ordered trace 3', 'usable', ['spend_last', 'payload', 'refresh', 'spend_last', 'refresh', 'lease_expired', 'old_grant', 'old_grant'], [{'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': []}, {'phase': 'exhausted', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'exhausted', 'registers': {'credits': 6, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'usable', 'registers': {'credits': 7, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6], ['STALE', 5]]}, {'phase': 'expired', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [7, 8, 9, 10, 11], 'stale_records': [], 'sent': [5, 6]}, 'frames': [['BLOCKED', 6], ['STALE', 5], ['STALE', 5]]}]), ('empty input', 'none', [], []), ('unknown event', 'none', ['unsupported'], [{'phase': 'none', 'registers': {'credits': 0, 'lease': 5, 'inflight': [5], 'queue': [5, 6, 7, 8, 9, 10, 11], 'stale_records': [], 'sent': []}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
While usable, event revoke produces usable/continue instead of revoked/stop_new_sends.

For the stipulated Receiver-issued transmission-credit lease controller, initialize the explicitly shown resource registers from seed (1..5), then consume classified events sequentially. After each event return a deep snapshot of phase, resource registers, and cumulative emitted control frames. The explicit ten phase/event rules and their resource effects define admission and response semantics. Unlisted events preserve phase and emit rejection. Payload is the consecutive integers seed through 2*seed+1. Empty event input returns no observations.

split: open-access