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 = {'staging': [seed-1], 'live': [seed-2], 'allocated': phase in ('receiving','verifying'), 'verified': phase=='installed', 'activations': 0}
    frames = []
    observed = []
    table = {('idle', 'offer'): ('manifest', 'request_manifest'), ('manifest', 'compatible'): ('receiving', 'allocate_staging'), ('manifest', 'incompatible'): ('idle', 'reject_offer'), ('receiving', 'chunk'): ('receiving', 'write_staging'), ('receiving', 'end'): ('verifying', 'verify_manifest'), ('verifying', 'valid'): ('installed', 'atomic_activate'), ('verifying', 'invalid'): ('idle', 'discard_staging'), ('receiving', 'cancel'): ('receiving', 'pause'), ('installed', 'duplicate_end'): ('installed', 'ack_installed'), ('idle', 'chunk'): ('idle', 'reject_unoffered')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'request_manifest':
            frames.append(['MANIFEST_REQUEST',seed])
        elif action == 'allocate_staging':
            r['allocated']=True; r['staging']=[]
        elif action == 'reject_offer':
            frames.append(['INCOMPATIBLE',seed])
        elif action == 'write_staging':
            r['staging'].extend(payload)
        elif action == 'verify_manifest':
            r['verified']=True
        elif action == 'atomic_activate':
            r['live']=r['staging'][:]; r['activations']+=1; r['staging']=[]
        elif action == 'discard_staging':
            r['staging']=[]; r['allocated']=False
        elif action == 'remove_staging':
            r['staging']=[]; r['allocated']=False
        elif action == 'ack_installed':
            frames.append(['INSTALLED',seed])
        elif action == 'reject_unoffered':
            frames.append(['UNSOLICITED_CHUNK',seed])
        elif action == 'write_chunks':
            r['staging'].extend(payload)
        elif action == 'accept_complete':
            frames.append(['INSTALLED',seed])
        elif action == 'activate':
            r['live']=r['staging'][:]; r['activations']+=1
        elif action == 'write_live':
            r['live'].extend(payload)
        elif action == 'ack_complete':
            frames.append(['INSTALLED',seed])
        elif action == 'copy_partial':
            r['live']=r['staging'][:1]; r['activations']+=1
        elif action == 'activate_again':
            r['activations']+=1
        elif action == 'pause':
            pass
        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/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 1]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [0], 'live': [-1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [0], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 1]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 1]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}, {'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1]]}, {'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1], ['MANIFEST_REQUEST', 1]]}, {'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1], ['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 2]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [1], 'live': [0], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [1], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 2]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 2]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}, {'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}, {'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible'], [{'phase': 'receiving', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 3]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [2], 'live': [1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [2], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 3]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 3]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 4]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [3], 'live': [2], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [3], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 4]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 4]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'receiving', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 5]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [4], 'live': [3], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [4], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 5]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 5]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(phase, events, seed):
    payload = list(range(seed, seed * 2 + 2))
    r = {'staging': [seed-1], 'live': [seed-2], 'allocated': phase in ('receiving','verifying'), 'verified': phase=='installed', 'activations': 0}
    frames = []
    observed = []
    table = {('idle', 'offer'): ('manifest', 'request_manifest'), ('manifest', 'compatible'): ('receiving', 'allocate_staging'), ('manifest', 'incompatible'): ('idle', 'reject_offer'), ('receiving', 'chunk'): ('receiving', 'write_staging'), ('receiving', 'end'): ('verifying', 'verify_manifest'), ('verifying', 'valid'): ('installed', 'atomic_activate'), ('verifying', 'invalid'): ('idle', 'discard_staging'), ('receiving', 'cancel'): ('idle', 'keep_staging'), ('installed', 'duplicate_end'): ('installed', 'ack_installed'), ('idle', 'chunk'): ('idle', 'reject_unoffered')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'request_manifest':
            frames.append(['MANIFEST_REQUEST',seed])
        elif action == 'allocate_staging':
            r['allocated']=True; r['staging']=[]
        elif action == 'reject_offer':
            frames.append(['INCOMPATIBLE',seed])
        elif action == 'write_staging':
            r['staging'].extend(payload)
        elif action == 'verify_manifest':
            r['verified']=True
        elif action == 'atomic_activate':
            r['live']=r['staging'][:]; r['activations']+=1; r['staging']=[]
        elif action == 'discard_staging':
            r['staging']=[]; r['allocated']=False
        elif action == 'remove_staging':
            r['staging']=[]; r['allocated']=False
        elif action == 'ack_installed':
            frames.append(['INSTALLED',seed])
        elif action == 'reject_unoffered':
            frames.append(['UNSOLICITED_CHUNK',seed])
        elif action == 'write_chunks':
            r['staging'].extend(payload)
        elif action == 'accept_complete':
            frames.append(['INSTALLED',seed])
        elif action == 'activate':
            r['live']=r['staging'][:]; r['activations']+=1
        elif action == 'write_live':
            r['live'].extend(payload)
        elif action == 'ack_complete':
            frames.append(['INSTALLED',seed])
        elif action == 'copy_partial':
            r['live']=r['staging'][:1]; r['activations']+=1
        elif action == 'activate_again':
            r['activations']+=1
        elif action == 'pause':
            pass
        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/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 1]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [0], 'live': [-1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [0], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 1]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 1]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}, {'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1]]}, {'phase': 'manifest', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1], ['MANIFEST_REQUEST', 1]]}, {'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1], ['MANIFEST_REQUEST', 1], ['INCOMPATIBLE', 1]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [0, 1, 2, 3], 'live': [-1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [-1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 1]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [0], 'live': [-1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 2]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [1], 'live': [0], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [1], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 2]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 2]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}, {'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}, {'phase': 'manifest', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2], ['MANIFEST_REQUEST', 2]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible'], [{'phase': 'receiving', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [1, 2, 3, 4, 5], 'live': [0], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [0], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 2], ['INCOMPATIBLE', 2]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [1], 'live': [0], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 3]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [2], 'live': [1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [2], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 3]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 3]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [2, 3, 4, 5, 6, 7], 'live': [1], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [1], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 3], ['INCOMPATIBLE', 3], ['MANIFEST_REQUEST', 3]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [2], 'live': [1], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 4]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [3], 'live': [2], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [3], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 4]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 4]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'receiving', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [3, 4, 5, 6, 7, 8, 9], 'live': [2], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [2], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4], ['MANIFEST_REQUEST', 4], ['INCOMPATIBLE', 4]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [3], 'live': [2], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('idle/offer', 'idle', ['offer'], [{'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}]), ('manifest/compatible', 'manifest', ['compatible'], [{'phase': 'receiving', 'registers': {'staging': [], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('manifest/incompatible', 'manifest', ['incompatible'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['INCOMPATIBLE', 5]]}]), ('receiving/chunk', 'receiving', ['chunk'], [{'phase': 'receiving', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/end', 'receiving', ['end'], [{'phase': 'verifying', 'registers': {'staging': [4], 'live': [3], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}]), ('verifying/valid', 'verifying', ['valid'], [{'phase': 'installed', 'registers': {'staging': [], 'live': [4], 'allocated': True, 'verified': False, 'activations': 1}, 'frames': []}]), ('verifying/invalid', 'verifying', ['invalid'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('receiving/cancel', 'receiving', ['cancel'], [{'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': []}]), ('installed/duplicate_end', 'installed', ['duplicate_end'], [{'phase': 'installed', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['INSTALLED', 5]]}]), ('idle/chunk', 'idle', ['chunk'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['UNSOLICITED_CHUNK', 5]]}]), ('ordered trace 0', 'idle', ['offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible', 'offer', 'incompatible'], [{'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}]), ('ordered trace 3', 'receiving', ['chunk', 'end', 'invalid', 'offer', 'incompatible', 'offer', 'incompatible', 'offer'], [{'phase': 'receiving', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': False, 'activations': 0}, 'frames': []}, {'phase': 'verifying', 'registers': {'staging': [4, 5, 6, 7, 8, 9, 10, 11], 'live': [3], 'allocated': True, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': []}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}, {'phase': 'idle', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5]]}, {'phase': 'manifest', 'registers': {'staging': [], 'live': [3], 'allocated': False, 'verified': True, 'activations': 0}, 'frames': [['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5], ['INCOMPATIBLE', 5], ['MANIFEST_REQUEST', 5]]}]), ('empty input', 'idle', [], []), ('unknown event', 'idle', ['unsupported'], [{'phase': 'idle', 'registers': {'staging': [4], 'live': [3], 'allocated': False, 'verified': False, 'activations': 0}, 'frames': [['reject', [5, 6, 7, 8, 9, 10, 11]]]}])]}
for label, phase, events, expected in cases[N]:
    check(label, solve(phase, events, N), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
While receiving, event cancel produces receiving/pause instead of idle/remove_staging.

For the stipulated Checkpoint transfer boundary 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