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 = {'receive': seed+3, 'origin': seed, 'departure': seed+5, 'response': seed+7, 'offset_twice': None, 'clock': seed*10, 'owned': True}
    frames = []
    observed = []
    table = {('idle', 'sync_received'): ('have_sync', 'record_receive_time'), ('have_sync', 'followup_received'): ('have_origin', 'record_origin_time'), ('have_origin', 'delay_sent'): ('awaiting_delay', 'record_departure_time'), ('awaiting_delay', 'delay_response'): ('complete', 'compute_exchange'), ('have_sync', 'wrong_followup'): ('have_sync', 'reject_sequence'), ('awaiting_delay', 'wrong_response'): ('awaiting_delay', 'reject_sequence'), ('complete', 'consume'): ('idle', 'release_measurement'), ('have_origin', 'new_sync'): ('have_sync', 'restart_exchange'), ('idle', 'delay_response'): ('idle', 'reject_orphan'), ('awaiting_delay', 'exchange_expired'): ('complete', 'publish_offset')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_receive_time':
            r['receive']=seed+3
        elif action == 'record_origin_time':
            r['origin']=seed
        elif action == 'record_departure_time':
            r['departure']=seed+5
        elif action == 'compute_exchange':
            r['offset_twice']=(r['receive']-r['origin'])-(r['response']-r['departure'])
        elif action == 'reject_sequence':
            frames.append(['WRONG_EXCHANGE',seed+1])
        elif action == 'release_measurement':
            r['owned']=False
        elif action == 'restart_exchange':
            r['receive']=seed+3; r['origin']=None; r['offset_twice']=None
        elif action == 'reject_orphan':
            frames.append(['ORPHAN_RESPONSE',seed])
        elif action == 'discard_measurement':
            r['owned']=False; r['offset_twice']=None
        elif action == 'publish_offset':
            frames.append(['OFFSET',r['offset_twice']])
        elif action == 'record_receive_as_origin':
            r['origin']=r['receive']
        elif action == 'record_origin_as_departure':
            r['departure']=r['origin']
        elif action == 'ignore_return_leg':
            r['offset_twice']=r['receive']-r['origin'] if r['origin'] is not None else None
        elif action == 'clear_exchange':
            r['origin']=None; r['offset_twice']=None
        elif action == 'use_previous_response':
            r['response']=seed-1
        elif action == 'clear_clock':
            r['owned']=False; r['clock']=0
        elif action == 'keep_old_origin':
            r['receive']=seed+3
        elif action == 'record_response':
            r['response']=seed+7
        elif action == 'publish_partial':
            frames.append(['OFFSET',r['receive']-r['departure']])
        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/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': None, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 1]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}, {'phase': 'have_origin', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': None, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received'], [{'phase': 'complete', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 1]]}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': None, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 2]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': None, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup'], [{'phase': 'complete', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2], ['WRONG_EXCHANGE', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 3]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received'], [{'phase': 'complete', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3], ['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3], ['WRONG_EXCHANGE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 4]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received', 'new_sync'], [{'phase': 'complete', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 5]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'complete', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(phase, events, seed):
    payload = list(range(seed, seed * 2 + 2))
    r = {'receive': seed+3, 'origin': seed, 'departure': seed+5, 'response': seed+7, 'offset_twice': None, 'clock': seed*10, 'owned': True}
    frames = []
    observed = []
    table = {('idle', 'sync_received'): ('have_sync', 'record_receive_time'), ('have_sync', 'followup_received'): ('have_origin', 'record_origin_time'), ('have_origin', 'delay_sent'): ('awaiting_delay', 'record_departure_time'), ('awaiting_delay', 'delay_response'): ('complete', 'compute_exchange'), ('have_sync', 'wrong_followup'): ('have_sync', 'reject_sequence'), ('awaiting_delay', 'wrong_response'): ('awaiting_delay', 'reject_sequence'), ('complete', 'consume'): ('idle', 'release_measurement'), ('have_origin', 'new_sync'): ('have_sync', 'restart_exchange'), ('idle', 'delay_response'): ('idle', 'reject_orphan'), ('awaiting_delay', 'exchange_expired'): ('idle', 'publish_partial')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'record_receive_time':
            r['receive']=seed+3
        elif action == 'record_origin_time':
            r['origin']=seed
        elif action == 'record_departure_time':
            r['departure']=seed+5
        elif action == 'compute_exchange':
            r['offset_twice']=(r['receive']-r['origin'])-(r['response']-r['departure'])
        elif action == 'reject_sequence':
            frames.append(['WRONG_EXCHANGE',seed+1])
        elif action == 'release_measurement':
            r['owned']=False
        elif action == 'restart_exchange':
            r['receive']=seed+3; r['origin']=None; r['offset_twice']=None
        elif action == 'reject_orphan':
            frames.append(['ORPHAN_RESPONSE',seed])
        elif action == 'discard_measurement':
            r['owned']=False; r['offset_twice']=None
        elif action == 'publish_offset':
            frames.append(['OFFSET',r['offset_twice']])
        elif action == 'record_receive_as_origin':
            r['origin']=r['receive']
        elif action == 'record_origin_as_departure':
            r['departure']=r['origin']
        elif action == 'ignore_return_leg':
            r['offset_twice']=r['receive']-r['origin'] if r['origin'] is not None else None
        elif action == 'clear_exchange':
            r['origin']=None; r['offset_twice']=None
        elif action == 'use_previous_response':
            r['response']=seed-1
        elif action == 'clear_clock':
            r['owned']=False; r['clock']=0
        elif action == 'keep_old_origin':
            r['receive']=seed+3
        elif action == 'record_response':
            r['response']=seed+7
        elif action == 'publish_partial':
            frames.append(['OFFSET',r['receive']-r['departure']])
        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/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': None, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 1]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}, {'phase': 'have_origin', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': None, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 2]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received'], [{'phase': 'complete', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 1]]}, {'phase': 'have_sync', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': 1, 'clock': 10, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 4, 'origin': 1, 'departure': 6, 'response': 8, 'offset_twice': None, 'clock': 10, 'owned': True}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': None, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 2]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': None, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}, {'phase': 'have_origin', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 3]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup'], [{'phase': 'complete', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2]]}, {'phase': 'have_sync', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': 1, 'clock': 20, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 2], ['WRONG_EXCHANGE', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 5, 'origin': 2, 'departure': 7, 'response': 9, 'offset_twice': None, 'clock': 20, 'owned': True}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 3]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': None, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 4]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received'], [{'phase': 'complete', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3]]}, {'phase': 'have_sync', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3], ['WRONG_EXCHANGE', 4]]}, {'phase': 'have_origin', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': 1, 'clock': 30, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 3], ['WRONG_EXCHANGE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 6, 'origin': 3, 'departure': 8, 'response': 10, 'offset_twice': None, 'clock': 30, 'owned': True}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 4]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 5]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received', 'new_sync'], [{'phase': 'complete', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}, {'phase': 'have_origin', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': 1, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 7, 'origin': None, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 4], ['WRONG_EXCHANGE', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 7, 'origin': 4, 'departure': 9, 'response': 11, 'offset_twice': None, 'clock': 40, 'owned': True}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/sync_received', 'idle', ['sync_received'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_sync/followup_received', 'have_sync', ['followup_received'], [{'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_origin/delay_sent', 'have_origin', ['delay_sent'], [{'phase': 'awaiting_delay', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('awaiting_delay/delay_response', 'awaiting_delay', ['delay_response'], [{'phase': 'complete', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': True}, 'frames': []}]), ('have_sync/wrong_followup', 'have_sync', ['wrong_followup'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('awaiting_delay/wrong_response', 'awaiting_delay', ['wrong_response'], [{'phase': 'awaiting_delay', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': []}]), ('have_origin/new_sync', 'have_origin', ['new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}]), ('idle/delay_response', 'idle', ['delay_response'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['ORPHAN_RESPONSE', 5]]}]), ('awaiting_delay/exchange_expired', 'awaiting_delay', ['exchange_expired'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': []}]), ('ordered trace 0', 'idle', ['sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received', 'new_sync', 'followup_received', 'new_sync'], [{'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': []}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, 'frames': [['WRONG_EXCHANGE', 6]]}]), ('ordered trace 3', 'awaiting_delay', ['delay_response', 'consume', 'delay_response', 'sync_received', 'wrong_followup', 'followup_received', 'new_sync', 'followup_received'], [{'phase': 'complete', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': True}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': []}, {'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': 1, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_sync', 'registers': {'receive': 8, 'origin': None, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}, {'phase': 'have_origin', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': False}, 'frames': [['ORPHAN_RESPONSE', 5], ['WRONG_EXCHANGE', 6]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'receive': 8, 'origin': 5, 'departure': 10, 'response': 12, 'offset_twice': None, 'clock': 50, 'owned': True}, '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 awaiting_delay, event exchange_expired produces complete/publish_offset instead of idle/discard_measurement.

For the stipulated Four-event clock measurement exchange 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