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 = {'queue': [seed] if phase=='queued' else [], 'running': phase in ('running','cancelling'), 'stop_requested': phase=='cancelling', 'result': payload[:], 'reported': [], 'executions': 0}
    frames = []
    observed = []
    table = {('idle', 'submit'): ('queued', 'enqueue'), ('queued', 'dispatch'): ('running', 'start_command'), ('queued', 'cancel'): ('cancelled', 'remove_and_ack'), ('running', 'cancel'): ('cancelling', 'request_stop'), ('cancelling', 'stopped'): ('cancelled', 'ack_cancel'), ('cancelling', 'completed_first'): ('done', 'report_result'), ('running', 'completed'): ('done', 'report_result'), ('done', 'cancel'): ('cancelled', 'ack_cancel'), ('cancelled', 'late_completion'): ('cancelled', 'discard_late_result'), ('idle', 'cancel'): ('idle', 'report_unknown')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'enqueue':
            r['queue'].append(seed)
        elif action == 'start_command':
            r['running']=True; r['executions']+=1
        elif action == 'remove_and_ack':
            r['queue']=[]; r['reported'].append('cancelled')
        elif action == 'request_stop':
            r['stop_requested']=True
        elif action == 'ack_cancel':
            r['running']=False; r['reported'].append('cancelled')
        elif action == 'report_result':
            r['reported'].append(r['result'][:])
        elif action == 'report_already_done':
            r['reported'].append('already_done')
        elif action == 'discard_late_result':
            r['result']=[]
        elif action == 'report_unknown':
            r['reported'].append('unknown')
        elif action == 'execute':
            r['running']=True; r['executions']+=1
        elif action == 'ack_result':
            r['reported'].append(r['result'][:])
        elif action == 'report_success':
            r['reported'].append('success')
        elif action == 'enqueue_again':
            r['queue'].append(seed)
        elif action == 'ack_without_remove':
            r['reported'].append('cancelled')
        elif action == 'report_pending':
            r['reported'].append('pending')
        elif action == 'discard_result':
            r['result']=[]
        else:
            if action not in ("wait", "ignore", "keep", "retain", "keep_peer", "keep_offer", "keep_hold", "keep_batch", "retain_staging", "keep_staging", "keep_local_owner", "keep_old_session", "keep_address", "keep_old_expiry", "ignore_conflict", "keep_service", "keep_subscription", "retain_shadow", "keep_live", "keep_suspicion", "keep_roles", "keep_staged"):
                frames.append([action, payload[:]])
        observed.append(json.loads(json.dumps({"phase": phase, "registers": r, "frames": frames})))
    return observed
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [1], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [1], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [1], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [2], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [2], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [2], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [3], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [3], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [3], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [4], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [4], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [4], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [5], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [5], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [5], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, '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 = {'queue': [seed] if phase=='queued' else [], 'running': phase in ('running','cancelling'), 'stop_requested': phase=='cancelling', 'result': payload[:], 'reported': [], 'executions': 0}
    frames = []
    observed = []
    table = {('idle', 'submit'): ('queued', 'enqueue'), ('queued', 'dispatch'): ('running', 'start_command'), ('queued', 'cancel'): ('cancelled', 'remove_and_ack'), ('running', 'cancel'): ('cancelling', 'request_stop'), ('cancelling', 'stopped'): ('cancelled', 'ack_cancel'), ('cancelling', 'completed_first'): ('done', 'report_result'), ('running', 'completed'): ('done', 'report_result'), ('done', 'cancel'): ('done', 'discard_result'), ('cancelled', 'late_completion'): ('cancelled', 'discard_late_result'), ('idle', 'cancel'): ('idle', 'report_unknown')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'enqueue':
            r['queue'].append(seed)
        elif action == 'start_command':
            r['running']=True; r['executions']+=1
        elif action == 'remove_and_ack':
            r['queue']=[]; r['reported'].append('cancelled')
        elif action == 'request_stop':
            r['stop_requested']=True
        elif action == 'ack_cancel':
            r['running']=False; r['reported'].append('cancelled')
        elif action == 'report_result':
            r['reported'].append(r['result'][:])
        elif action == 'report_already_done':
            r['reported'].append('already_done')
        elif action == 'discard_late_result':
            r['result']=[]
        elif action == 'report_unknown':
            r['reported'].append('unknown')
        elif action == 'execute':
            r['running']=True; r['executions']+=1
        elif action == 'ack_result':
            r['reported'].append(r['result'][:])
        elif action == 'report_success':
            r['reported'].append('success')
        elif action == 'enqueue_again':
            r['queue'].append(seed)
        elif action == 'ack_without_remove':
            r['reported'].append('cancelled')
        elif action == 'report_pending':
            r['reported'].append('pending')
        elif action == 'discard_result':
            r['result']=[]
        else:
            if action not in ("wait", "ignore", "keep", "retain", "keep_peer", "keep_offer", "keep_hold", "keep_batch", "retain_staging", "keep_staging", "keep_local_owner", "keep_old_session", "keep_address", "keep_old_expiry", "ignore_conflict", "keep_service", "keep_subscription", "retain_shadow", "keep_live", "keep_suspicion", "keep_roles", "keep_staged"):
                frames.append([action, payload[:]])
        observed.append(json.loads(json.dumps({"phase": phase, "registers": r, "frames": frames})))
    return observed
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [1], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [1], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [1], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [[1, 2, 3], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [1, 2, 3], 'reported': [], 'executions': 0}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [2], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [2], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [2], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [[2, 3, 4, 5], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [2, 3, 4, 5], 'reported': [], 'executions': 0}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [3], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [3], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [3], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [[3, 4, 5, 6, 7], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [3, 4, 5, 6, 7], 'reported': [], 'executions': 0}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [4], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [4], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [4], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [[4, 5, 6, 7, 8, 9], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [4, 5, 6, 7, 8, 9], 'reported': [], 'executions': 0}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/submit', 'idle', ['submit'], [{'phase': 'queued', 'registers': {'queue': [5], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}]), ('queued/dispatch', 'queued', ['dispatch'], [{'phase': 'running', 'registers': {'queue': [5], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 1}, 'frames': []}]), ('queued/cancel', 'queued', ['cancel'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('running/cancel', 'running', ['cancel'], [{'phase': 'cancelling', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}]), ('cancelling/stopped', 'cancelling', ['stopped'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('cancelling/completed_first', 'cancelling', ['completed_first'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': True, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}]), ('running/completed', 'running', ['completed'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}]), ('done/cancel', 'done', ['cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['already_done'], 'executions': 0}, 'frames': []}]), ('cancelled/late_completion', 'cancelled', ['late_completion'], [{'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': [], 'executions': 0}, 'frames': []}]), ('idle/cancel', 'idle', ['cancel'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['unknown'], 'executions': 0}, 'frames': []}]), ('ordered trace 0', 'idle', ['submit', 'cancel', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion', 'late_completion'], [{'phase': 'queued', 'registers': {'queue': [5], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}, {'phase': 'cancelled', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [], 'reported': ['cancelled'], 'executions': 0}, 'frames': []}]), ('ordered trace 3', 'running', ['completed', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel', 'cancel'], [{'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11]], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}, {'phase': 'done', 'registers': {'queue': [], 'running': True, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [[5, 6, 7, 8, 9, 10, 11], 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done', 'already_done'], 'executions': 0}, 'frames': []}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'queue': [], 'running': False, 'stop_requested': False, 'result': [5, 6, 7, 8, 9, 10, 11], 'reported': [], 'executions': 0}, '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 done, event cancel produces cancelled/ack_cancel instead of done/report_already_done.

For the stipulated Asynchronous command cancellation 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