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 = {'staged': payload[:] if phase in ('collecting','sealed') else [], 'application': [seed-1], 'sealed': phase in ('sealed','committed'), 'receipt': seed if phase=='committed' else None, 'valid': True}
    frames = []
    observed = []
    table = {('idle', 'begin'): ('collecting', 'create_batch'), ('collecting', 'operation'): ('collecting', 'stage_operation'), ('collecting', 'seal'): ('sealed', 'freeze_batch'), ('sealed', 'commit'): ('committed', 'apply_once'), ('collecting', 'commit'): ('collecting', 'reject_unsealed'), ('sealed', 'operation'): ('sealed', 'reject_sealed'), ('collecting', 'abort'): ('idle', 'discard_batch'), ('committed', 'duplicate_commit'): ('committed', 'repeat_receipt'), ('sealed', 'validation_failed'): ('committed', 'apply'), ('committed', 'receipt_consumed'): ('idle', 'release_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'create_batch':
            r['staged']=[]; r['sealed']=False
        elif action == 'stage_operation':
            r['staged'].extend(payload)
        elif action == 'freeze_batch':
            r['sealed']=True
        elif action == 'apply_once':
            r['application'].extend(r['staged']); r['staged']=[]
        elif action == 'reject_unsealed':
            frames.append(['UNSEALED',seed])
        elif action == 'reject_sealed':
            frames.append(['SEALED',seed])
        elif action == 'discard_batch':
            r['staged']=[]
        elif action == 'repeat_receipt':
            frames.append(['COMMITTED',r['receipt']])
        elif action == 'reject_discard':
            r['staged']=[]; frames.append(['INVALID',seed])
        elif action == 'release_receipt':
            r['receipt']=None
        elif action == 'apply':
            r['application'].extend(r['staged'])
        elif action == 'apply_operation':
            r['application'].extend(payload)
        elif action == 'replace_operations':
            r['staged']=payload[:]
        elif action == 'allow_append':
            r['sealed']=False
        elif action == 'apply_reversed':
            r['application'].extend(reversed(r['staged'])); r['staged']=[]
        elif action == 'discard':
            r['staged']=[]
        elif action == 'discard_receipt':
            r['receipt']=None
        elif action == 'clear_application':
            r['application']=[]
        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': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [1, 2, 3, 1, 2, 3], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 1]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': 1, 'valid': True}, 'frames': [['COMMITTED', 1]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5, 2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 2]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 2]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': 2, 'valid': True}, 'frames': [['COMMITTED', 2]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}, {'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 3]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 3]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': 3, 'valid': True}, 'frames': [['COMMITTED', 3]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 4]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 4]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': 4, 'valid': True}, 'frames': [['COMMITTED', 4]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal', 'commit'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin', 'seal'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 5]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 5]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': 5, 'valid': True}, 'frames': [['COMMITTED', 5]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal', 'commit', 'receipt_consumed'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin', 'seal', 'operation'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None], ['SEALED', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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 = {'staged': payload[:] if phase in ('collecting','sealed') else [], 'application': [seed-1], 'sealed': phase in ('sealed','committed'), 'receipt': seed if phase=='committed' else None, 'valid': True}
    frames = []
    observed = []
    table = {('idle', 'begin'): ('collecting', 'create_batch'), ('collecting', 'operation'): ('collecting', 'stage_operation'), ('collecting', 'seal'): ('sealed', 'freeze_batch'), ('sealed', 'commit'): ('committed', 'apply_once'), ('collecting', 'commit'): ('collecting', 'reject_unsealed'), ('sealed', 'operation'): ('sealed', 'reject_sealed'), ('collecting', 'abort'): ('idle', 'discard_batch'), ('committed', 'duplicate_commit'): ('committed', 'repeat_receipt'), ('sealed', 'validation_failed'): ('idle', 'keep_batch'), ('committed', 'receipt_consumed'): ('idle', 'release_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'create_batch':
            r['staged']=[]; r['sealed']=False
        elif action == 'stage_operation':
            r['staged'].extend(payload)
        elif action == 'freeze_batch':
            r['sealed']=True
        elif action == 'apply_once':
            r['application'].extend(r['staged']); r['staged']=[]
        elif action == 'reject_unsealed':
            frames.append(['UNSEALED',seed])
        elif action == 'reject_sealed':
            frames.append(['SEALED',seed])
        elif action == 'discard_batch':
            r['staged']=[]
        elif action == 'repeat_receipt':
            frames.append(['COMMITTED',r['receipt']])
        elif action == 'reject_discard':
            r['staged']=[]; frames.append(['INVALID',seed])
        elif action == 'release_receipt':
            r['receipt']=None
        elif action == 'apply':
            r['application'].extend(r['staged'])
        elif action == 'apply_operation':
            r['application'].extend(payload)
        elif action == 'replace_operations':
            r['staged']=payload[:]
        elif action == 'allow_append':
            r['sealed']=False
        elif action == 'apply_reversed':
            r['application'].extend(reversed(r['staged'])); r['staged']=[]
        elif action == 'discard':
            r['staged']=[]
        elif action == 'discard_receipt':
            r['receipt']=None
        elif action == 'clear_application':
            r['application']=[]
        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': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [1, 2, 3, 1, 2, 3], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 1]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [1, 2, 3], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 1]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': 1, 'valid': True}, 'frames': [['COMMITTED', 1]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 1]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [0, 1, 2, 3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [0], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5, 2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 2]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 2]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': 2, 'valid': True}, 'frames': [['COMMITTED', 2]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}, {'phase': 'collecting', 'registers': {'staged': [2, 3, 4, 5], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 2]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [1, 2, 3, 4, 5], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [1], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7, 3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 3]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 3]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': 3, 'valid': True}, 'frames': [['COMMITTED', 3]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'collecting', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}, {'phase': 'sealed', 'registers': {'staged': [3, 4, 5, 6, 7], 'application': [2], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 3]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [2, 3, 4, 5, 6, 7], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [2], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 4]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 4]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': 4, 'valid': True}, 'frames': [['COMMITTED', 4]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal', 'commit'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'collecting', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'sealed', 'registers': {'staged': [4, 5, 6, 7, 8, 9], 'application': [3], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}, {'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 4]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin', 'seal'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [3, 4, 5, 6, 7, 8, 9], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [3], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/begin', 'idle', ['begin'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/operation', 'collecting', ['operation'], [{'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11, 5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/seal', 'collecting', ['seal'], [{'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('sealed/commit', 'sealed', ['commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('collecting/commit', 'collecting', ['commit'], [{'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['UNSEALED', 5]]}]), ('sealed/operation', 'sealed', ['operation'], [{'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['SEALED', 5]]}]), ('collecting/abort', 'collecting', ['abort'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}]), ('committed/duplicate_commit', 'committed', ['duplicate_commit'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': 5, 'valid': True}, 'frames': [['COMMITTED', 5]]}]), ('sealed/validation_failed', 'sealed', ['validation_failed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}]), ('committed/receipt_consumed', 'committed', ['receipt_consumed'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}]), ('ordered trace 0', 'idle', ['begin', 'seal', 'validation_failed', 'begin', 'operation', 'seal', 'commit', 'receipt_consumed'], [{'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'collecting', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'sealed', 'registers': {'staged': [5, 6, 7, 8, 9, 10, 11], 'application': [4], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['INVALID', 5]]}]), ('ordered trace 3', 'sealed', ['commit', 'duplicate_commit', 'receipt_consumed', 'begin', 'abort', 'begin', 'seal', 'operation'], [{'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': []}, {'phase': 'committed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'idle', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'collecting', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None]]}, {'phase': 'sealed', 'registers': {'staged': [], 'application': [4, 5, 6, 7, 8, 9, 10, 11], 'sealed': True, 'receipt': None, 'valid': True}, 'frames': [['COMMITTED', None], ['SEALED', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staged': [], 'application': [4], 'sealed': False, 'receipt': None, 'valid': True}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
While sealed, event validation_failed produces committed/apply instead of idle/reject_discard.

For the stipulated Delimited batch command 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