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 = {'admission': phase=='running', 'owned_session': None if phase=='stopped' else seed, 'generation': seed, 'work': payload[:], 'ready': False, 'delivered': []}
    frames = []
    observed = []
    table = {('running', 'restart_notice'): ('draining', 'stop_new_work'), ('draining', 'work_finished'): ('ready', 'send_ready'), ('ready', 'restart_commit'): ('stopped', 'close_old_session'), ('ready', 'restart_cancel'): ('running', 'resume_admission'), ('stopped', 'new_session'): ('synchronizing', 'exchange_generation'), ('synchronizing', 'generation_agreed'): ('running', 'resume_admission'), ('draining', 'new_work'): ('draining', 'accept_work'), ('running', 'restart_commit'): ('running', 'reject_unprepared'), ('synchronizing', 'old_session_frame'): ('synchronizing', 'reject_old_generation'), ('stopped', 'duplicate_commit'): ('stopped', 'ack_stopped')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stop_new_work':
            r['admission']=False
        elif action == 'send_ready':
            r['ready']=True; frames.append(['DRAINED',r['generation']])
        elif action == 'close_old_session':
            r['owned_session']=None
        elif action == 'resume_admission':
            r['admission']=True
        elif action == 'exchange_generation':
            frames.append(['GENERATION',seed+1])
        elif action == 'redirect_work':
            frames.append(['REDIRECT',payload])
        elif action == 'reject_unprepared':
            frames.append(['NOT_DRAINED',seed])
        elif action == 'reject_old_generation':
            frames.append(['STALE_GENERATION',seed])
        elif action == 'ack_stopped':
            frames.append(['STOPPED',seed])
        elif action == 'terminate':
            r['owned_session']=None; r['work']=[]
        elif action == 'accept_new_work':
            r['work'].extend(payload)
        elif action == 'resume_old':
            r['owned_session']=seed; r['admission']=True
        elif action == 'keep_admission_closed':
            r['admission']=False
        elif action == 'reuse_generation':
            frames.append(['GENERATION',seed])
        elif action == 'resume_old_work':
            r['delivered'].extend(r['work'])
        elif action == 'accept_work':
            r['work'].extend(payload)
        elif action == 'drop':
            r['work']=[]
        elif action == 'deliver':
            r['delivered'].extend(payload)
        elif action == 'buffer_old':
            r['work'].extend(payload)
        elif action == 'close_new_session':
            r['owned_session']=None; r['generation']=seed+1
        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: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 1]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 2]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 1]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 1]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 1]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 2]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 3]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 2]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 2]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 2]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 3]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 4]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 3]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 3]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 3]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3], ['REDIRECT', [3, 4, 5, 6, 7]]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 4]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 5]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 4]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 4]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 4]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 5]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 6]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 5]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 5]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 5]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, '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 = {'admission': phase=='running', 'owned_session': None if phase=='stopped' else seed, 'generation': seed, 'work': payload[:], 'ready': False, 'delivered': []}
    frames = []
    observed = []
    table = {('running', 'restart_notice'): ('draining', 'stop_new_work'), ('draining', 'work_finished'): ('ready', 'send_ready'), ('ready', 'restart_commit'): ('stopped', 'close_old_session'), ('ready', 'restart_cancel'): ('running', 'resume_admission'), ('stopped', 'new_session'): ('synchronizing', 'exchange_generation'), ('synchronizing', 'generation_agreed'): ('running', 'resume_admission'), ('draining', 'new_work'): ('stopped', 'drop'), ('running', 'restart_commit'): ('running', 'reject_unprepared'), ('synchronizing', 'old_session_frame'): ('synchronizing', 'reject_old_generation'), ('stopped', 'duplicate_commit'): ('stopped', 'ack_stopped')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'stop_new_work':
            r['admission']=False
        elif action == 'send_ready':
            r['ready']=True; frames.append(['DRAINED',r['generation']])
        elif action == 'close_old_session':
            r['owned_session']=None
        elif action == 'resume_admission':
            r['admission']=True
        elif action == 'exchange_generation':
            frames.append(['GENERATION',seed+1])
        elif action == 'redirect_work':
            frames.append(['REDIRECT',payload])
        elif action == 'reject_unprepared':
            frames.append(['NOT_DRAINED',seed])
        elif action == 'reject_old_generation':
            frames.append(['STALE_GENERATION',seed])
        elif action == 'ack_stopped':
            frames.append(['STOPPED',seed])
        elif action == 'terminate':
            r['owned_session']=None; r['work']=[]
        elif action == 'accept_new_work':
            r['work'].extend(payload)
        elif action == 'resume_old':
            r['owned_session']=seed; r['admission']=True
        elif action == 'keep_admission_closed':
            r['admission']=False
        elif action == 'reuse_generation':
            frames.append(['GENERATION',seed])
        elif action == 'resume_old_work':
            r['delivered'].extend(r['work'])
        elif action == 'accept_work':
            r['work'].extend(payload)
        elif action == 'drop':
            r['work']=[]
        elif action == 'deliver':
            r['delivered'].extend(payload)
        elif action == 'buffer_old':
            r['work'].extend(payload)
        elif action == 'close_new_session':
            r['owned_session']=None; r['generation']=seed+1
        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: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 1]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 2]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 1]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 1]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 1]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [1, 2, 3]], ['DRAINED', 1]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 1, 'generation': 1, 'work': [1, 2, 3], 'ready': False, 'delivered': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 2]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 3]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 2]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 2]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 2]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [2, 3, 4, 5]], ['DRAINED', 2]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 2, 'generation': 2, 'work': [2, 3, 4, 5], 'ready': False, 'delivered': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 3]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 4]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 3]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 3]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 3]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3], ['REDIRECT', [3, 4, 5, 6, 7]]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [3, 4, 5, 6, 7]], ['DRAINED', 3]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 3, 'generation': 3, 'work': [3, 4, 5, 6, 7], 'ready': False, 'delivered': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 4]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 5]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 4]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 4]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 4]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [4, 5, 6, 7, 8, 9]], ['DRAINED', 4], ['REDIRECT', [4, 5, 6, 7, 8, 9]]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 4, 'generation': 4, 'work': [4, 5, 6, 7, 8, 9], 'ready': False, 'delivered': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('running/restart_notice', 'running', ['restart_notice'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/work_finished', 'draining', ['work_finished'], [{'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['DRAINED', 5]]}]), ('ready/restart_commit', 'ready', ['restart_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('ready/restart_cancel', 'ready', ['restart_cancel'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('stopped/new_session', 'stopped', ['new_session'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['GENERATION', 6]]}]), ('synchronizing/generation_agreed', 'synchronizing', ['generation_agreed'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}]), ('draining/new_work', 'draining', ['new_work'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}]), ('running/restart_commit', 'running', ['restart_commit'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['NOT_DRAINED', 5]]}]), ('synchronizing/old_session_frame', 'synchronizing', ['old_session_frame'], [{'phase': 'synchronizing', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['STALE_GENERATION', 5]]}]), ('stopped/duplicate_commit', 'stopped', ['duplicate_commit'], [{'phase': 'stopped', 'registers': {'admission': False, 'owned_session': None, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['STOPPED', 5]]}]), ('ordered trace 0', 'running', ['restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel'], [{'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}]), ('ordered trace 3', 'ready', ['restart_cancel', 'restart_notice', 'new_work', 'work_finished', 'restart_cancel', 'restart_notice', 'new_work', 'work_finished'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': []}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}, {'phase': 'draining', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]]]}, {'phase': 'ready', 'registers': {'admission': False, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': True, 'delivered': []}, 'frames': [['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5], ['REDIRECT', [5, 6, 7, 8, 9, 10, 11]], ['DRAINED', 5]]}]), ('empty input', 'running', [], []), ('unknown event', 'running', ['unsupported'], [{'phase': 'running', 'registers': {'admission': True, 'owned_session': 5, 'generation': 5, 'work': [5, 6, 7, 8, 9, 10, 11], 'ready': False, 'delivered': []}, '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 draining, event new_work produces draining/accept_work instead of draining/redirect_work.

For the stipulated Peer restart-drain coordination 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