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 = {'active': [seed], 'staged': payload[:] if phase in ('pending','prepared','recovering') else [], 'epoch': seed, 'processed': [], 'validated': phase=='prepared'}
    frames = []
    observed = []
    table = {('active', 'propose'): ('pending', 'stage_config'), ('pending', 'validated'): ('prepared', 'send_prepared'), ('pending', 'invalid'): ('active', 'discard_proposal'), ('prepared', 'activate'): ('active', 'swap_epoch'), ('prepared', 'withdraw'): ('active', 'swap_epoch'), ('prepared', 'old_epoch_data'): ('prepared', 'process_old'), ('active', 'future_epoch_data'): ('active', 'reject_future'), ('pending', 'second_proposal'): ('pending', 'reject_busy'), ('active', 'duplicate_activation'): ('active', 'ack_current'), ('prepared', 'restart'): ('recovering', 'load_prepared')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stage_config':
            r['staged']=payload[:]
        elif action == 'send_prepared':
            r['validated']=True; frames.append(['PREPARED',seed+1])
        elif action == 'discard_proposal':
            r['staged']=[]
        elif action == 'swap_epoch':
            r['active']=r['staged'][:]; r['staged']=[]; r['epoch']+=1
        elif action == 'process_old':
            r['processed'].append([seed,payload])
        elif action == 'reject_future':
            frames.append(['FUTURE_EPOCH',seed+1])
        elif action == 'reject_busy':
            frames.append(['CONFIG_BUSY',seed])
        elif action == 'ack_current':
            frames.append(['ACTIVE',r['epoch']])
        elif action == 'load_prepared':
            frames.append(['RECOVER_PREPARED',r['staged'][:]])
        elif action == 'activate_config':
            r['active']=payload[:]; r['epoch']+=1
        elif action == 'overwrite_active':
            r['active']=payload[:]
        elif action == 'send_active':
            frames.append(['ACTIVE',seed+1])
        elif action == 'merge_epochs':
            r['active'].extend(r['staged']); r['epoch']+=1
        elif action == 'clear_active':
            r['active']=[]
        elif action == 'process_new':
            r['processed'].append([seed+1,payload])
        elif action == 'stage_from_data':
            r['staged']=payload[:]
        elif action == 'replace_staged':
            r['staged']=payload[:]
        elif action == 'discard_all':
            r['active']=[]; r['staged']=[]
        elif action == 'swap_again':
            r['epoch']+=1
        elif action == 'load_active_only':
            frames.append(['RECOVER_ACTIVE',r['active'][:]])
        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: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 2]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [1, 2, 3], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [[1, [1, 2, 3]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 2]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 1]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}, {'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 3]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [2, 3, 4, 5], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [[2, [2, 3, 4, 5]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 3]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 2]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 4]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [3, 4, 5, 6, 7], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [[3, [3, 4, 5, 6, 7]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 4]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 3]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3], ['ACTIVE', 3]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 5]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [4, 5, 6, 7, 8, 9], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [[4, [4, 5, 6, 7, 8, 9]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 5]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 4]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 6]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [5, 6, 7, 8, 9, 10, 11], 'staged': [], 'epoch': 6, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [[5, [5, 6, 7, 8, 9, 10, 11]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 6]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 5]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, '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 = {'active': [seed], 'staged': payload[:] if phase in ('pending','prepared','recovering') else [], 'epoch': seed, 'processed': [], 'validated': phase=='prepared'}
    frames = []
    observed = []
    table = {('active', 'propose'): ('pending', 'stage_config'), ('pending', 'validated'): ('prepared', 'send_prepared'), ('pending', 'invalid'): ('active', 'discard_proposal'), ('prepared', 'activate'): ('active', 'swap_epoch'), ('prepared', 'withdraw'): ('active', 'clear_active'), ('prepared', 'old_epoch_data'): ('prepared', 'process_old'), ('active', 'future_epoch_data'): ('active', 'reject_future'), ('pending', 'second_proposal'): ('pending', 'reject_busy'), ('active', 'duplicate_activation'): ('active', 'ack_current'), ('prepared', 'restart'): ('recovering', 'load_prepared')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stage_config':
            r['staged']=payload[:]
        elif action == 'send_prepared':
            r['validated']=True; frames.append(['PREPARED',seed+1])
        elif action == 'discard_proposal':
            r['staged']=[]
        elif action == 'swap_epoch':
            r['active']=r['staged'][:]; r['staged']=[]; r['epoch']+=1
        elif action == 'process_old':
            r['processed'].append([seed,payload])
        elif action == 'reject_future':
            frames.append(['FUTURE_EPOCH',seed+1])
        elif action == 'reject_busy':
            frames.append(['CONFIG_BUSY',seed])
        elif action == 'ack_current':
            frames.append(['ACTIVE',r['epoch']])
        elif action == 'load_prepared':
            frames.append(['RECOVER_PREPARED',r['staged'][:]])
        elif action == 'activate_config':
            r['active']=payload[:]; r['epoch']+=1
        elif action == 'overwrite_active':
            r['active']=payload[:]
        elif action == 'send_active':
            frames.append(['ACTIVE',seed+1])
        elif action == 'merge_epochs':
            r['active'].extend(r['staged']); r['epoch']+=1
        elif action == 'clear_active':
            r['active']=[]
        elif action == 'process_new':
            r['processed'].append([seed+1,payload])
        elif action == 'stage_from_data':
            r['staged']=payload[:]
        elif action == 'replace_staged':
            r['staged']=payload[:]
        elif action == 'discard_all':
            r['active']=[]; r['staged']=[]
        elif action == 'swap_again':
            r['epoch']+=1
        elif action == 'load_active_only':
            frames.append(['RECOVER_ACTIVE',r['active'][:]])
        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: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 2]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [1, 2, 3], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [[1, [1, 2, 3]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 2]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 1]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}, {'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 3]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [2, 3, 4, 5], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [[2, [2, 3, 4, 5]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 3]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 2]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 4]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [3, 4, 5, 6, 7], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [[3, [3, 4, 5, 6, 7]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 4]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 3]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3], ['ACTIVE', 3]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 5]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [4, 5, 6, 7, 8, 9], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [[4, [4, 5, 6, 7, 8, 9]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 5]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 4]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 6]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [5, 6, 7, 8, 9, 10, 11], 'staged': [], 'epoch': 6, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [[5, [5, 6, 7, 8, 9, 10, 11]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 6]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 5]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, '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 prepared, event withdraw produces active/swap_epoch instead of active/discard_proposal.

For the stipulated Peer configuration epoch activation 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


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 = {'active': [seed], 'staged': payload[:] if phase in ('pending','prepared','recovering') else [], 'epoch': seed, 'processed': [], 'validated': phase=='prepared'}
    frames = []
    observed = []
    table = {('active', 'propose'): ('pending', 'stage_config'), ('pending', 'validated'): ('prepared', 'send_prepared'), ('pending', 'invalid'): ('active', 'discard_proposal'), ('prepared', 'activate'): ('active', 'swap_epoch'), ('prepared', 'withdraw'): ('active', 'discard_proposal'), ('prepared', 'old_epoch_data'): ('prepared', 'process_new'), ('active', 'future_epoch_data'): ('active', 'reject_future'), ('pending', 'second_proposal'): ('pending', 'reject_busy'), ('active', 'duplicate_activation'): ('active', 'ack_current'), ('prepared', 'restart'): ('recovering', 'load_prepared')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stage_config':
            r['staged']=payload[:]
        elif action == 'send_prepared':
            r['validated']=True; frames.append(['PREPARED',seed+1])
        elif action == 'discard_proposal':
            r['staged']=[]
        elif action == 'swap_epoch':
            r['active']=r['staged'][:]; r['staged']=[]; r['epoch']+=1
        elif action == 'process_old':
            r['processed'].append([seed,payload])
        elif action == 'reject_future':
            frames.append(['FUTURE_EPOCH',seed+1])
        elif action == 'reject_busy':
            frames.append(['CONFIG_BUSY',seed])
        elif action == 'ack_current':
            frames.append(['ACTIVE',r['epoch']])
        elif action == 'load_prepared':
            frames.append(['RECOVER_PREPARED',r['staged'][:]])
        elif action == 'activate_config':
            r['active']=payload[:]; r['epoch']+=1
        elif action == 'overwrite_active':
            r['active']=payload[:]
        elif action == 'send_active':
            frames.append(['ACTIVE',seed+1])
        elif action == 'merge_epochs':
            r['active'].extend(r['staged']); r['epoch']+=1
        elif action == 'clear_active':
            r['active']=[]
        elif action == 'process_new':
            r['processed'].append([seed+1,payload])
        elif action == 'stage_from_data':
            r['staged']=payload[:]
        elif action == 'replace_staged':
            r['staged']=payload[:]
        elif action == 'discard_all':
            r['active']=[]; r['staged']=[]
        elif action == 'swap_again':
            r['epoch']+=1
        elif action == 'load_active_only':
            frames.append(['RECOVER_ACTIVE',r['active'][:]])
        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: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 2]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [1, 2, 3], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [[1, [1, 2, 3]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 2]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 1]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}, {'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 3]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [2, 3, 4, 5], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [[2, [2, 3, 4, 5]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 3]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 2]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 4]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [3, 4, 5, 6, 7], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [[3, [3, 4, 5, 6, 7]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 4]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 3]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3], ['ACTIVE', 3]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 5]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [4, 5, 6, 7, 8, 9], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [[4, [4, 5, 6, 7, 8, 9]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 5]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 4]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 6]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [5, 6, 7, 8, 9, 10, 11], 'staged': [], 'epoch': 6, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [[5, [5, 6, 7, 8, 9, 10, 11]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 6]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 5]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, '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 = {'active': [seed], 'staged': payload[:] if phase in ('pending','prepared','recovering') else [], 'epoch': seed, 'processed': [], 'validated': phase=='prepared'}
    frames = []
    observed = []
    table = {('active', 'propose'): ('pending', 'stage_config'), ('pending', 'validated'): ('prepared', 'send_prepared'), ('pending', 'invalid'): ('active', 'discard_proposal'), ('prepared', 'activate'): ('active', 'swap_epoch'), ('prepared', 'withdraw'): ('active', 'discard_proposal'), ('prepared', 'old_epoch_data'): ('active', 'process_old'), ('active', 'future_epoch_data'): ('active', 'reject_future'), ('pending', 'second_proposal'): ('pending', 'reject_busy'), ('active', 'duplicate_activation'): ('active', 'ack_current'), ('prepared', 'restart'): ('recovering', 'load_prepared')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stage_config':
            r['staged']=payload[:]
        elif action == 'send_prepared':
            r['validated']=True; frames.append(['PREPARED',seed+1])
        elif action == 'discard_proposal':
            r['staged']=[]
        elif action == 'swap_epoch':
            r['active']=r['staged'][:]; r['staged']=[]; r['epoch']+=1
        elif action == 'process_old':
            r['processed'].append([seed,payload])
        elif action == 'reject_future':
            frames.append(['FUTURE_EPOCH',seed+1])
        elif action == 'reject_busy':
            frames.append(['CONFIG_BUSY',seed])
        elif action == 'ack_current':
            frames.append(['ACTIVE',r['epoch']])
        elif action == 'load_prepared':
            frames.append(['RECOVER_PREPARED',r['staged'][:]])
        elif action == 'activate_config':
            r['active']=payload[:]; r['epoch']+=1
        elif action == 'overwrite_active':
            r['active']=payload[:]
        elif action == 'send_active':
            frames.append(['ACTIVE',seed+1])
        elif action == 'merge_epochs':
            r['active'].extend(r['staged']); r['epoch']+=1
        elif action == 'clear_active':
            r['active']=[]
        elif action == 'process_new':
            r['processed'].append([seed+1,payload])
        elif action == 'stage_from_data':
            r['staged']=payload[:]
        elif action == 'replace_staged':
            r['staged']=payload[:]
        elif action == 'discard_all':
            r['active']=[]; r['staged']=[]
        elif action == 'swap_again':
            r['epoch']+=1
        elif action == 'load_active_only':
            frames.append(['RECOVER_ACTIVE',r['active'][:]])
        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: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 2]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [1, 2, 3], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [[1, [1, 2, 3]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 2]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 1]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}, {'phase': 'pending', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 1]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [1], 'staged': [1, 2, 3], 'epoch': 1, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [1, 2, 3]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [1], 'staged': [], 'epoch': 1, 'processed': [], 'validated': False}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 3]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [2, 3, 4, 5], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [[2, [2, 3, 4, 5]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 3]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 2]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'pending', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}, {'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 2]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [2], 'staged': [2, 3, 4, 5], 'epoch': 2, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [2, 3, 4, 5]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [2], 'staged': [], 'epoch': 2, 'processed': [], 'validated': False}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 4]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [3, 4, 5, 6, 7], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [[3, [3, 4, 5, 6, 7]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 4]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 3]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation'], [{'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'pending', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3]]}, {'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 3], ['ACTIVE', 3]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [3], 'staged': [3, 4, 5, 6, 7], 'epoch': 3, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [3, 4, 5, 6, 7]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [3], 'staged': [], 'epoch': 3, 'processed': [], 'validated': False}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 5]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [4, 5, 6, 7, 8, 9], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [[4, [4, 5, 6, 7, 8, 9]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 5]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 4]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose'], [{'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4]]}, {'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}, {'phase': 'pending', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 4], ['ACTIVE', 4]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [4], 'staged': [4, 5, 6, 7, 8, 9], 'epoch': 4, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [4], 'staged': [], 'epoch': 4, 'processed': [], 'validated': False}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('active/propose', 'active', ['propose'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('pending/validated', 'pending', ['validated'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['PREPARED', 6]]}]), ('pending/invalid', 'pending', ['invalid'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}]), ('prepared/activate', 'prepared', ['activate'], [{'phase': 'active', 'registers': {'active': [5, 6, 7, 8, 9, 10, 11], 'staged': [], 'epoch': 6, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/withdraw', 'prepared', ['withdraw'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': []}]), ('prepared/old_epoch_data', 'prepared', ['old_epoch_data'], [{'phase': 'prepared', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [[5, [5, 6, 7, 8, 9, 10, 11]]], 'validated': True}, 'frames': []}]), ('active/future_epoch_data', 'active', ['future_epoch_data'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['FUTURE_EPOCH', 6]]}]), ('pending/second_proposal', 'pending', ['second_proposal'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['CONFIG_BUSY', 5]]}]), ('active/duplicate_activation', 'active', ['duplicate_activation'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}]), ('prepared/restart', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('ordered trace 0', 'active', ['propose', 'invalid', 'duplicate_activation', 'propose', 'invalid', 'duplicate_activation', 'propose', 'invalid'], [{'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': []}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'pending', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}, {'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, 'frames': [['ACTIVE', 5], ['ACTIVE', 5]]}]), ('ordered trace 3', 'prepared', ['restart'], [{'phase': 'recovering', 'registers': {'active': [5], 'staged': [5, 6, 7, 8, 9, 10, 11], 'epoch': 5, 'processed': [], 'validated': True}, 'frames': [['RECOVER_PREPARED', [5, 6, 7, 8, 9, 10, 11]]]}]), ('empty input', 'active', [], []), ('unknown event', 'active', ['unsupported'], [{'phase': 'active', 'registers': {'active': [5], 'staged': [], 'epoch': 5, 'processed': [], 'validated': False}, '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 prepared, event old_epoch_data produces prepared/process_new instead of prepared/process_old.

For the stipulated Peer configuration epoch activation 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