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 = {'first': seed, 'second': seed+1, 'roles': {str(seed):'initiator',str(seed+1):'responder'} if phase in ('paired','one_ready','active') else {}, 'ready': [seed] if phase in ('one_ready','active') else [], 'started': [], 'waiting': []}
    frames = []
    observed = []
    table = {('empty', 'first_arrival'): ('waiting', 'record_first'), ('waiting', 'second_arrival'): ('paired', 'assign_complementary_roles'), ('paired', 'first_ready'): ('one_ready', 'record_ready'), ('one_ready', 'second_ready'): ('active', 'start_both'), ('waiting', 'first_withdraws'): ('empty', 'remove_first'), ('paired', 'partner_withdraws'): ('waiting', 'notify_requeue_survivor'), ('active', 'third_arrival'): ('paired', 'replace_partner'), ('one_ready', 'duplicate_ready'): ('one_ready', 'ack_existing'), ('empty', 'ready'): ('empty', 'reject_unpaired'), ('active', 'both_done'): ('empty', 'release_pair')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_first':
            r['waiting'].append(seed)
        elif action == 'assign_complementary_roles':
            r['roles']={str(seed):'initiator',str(seed+1):'responder'}
        elif action == 'record_ready':
            r['ready'].append(seed)
        elif action == 'start_both':
            r['started']=[seed,seed+1]
        elif action == 'remove_first':
            r['first']=None; r['waiting']=[]
        elif action == 'notify_requeue_survivor':
            r['waiting']=[seed]; r['second']=None; frames.append(['PARTNER_LEFT',seed])
        elif action == 'reject_full':
            frames.append(['PAIR_FULL',seed+2])
        elif action == 'ack_existing':
            frames.append(['READY_ACK',seed])
        elif action == 'reject_unpaired':
            frames.append(['UNPAIRED',seed])
        elif action == 'release_pair':
            r['first']=None; r['second']=None; r['roles']={}; r['ready']=[]
        elif action == 'notify_pair':
            frames.append(['PAIRED',seed,None])
        elif action == 'reject':
            frames.append(['REJECT',seed])
        elif action == 'replace_first':
            r['first']=seed+1
        elif action == 'assign_same_role':
            r['roles']={str(seed):'initiator',str(seed+1):'initiator'}
        elif action == 'forget_second':
            r['second']=None
        elif action == 'start_second_only':
            r['started']=[seed+1]
        elif action == 'requeue_departed':
            r['waiting']=[seed+1]
        elif action == 'replace_partner':
            r['second']=seed+2
        elif action == 'assign_third_role':
            r['roles'][str(seed+2)]='observer'
        elif action == 'clear_ready':
            r['ready']=[]
        elif action == 'assign_roles':
            r['roles']={str(seed):'initiator',str(seed+1):'responder'}
        elif action == 'keep_roles':
            r['first']=None; r['second']=None
        elif action == 'keep_first':
            r['first']=seed
        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: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [1, 2], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': None, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': [['PARTNER_LEFT', 1]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 3]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 1]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 1]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [1, 2], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [1, 2], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [1, 2], 'waiting': [1]}, 'frames': [['READY_ACK', 1]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 1]]}])], 2: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [2, 3], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': None, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': [['PARTNER_LEFT', 2]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 4]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 2]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 2]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': [2]}, 'frames': [['READY_ACK', 2]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 2]]}])], 3: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [3, 4], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': None, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': [['PARTNER_LEFT', 3]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 5]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 3]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 3]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': [3]}, 'frames': [['READY_ACK', 3]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': [3]}, 'frames': [['READY_ACK', 3]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 3]]}])], 4: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [4, 5], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': None, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': [['PARTNER_LEFT', 4]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 6]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 4]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 4]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': [4]}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': [4]}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 4]]}])], 5: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [5, 6], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': None, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': [['PARTNER_LEFT', 5]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 7]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 5]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 5]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 5]]}])]}
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)

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 = {'first': seed, 'second': seed+1, 'roles': {str(seed):'initiator',str(seed+1):'responder'} if phase in ('paired','one_ready','active') else {}, 'ready': [seed] if phase in ('one_ready','active') else [], 'started': [], 'waiting': []}
    frames = []
    observed = []
    table = {('empty', 'first_arrival'): ('waiting', 'record_first'), ('waiting', 'second_arrival'): ('paired', 'assign_complementary_roles'), ('paired', 'first_ready'): ('one_ready', 'record_ready'), ('one_ready', 'second_ready'): ('active', 'start_both'), ('waiting', 'first_withdraws'): ('empty', 'remove_first'), ('paired', 'partner_withdraws'): ('waiting', 'notify_requeue_survivor'), ('active', 'third_arrival'): ('active', 'assign_third_role'), ('one_ready', 'duplicate_ready'): ('one_ready', 'ack_existing'), ('empty', 'ready'): ('empty', 'reject_unpaired'), ('active', 'both_done'): ('empty', 'release_pair')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_first':
            r['waiting'].append(seed)
        elif action == 'assign_complementary_roles':
            r['roles']={str(seed):'initiator',str(seed+1):'responder'}
        elif action == 'record_ready':
            r['ready'].append(seed)
        elif action == 'start_both':
            r['started']=[seed,seed+1]
        elif action == 'remove_first':
            r['first']=None; r['waiting']=[]
        elif action == 'notify_requeue_survivor':
            r['waiting']=[seed]; r['second']=None; frames.append(['PARTNER_LEFT',seed])
        elif action == 'reject_full':
            frames.append(['PAIR_FULL',seed+2])
        elif action == 'ack_existing':
            frames.append(['READY_ACK',seed])
        elif action == 'reject_unpaired':
            frames.append(['UNPAIRED',seed])
        elif action == 'release_pair':
            r['first']=None; r['second']=None; r['roles']={}; r['ready']=[]
        elif action == 'notify_pair':
            frames.append(['PAIRED',seed,None])
        elif action == 'reject':
            frames.append(['REJECT',seed])
        elif action == 'replace_first':
            r['first']=seed+1
        elif action == 'assign_same_role':
            r['roles']={str(seed):'initiator',str(seed+1):'initiator'}
        elif action == 'forget_second':
            r['second']=None
        elif action == 'start_second_only':
            r['started']=[seed+1]
        elif action == 'requeue_departed':
            r['waiting']=[seed+1]
        elif action == 'replace_partner':
            r['second']=seed+2
        elif action == 'assign_third_role':
            r['roles'][str(seed+2)]='observer'
        elif action == 'clear_ready':
            r['ready']=[]
        elif action == 'assign_roles':
            r['roles']={str(seed):'initiator',str(seed+1):'responder'}
        elif action == 'keep_roles':
            r['first']=None; r['second']=None
        elif action == 'keep_first':
            r['first']=seed
        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: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [1, 2], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': None, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': [['PARTNER_LEFT', 1]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 3]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 1]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 1]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': [1]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'active', 'registers': {'first': 1, 'second': 2, 'roles': {'1': 'initiator', '2': 'responder'}, 'ready': [1], 'started': [1, 2], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [1, 2], 'waiting': []}, 'frames': [['READY_ACK', 1]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [1, 2], 'waiting': [1]}, 'frames': [['READY_ACK', 1]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 1, 'second': 2, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 1]]}])], 2: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [2, 3], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': None, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': [['PARTNER_LEFT', 2]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 4]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 2]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 2]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'waiting', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': [2]}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws'], [{'phase': 'one_ready', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'active', 'registers': {'first': 2, 'second': 3, 'roles': {'2': 'initiator', '3': 'responder'}, 'ready': [2], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': [2]}, 'frames': [['READY_ACK', 2]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [2, 3], 'waiting': []}, 'frames': [['READY_ACK', 2]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 2, 'second': 3, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 2]]}])], 3: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [3, 4], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': None, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': [['PARTNER_LEFT', 3]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 5]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 3]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 3]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': [3]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'active', 'registers': {'first': 3, 'second': 4, 'roles': {'3': 'initiator', '4': 'responder'}, 'ready': [3], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': [3]}, 'frames': [['READY_ACK', 3]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': []}, 'frames': [['READY_ACK', 3]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [3, 4], 'waiting': [3]}, 'frames': [['READY_ACK', 3]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 3, 'second': 4, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 3]]}])], 4: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [4, 5], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': None, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': [['PARTNER_LEFT', 4]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 6]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 4]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 4]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'waiting', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': [4]}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'one_ready', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'active', 'registers': {'first': 4, 'second': 5, 'roles': {'4': 'initiator', '5': 'responder'}, 'ready': [4], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': [4]}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': [4]}, 'frames': [['READY_ACK', 4]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [4, 5], 'waiting': []}, 'frames': [['READY_ACK', 4]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 4, 'second': 5, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 4]]}])], 5: [('empty/first_arrival', 'empty', ['first_arrival'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}]), ('waiting/second_arrival', 'waiting', ['second_arrival'], [{'phase': 'paired', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/first_ready', 'paired', ['first_ready'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': []}]), ('one_ready/second_ready', 'one_ready', ['second_ready'], [{'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [5, 6], 'waiting': []}, 'frames': []}]), ('waiting/first_withdraws', 'waiting', ['first_withdraws'], [{'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('paired/partner_withdraws', 'paired', ['partner_withdraws'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': None, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': [['PARTNER_LEFT', 5]]}]), ('active/third_arrival', 'active', ['third_arrival'], [{'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['PAIR_FULL', 7]]}]), ('one_ready/duplicate_ready', 'one_ready', ['duplicate_ready'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 5]]}]), ('empty/ready', 'empty', ['ready'], [{'phase': 'empty', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['UNPAIRED', 5]]}]), ('active/both_done', 'active', ['both_done'], [{'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 0', 'empty', ['first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws'], [{'phase': 'waiting', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}, {'phase': 'waiting', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': [5]}, 'frames': []}, {'phase': 'empty', 'registers': {'first': None, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': []}]), ('ordered trace 3', 'one_ready', ['duplicate_ready', 'second_ready', 'both_done', 'first_arrival', 'first_withdraws', 'first_arrival', 'first_withdraws', 'first_arrival'], [{'phase': 'one_ready', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'active', 'registers': {'first': 5, 'second': 6, 'roles': {'5': 'initiator', '6': 'responder'}, 'ready': [5], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}, {'phase': 'empty', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': []}, 'frames': [['READY_ACK', 5]]}, {'phase': 'waiting', 'registers': {'first': None, 'second': None, 'roles': {}, 'ready': [], 'started': [5, 6], 'waiting': [5]}, 'frames': [['READY_ACK', 5]]}]), ('empty input', 'empty', [], []), ('unknown event', 'empty', ['unsupported'], [{'phase': 'empty', 'registers': {'first': 5, 'second': 6, 'roles': {}, 'ready': [], 'started': [], 'waiting': []}, 'frames': [['REJECT', 5]]}])]}
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 active, event third_arrival produces paired/replace_partner instead of active/reject_full.

For the stipulated Two-peer rendezvous role assignment 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