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 = {'partial': [seed-1] if phase=='collecting' else [], 'published': [payload[:]] if phase=='complete' else [], 'owned': phase!='idle', 'discarded': []}
    frames = []
    observed = []
    table = {('idle', 'begin'): ('collecting', 'start_message'), ('collecting', 'middle'): ('collecting', 'append'), ('collecting', 'end'): ('complete', 'append_publish'), ('idle', 'middle'): ('idle', 'reject_orphan'), ('idle', 'end'): ('complete', 'publish'), ('collecting', 'begin'): ('collecting', 'reject_nested'), ('collecting', 'abort'): ('idle', 'discard_partial'), ('complete', 'consume'): ('idle', 'release_message'), ('complete', 'middle'): ('complete', 'reject_sealed'), ('collecting', 'oversize'): ('idle', 'reject_discard')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'start_message':
            r['partial']=payload[:]
        elif action == 'append':
            r['partial'].extend(payload)
        elif action == 'append_publish':
            r['partial'].extend(payload); r['published'].append(r['partial'][:])
        elif action == 'reject_orphan':
            frames.append(['ORPHAN',event])
        elif action == 'reject_nested':
            frames.append(['NESTED_BEGIN',len(r['partial'])])
        elif action == 'discard_partial':
            r['discarded'].extend(r['partial']); r['partial']=[]
        elif action == 'release_message':
            r['owned']=False
        elif action == 'reject_sealed':
            frames.append(['SEALED',event])
        elif action == 'reject_discard':
            r['partial']=[]; frames.append(['TOO_LARGE',len(payload)])
        elif action == 'publish':
            r['published'].append(r['partial'][:])
        elif action == 'publish_without_end':
            r['published'].append(r['partial'][:])
        elif action == 'replace':
            r['partial']=payload[:]
        elif action == 'buffer':
            r['partial'].extend(payload)
        elif action == 'ack':
            frames.append(['MESSAGE_OK',seed])
        elif action == 'restart':
            r['partial']=payload[:]
        elif action == 'discard':
            r['partial']=[]
        elif action == 'keep_partial':
            r['owned']=False
        elif action == 'retain':
            r['owned']=True
        elif action == 'discard_unread':
            r['published']=[]
        elif action == 'truncate':
            r['partial']=r['partial'][:1]
        elif action == 'publish_prefix':
            r['published'].append(r['partial'][: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: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [0, 1, 2, 3], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [0, 1, 2, 3], 'published': [[0, 1, 2, 3]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [0], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [0]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[1, 2, 3]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 3]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [1, 2, 3, 1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [1, 2, 3, 1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3], ['ORPHAN', 'end']]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3, 4, 5], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [1, 2, 3, 4, 5], 'published': [[1, 2, 3, 4, 5]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [1], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [1]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[2, 3, 4, 5]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [2, 3, 4, 5, 2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [2, 3, 4, 5, 2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end'], ['NESTED_BEGIN', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5, 6, 7], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [2, 3, 4, 5, 6, 7], 'published': [[2, 3, 4, 5, 6, 7]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [2], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [2]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end'], ['NESTED_BEGIN', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [3, 4, 5, 6, 7]}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end'], ['NESTED_BEGIN', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7, 8, 9], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [3, 4, 5, 6, 7, 8, 9], 'published': [[3, 4, 5, 6, 7, 8, 9]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [3], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [3]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [4, 5, 6, 7, 8, 9]}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': [4, 5, 6, 7, 8, 9]}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 10, 11], 'published': [[4, 5, 6, 7, 8, 9, 10, 11]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [4], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [4]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end', 'begin', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort', 'begin', 'middle'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, '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 = {'partial': [seed-1] if phase=='collecting' else [], 'published': [payload[:]] if phase=='complete' else [], 'owned': phase!='idle', 'discarded': []}
    frames = []
    observed = []
    table = {('idle', 'begin'): ('collecting', 'start_message'), ('collecting', 'middle'): ('collecting', 'append'), ('collecting', 'end'): ('complete', 'append_publish'), ('idle', 'middle'): ('idle', 'reject_orphan'), ('idle', 'end'): ('idle', 'ack'), ('collecting', 'begin'): ('collecting', 'reject_nested'), ('collecting', 'abort'): ('idle', 'discard_partial'), ('complete', 'consume'): ('idle', 'release_message'), ('complete', 'middle'): ('complete', 'reject_sealed'), ('collecting', 'oversize'): ('idle', 'reject_discard')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'start_message':
            r['partial']=payload[:]
        elif action == 'append':
            r['partial'].extend(payload)
        elif action == 'append_publish':
            r['partial'].extend(payload); r['published'].append(r['partial'][:])
        elif action == 'reject_orphan':
            frames.append(['ORPHAN',event])
        elif action == 'reject_nested':
            frames.append(['NESTED_BEGIN',len(r['partial'])])
        elif action == 'discard_partial':
            r['discarded'].extend(r['partial']); r['partial']=[]
        elif action == 'release_message':
            r['owned']=False
        elif action == 'reject_sealed':
            frames.append(['SEALED',event])
        elif action == 'reject_discard':
            r['partial']=[]; frames.append(['TOO_LARGE',len(payload)])
        elif action == 'publish':
            r['published'].append(r['partial'][:])
        elif action == 'publish_without_end':
            r['published'].append(r['partial'][:])
        elif action == 'replace':
            r['partial']=payload[:]
        elif action == 'buffer':
            r['partial'].extend(payload)
        elif action == 'ack':
            frames.append(['MESSAGE_OK',seed])
        elif action == 'restart':
            r['partial']=payload[:]
        elif action == 'discard':
            r['partial']=[]
        elif action == 'keep_partial':
            r['owned']=False
        elif action == 'retain':
            r['owned']=True
        elif action == 'discard_unread':
            r['published']=[]
        elif action == 'truncate':
            r['partial']=r['partial'][:1]
        elif action == 'publish_prefix':
            r['published'].append(r['partial'][: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: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [0, 1, 2, 3], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [0, 1, 2, 3], 'published': [[0, 1, 2, 3]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [0], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [0]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[1, 2, 3]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 3]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [1, 2, 3, 1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [1, 2, 3, 1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [[1, 2, 3, 1, 2, 3]], 'owned': False, 'discarded': []}, 'frames': []}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [1, 2, 3], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 3], ['ORPHAN', 'end']]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [1, 2, 3, 4, 5], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [1, 2, 3, 4, 5], 'published': [[1, 2, 3, 4, 5]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [1], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [1]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[2, 3, 4, 5]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [2, 3, 4, 5, 2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [2, 3, 4, 5, 2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[2, 3, 4, 5, 2, 3, 4, 5]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 4], ['ORPHAN', 'end'], ['NESTED_BEGIN', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [2, 3, 4, 5, 6, 7], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [2, 3, 4, 5, 6, 7], 'published': [[2, 3, 4, 5, 6, 7]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [2], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [2]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[3, 4, 5, 6, 7, 3, 4, 5, 6, 7]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end'], ['NESTED_BEGIN', 5]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [3, 4, 5, 6, 7]}, 'frames': [['TOO_LARGE', 5], ['ORPHAN', 'end'], ['NESTED_BEGIN', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [3, 4, 5, 6, 7, 8, 9], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [3, 4, 5, 6, 7, 8, 9], 'published': [[3, 4, 5, 6, 7, 8, 9]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [3], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [3]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [[4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [4, 5, 6, 7, 8, 9]}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}, {'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9], 'published': [], 'owned': False, 'discarded': [4, 5, 6, 7, 8, 9]}, 'frames': [['TOO_LARGE', 6], ['ORPHAN', 'end'], ['NESTED_BEGIN', 6]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}]), ('collecting/middle', 'collecting', ['middle'], [{'phase': 'collecting', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': True, 'discarded': []}, 'frames': []}]), ('collecting/end', 'collecting', ['end'], [{'phase': 'complete', 'registers': {'partial': [4, 5, 6, 7, 8, 9, 10, 11], 'published': [[4, 5, 6, 7, 8, 9, 10, 11]], 'owned': True, 'discarded': []}, 'frames': []}]), ('idle/middle', 'idle', ['middle'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'middle']]}]), ('idle/end', 'idle', ['end'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['ORPHAN', 'end']]}]), ('collecting/begin', 'collecting', ['begin'], [{'phase': 'collecting', 'registers': {'partial': [4], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['NESTED_BEGIN', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': [4]}, 'frames': []}]), ('complete/consume', 'complete', ['consume'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}]), ('complete/middle', 'complete', ['middle'], [{'phase': 'complete', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11]], 'owned': True, 'discarded': []}, 'frames': [['SEALED', 'middle']]}]), ('collecting/oversize', 'collecting', ['oversize'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': True, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}]), ('ordered trace 0', 'idle', ['begin', 'end', 'consume', 'begin', 'oversize', 'end', 'begin', 'begin'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'complete', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [[5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11]], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}]), ('ordered trace 3', 'idle', ['begin', 'oversize', 'end', 'begin', 'begin', 'abort', 'begin', 'middle'], [{'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': []}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end']]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': []}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}, {'phase': 'collecting', 'registers': {'partial': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'published': [], 'owned': False, 'discarded': [5, 6, 7, 8, 9, 10, 11]}, 'frames': [['TOO_LARGE', 7], ['ORPHAN', 'end'], ['NESTED_BEGIN', 7]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'partial': [], 'published': [], 'owned': False, 'discarded': []}, '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 idle, event end produces complete/publish instead of idle/reject_orphan.

For the stipulated Segmented message assembly 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