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 = {'tx': phase in ('connected','held'), 'rx': phase in ('connected','held'), 'bell': phase=='incoming', 'muted': phase=='held', 'status': [], 'call': seed}
    frames = []
    observed = []
    table = {('idle', 'dial'): ('outgoing', 'send_invitation'), ('outgoing', 'ringing'): ('alerting', 'notify_remote_ring'), ('alerting', 'answered'): ('connected', 'open_media'), ('outgoing', 'busy'): ('idle', 'report_busy'), ('idle', 'invitation'): ('incoming', 'ring_local'), ('incoming', 'accept'): ('connected', 'answer_open_media'), ('incoming', 'decline'): ('idle', 'send_decline_stop_ring'), ('connected', 'hold'): ('held', 'mute_send_hold'), ('held', 'resume'): ('connected', 'unmute_only'), ('connected', 'hangup'): ('idle', 'close_media_send_bye')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'send_invitation':
            frames.append(['INVITE',seed])
        elif action == 'notify_remote_ring':
            r['status'].append('remote_ringing')
        elif action == 'open_media':
            r['tx']=True; r['rx']=True
        elif action == 'report_busy':
            r['status'].append('busy')
        elif action == 'ring_local':
            r['bell']=True
        elif action == 'answer_open_media':
            frames.append(['ANSWER',seed]); r['bell']=False; r['tx']=True; r['rx']=True
        elif action == 'send_decline_stop_ring':
            frames.append(['DECLINE',seed]); r['bell']=False
        elif action == 'mute_send_hold':
            r['muted']=True; frames.append(['HOLD',seed])
        elif action == 'unmute_send_resume':
            r['muted']=False; frames.append(['RESUME',seed])
        elif action == 'close_media_send_bye':
            r['tx']=False; r['rx']=False; frames.append(['BYE',seed])
        elif action == 'open_receive_only':
            r['rx']=True
        elif action == 'report_no_answer':
            r['status'].append('no_answer')
        elif action == 'send_answer_only':
            frames.append(['ANSWER',seed])
        elif action == 'stop_ring_only':
            r['bell']=False
        elif action == 'mute_only':
            r['muted']=True
        elif action == 'send_hold_only':
            frames.append(['HOLD',seed])
        elif action == 'unmute_only':
            r['muted']=False
        elif action == 'send_resume_only':
            frames.append(['RESUME',seed])
        elif action == 'close_media_only':
            r['tx']=False; r['rx']=False
        elif action == 'send_bye_only':
            frames.append(['BYE',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: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['INVITE', 1]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 1}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 1}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['ANSWER', 1]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['DECLINE', 1]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 1}, 'frames': [['HOLD', 1]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['RESUME', 1]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['BYE', 1]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['INVITE', 2]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 2}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 2}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['ANSWER', 2]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['DECLINE', 2]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 2}, 'frames': [['HOLD', 2]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['RESUME', 2]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['BYE', 2]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2], ['INVITE', 2]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['INVITE', 3]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 3}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 3}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['ANSWER', 3]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['DECLINE', 3]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 3}, 'frames': [['HOLD', 3]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['RESUME', 3]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['BYE', 3]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['INVITE', 4]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 4}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 4}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['ANSWER', 4]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['DECLINE', 4]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 4}, 'frames': [['HOLD', 4]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['RESUME', 4]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['BYE', 4]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['INVITE', 5]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 5}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 5}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['ANSWER', 5]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['DECLINE', 5]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 5}, 'frames': [['HOLD', 5]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['RESUME', 5]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['BYE', 5]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, '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)

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 = {'tx': phase in ('connected','held'), 'rx': phase in ('connected','held'), 'bell': phase=='incoming', 'muted': phase=='held', 'status': [], 'call': seed}
    frames = []
    observed = []
    table = {('idle', 'dial'): ('outgoing', 'send_invitation'), ('outgoing', 'ringing'): ('alerting', 'notify_remote_ring'), ('alerting', 'answered'): ('connected', 'open_media'), ('outgoing', 'busy'): ('idle', 'report_busy'), ('idle', 'invitation'): ('incoming', 'ring_local'), ('incoming', 'accept'): ('connected', 'answer_open_media'), ('incoming', 'decline'): ('idle', 'send_decline_stop_ring'), ('connected', 'hold'): ('held', 'mute_send_hold'), ('held', 'resume'): ('held', 'send_resume_only'), ('connected', 'hangup'): ('idle', 'close_media_send_bye')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'send_invitation':
            frames.append(['INVITE',seed])
        elif action == 'notify_remote_ring':
            r['status'].append('remote_ringing')
        elif action == 'open_media':
            r['tx']=True; r['rx']=True
        elif action == 'report_busy':
            r['status'].append('busy')
        elif action == 'ring_local':
            r['bell']=True
        elif action == 'answer_open_media':
            frames.append(['ANSWER',seed]); r['bell']=False; r['tx']=True; r['rx']=True
        elif action == 'send_decline_stop_ring':
            frames.append(['DECLINE',seed]); r['bell']=False
        elif action == 'mute_send_hold':
            r['muted']=True; frames.append(['HOLD',seed])
        elif action == 'unmute_send_resume':
            r['muted']=False; frames.append(['RESUME',seed])
        elif action == 'close_media_send_bye':
            r['tx']=False; r['rx']=False; frames.append(['BYE',seed])
        elif action == 'open_receive_only':
            r['rx']=True
        elif action == 'report_no_answer':
            r['status'].append('no_answer')
        elif action == 'send_answer_only':
            frames.append(['ANSWER',seed])
        elif action == 'stop_ring_only':
            r['bell']=False
        elif action == 'mute_only':
            r['muted']=True
        elif action == 'send_hold_only':
            frames.append(['HOLD',seed])
        elif action == 'unmute_only':
            r['muted']=False
        elif action == 'send_resume_only':
            frames.append(['RESUME',seed])
        elif action == 'close_media_only':
            r['tx']=False; r['rx']=False
        elif action == 'send_bye_only':
            frames.append(['BYE',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: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['INVITE', 1]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 1}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 1}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['ANSWER', 1]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['DECLINE', 1]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 1}, 'frames': [['HOLD', 1]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['RESUME', 1]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['BYE', 1]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 1}, 'frames': [['INVITE', 1], ['INVITE', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 1}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['INVITE', 2]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 2}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 2}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['ANSWER', 2]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['DECLINE', 2]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 2}, 'frames': [['HOLD', 2]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['RESUME', 2]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['BYE', 2]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2], ['INVITE', 2]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 2}, 'frames': [['INVITE', 2], ['INVITE', 2]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 2}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['INVITE', 3]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 3}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 3}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['ANSWER', 3]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['DECLINE', 3]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 3}, 'frames': [['HOLD', 3]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['RESUME', 3]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['BYE', 3]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 3}, 'frames': [['INVITE', 3], ['INVITE', 3], ['INVITE', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 3}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['INVITE', 4]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 4}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 4}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['ANSWER', 4]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['DECLINE', 4]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 4}, 'frames': [['HOLD', 4]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['RESUME', 4]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['BYE', 4]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 4}, 'frames': [['INVITE', 4], ['INVITE', 4], ['INVITE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 4}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/dial', 'idle', ['dial'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['INVITE', 5]]}]), ('outgoing/ringing', 'outgoing', ['ringing'], [{'phase': 'alerting', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['remote_ringing'], 'call': 5}, 'frames': []}]), ('alerting/answered', 'alerting', ['answered'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': []}]), ('outgoing/busy', 'outgoing', ['busy'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': []}]), ('idle/invitation', 'idle', ['invitation'], [{'phase': 'incoming', 'registers': {'tx': False, 'rx': False, 'bell': True, 'muted': False, 'status': [], 'call': 5}, 'frames': []}]), ('incoming/accept', 'incoming', ['accept'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['ANSWER', 5]]}]), ('incoming/decline', 'incoming', ['decline'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['DECLINE', 5]]}]), ('connected/hold', 'connected', ['hold'], [{'phase': 'held', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': True, 'status': [], 'call': 5}, 'frames': [['HOLD', 5]]}]), ('held/resume', 'held', ['resume'], [{'phase': 'connected', 'registers': {'tx': True, 'rx': True, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['RESUME', 5]]}]), ('connected/hangup', 'connected', ['hangup'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['BYE', 5]]}]), ('ordered trace 0', 'idle', ['dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy'], [{'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}]), ('ordered trace 3', 'outgoing', ['busy', 'dial', 'busy', 'dial', 'busy', 'dial', 'busy', 'dial'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': []}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}, {'phase': 'outgoing', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': ['busy', 'busy', 'busy', 'busy'], 'call': 5}, 'frames': [['INVITE', 5], ['INVITE', 5], ['INVITE', 5], ['INVITE', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'tx': False, 'rx': False, 'bell': False, 'muted': False, 'status': [], 'call': 5}, '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 held, event resume produces connected/unmute_only instead of connected/unmute_send_resume.

For the stipulated Intercom call-signaling 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