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 = {'available': seed+2, 'held': int(phase=='tentative'), 'committed': int(phase in ('reserved','in_use')), 'uses': int(phase=='in_use'), 'receipts': []}
    frames = []
    observed = []
    table = {('free', 'request'): ('tentative', 'hold_resource'), ('tentative', 'confirm'): ('reserved', 'commit_hold'), ('tentative', 'decline'): ('free', 'release_hold'), ('tentative', 'hold_expired'): ('free', 'notify_expired'), ('reserved', 'use'): ('in_use', 'start_use'), ('in_use', 'finish'): ('free', 'release_and_receipt'), ('reserved', 'cancel'): ('reserved', 'keep'), ('free', 'confirm'): ('free', 'reject_expired'), ('in_use', 'cancel'): ('in_use', 'reject_busy'), ('reserved', 'duplicate_confirm'): ('reserved', 'repeat_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'hold_resource':
            r['available']-=1; r['held']+=1
        elif action == 'commit_hold':
            r['held']-=1; r['committed']+=1
        elif action == 'release_hold':
            r['available']+=r['held']; r['held']=0
        elif action == 'notify_expired':
            r['available']+=r['held']; r['held']=0; frames.append(['EXPIRED',seed])
        elif action == 'start_use':
            r['uses']+=1
        elif action == 'release_and_receipt':
            r['available']+=1; r['committed']=0; r['receipts'].append('finished')
        elif action == 'release_and_cancel_ack':
            r['available']+=1; r['committed']=0; r['receipts'].append('cancelled')
        elif action == 'reject_expired':
            frames.append(['EXPIRED_CONFIRM',seed])
        elif action == 'reject_busy':
            frames.append(['BUSY',seed])
        elif action == 'repeat_receipt':
            frames.append(['RESERVED',seed])
        elif action == 'confirm':
            frames.append(['RESERVED',seed])
        elif action == 'release':
            r['available']+=1; r['committed']=0
        elif action == 'allocate_second':
            r['available']-=1; r['committed']+=1
        elif action == 'silent_release':
            r['available']+=r['held']; r['held']=0
        elif action == 'release_only':
            r['available']+=1; r['committed']=0
        elif action == 'allocate':
            r['available']-=1; r['committed']+=1
        elif action == 'ack_cancel':
            frames.append(['CANCELLED',seed])
        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: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 1]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 1]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 1]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 2, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 2]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 2]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 2]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 3]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 3]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 3]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 4]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 4]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 4]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 5]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 5]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 5]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled', 'cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, '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 = {'available': seed+2, 'held': int(phase=='tentative'), 'committed': int(phase in ('reserved','in_use')), 'uses': int(phase=='in_use'), 'receipts': []}
    frames = []
    observed = []
    table = {('free', 'request'): ('tentative', 'hold_resource'), ('tentative', 'confirm'): ('reserved', 'commit_hold'), ('tentative', 'decline'): ('free', 'release_hold'), ('tentative', 'hold_expired'): ('free', 'notify_expired'), ('reserved', 'use'): ('in_use', 'start_use'), ('in_use', 'finish'): ('free', 'release_and_receipt'), ('reserved', 'cancel'): ('free', 'release_only'), ('free', 'confirm'): ('free', 'reject_expired'), ('in_use', 'cancel'): ('in_use', 'reject_busy'), ('reserved', 'duplicate_confirm'): ('reserved', 'repeat_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'hold_resource':
            r['available']-=1; r['held']+=1
        elif action == 'commit_hold':
            r['held']-=1; r['committed']+=1
        elif action == 'release_hold':
            r['available']+=r['held']; r['held']=0
        elif action == 'notify_expired':
            r['available']+=r['held']; r['held']=0; frames.append(['EXPIRED',seed])
        elif action == 'start_use':
            r['uses']+=1
        elif action == 'release_and_receipt':
            r['available']+=1; r['committed']=0; r['receipts'].append('finished')
        elif action == 'release_and_cancel_ack':
            r['available']+=1; r['committed']=0; r['receipts'].append('cancelled')
        elif action == 'reject_expired':
            frames.append(['EXPIRED_CONFIRM',seed])
        elif action == 'reject_busy':
            frames.append(['BUSY',seed])
        elif action == 'repeat_receipt':
            frames.append(['RESERVED',seed])
        elif action == 'confirm':
            frames.append(['RESERVED',seed])
        elif action == 'release':
            r['available']+=1; r['committed']=0
        elif action == 'allocate_second':
            r['available']-=1; r['committed']+=1
        elif action == 'silent_release':
            r['available']+=r['held']; r['held']=0
        elif action == 'release_only':
            r['available']+=1; r['committed']=0
        elif action == 'allocate':
            r['available']-=1; r['committed']+=1
        elif action == 'ack_cancel':
            frames.append(['CANCELLED',seed])
        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: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 1]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 1]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 1]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 2, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 2]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 2]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 2]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 3]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 3]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 3]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 4]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 4]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 4]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 5]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 5]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 5]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled', 'cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, '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 reserved, event cancel produces reserved/keep instead of free/release_and_cancel_ack.

For the stipulated Two-party resource reservation 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


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 = {'available': seed+2, 'held': int(phase=='tentative'), 'committed': int(phase in ('reserved','in_use')), 'uses': int(phase=='in_use'), 'receipts': []}
    frames = []
    observed = []
    table = {('free', 'request'): ('tentative', 'hold_resource'), ('tentative', 'confirm'): ('reserved', 'commit_hold'), ('tentative', 'decline'): ('free', 'release_hold'), ('tentative', 'hold_expired'): ('free', 'notify_expired'), ('reserved', 'use'): ('in_use', 'start_use'), ('in_use', 'finish'): ('free', 'release_and_receipt'), ('reserved', 'cancel'): ('free', 'release_and_cancel_ack'), ('free', 'confirm'): ('reserved', 'allocate'), ('in_use', 'cancel'): ('in_use', 'reject_busy'), ('reserved', 'duplicate_confirm'): ('reserved', 'repeat_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'hold_resource':
            r['available']-=1; r['held']+=1
        elif action == 'commit_hold':
            r['held']-=1; r['committed']+=1
        elif action == 'release_hold':
            r['available']+=r['held']; r['held']=0
        elif action == 'notify_expired':
            r['available']+=r['held']; r['held']=0; frames.append(['EXPIRED',seed])
        elif action == 'start_use':
            r['uses']+=1
        elif action == 'release_and_receipt':
            r['available']+=1; r['committed']=0; r['receipts'].append('finished')
        elif action == 'release_and_cancel_ack':
            r['available']+=1; r['committed']=0; r['receipts'].append('cancelled')
        elif action == 'reject_expired':
            frames.append(['EXPIRED_CONFIRM',seed])
        elif action == 'reject_busy':
            frames.append(['BUSY',seed])
        elif action == 'repeat_receipt':
            frames.append(['RESERVED',seed])
        elif action == 'confirm':
            frames.append(['RESERVED',seed])
        elif action == 'release':
            r['available']+=1; r['committed']=0
        elif action == 'allocate_second':
            r['available']-=1; r['committed']+=1
        elif action == 'silent_release':
            r['available']+=r['held']; r['held']=0
        elif action == 'release_only':
            r['available']+=1; r['committed']=0
        elif action == 'allocate':
            r['available']-=1; r['committed']+=1
        elif action == 'ack_cancel':
            frames.append(['CANCELLED',seed])
        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: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 1]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 1]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 1]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 2, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 2]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 2]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 2]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 3]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 3]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 3]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 4]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 4]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 4]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 5]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 5]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 5]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled', 'cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, '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 = {'available': seed+2, 'held': int(phase=='tentative'), 'committed': int(phase in ('reserved','in_use')), 'uses': int(phase=='in_use'), 'receipts': []}
    frames = []
    observed = []
    table = {('free', 'request'): ('tentative', 'hold_resource'), ('tentative', 'confirm'): ('reserved', 'commit_hold'), ('tentative', 'decline'): ('free', 'release_hold'), ('tentative', 'hold_expired'): ('free', 'notify_expired'), ('reserved', 'use'): ('in_use', 'start_use'), ('in_use', 'finish'): ('free', 'release_and_receipt'), ('reserved', 'cancel'): ('free', 'release_and_cancel_ack'), ('free', 'confirm'): ('tentative', 'hold_resource'), ('in_use', 'cancel'): ('in_use', 'reject_busy'), ('reserved', 'duplicate_confirm'): ('reserved', 'repeat_receipt')}
    for event in events:
        phase, action = table.get((phase, event), (phase, "reject"))
        if action == 'hold_resource':
            r['available']-=1; r['held']+=1
        elif action == 'commit_hold':
            r['held']-=1; r['committed']+=1
        elif action == 'release_hold':
            r['available']+=r['held']; r['held']=0
        elif action == 'notify_expired':
            r['available']+=r['held']; r['held']=0; frames.append(['EXPIRED',seed])
        elif action == 'start_use':
            r['uses']+=1
        elif action == 'release_and_receipt':
            r['available']+=1; r['committed']=0; r['receipts'].append('finished')
        elif action == 'release_and_cancel_ack':
            r['available']+=1; r['committed']=0; r['receipts'].append('cancelled')
        elif action == 'reject_expired':
            frames.append(['EXPIRED_CONFIRM',seed])
        elif action == 'reject_busy':
            frames.append(['BUSY',seed])
        elif action == 'repeat_receipt':
            frames.append(['RESERVED',seed])
        elif action == 'confirm':
            frames.append(['RESERVED',seed])
        elif action == 'release':
            r['available']+=1; r['committed']=0
        elif action == 'allocate_second':
            r['available']-=1; r['committed']+=1
        elif action == 'silent_release':
            r['available']+=r['held']; r['held']=0
        elif action == 'release_only':
            r['available']+=1; r['committed']=0
        elif action == 'allocate':
            r['available']-=1; r['committed']+=1
        elif action == 'ack_cancel':
            frames.append(['CANCELLED',seed])
        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: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 1]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 1]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 1]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 2, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 2, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request'], [{'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 1]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 3, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [1, 2, 3]]]}])], 2: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 2]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 2]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 2]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 3, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 3, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 2]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 4, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [2, 3, 4, 5]]]}])], 3: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 3]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 3]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 3]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm'], [{'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 4, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 4, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request'], [{'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 3]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 5, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [3, 4, 5, 6, 7]]]}])], 4: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 4]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 4]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 4]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request'], [{'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 5, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 5, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm'], [{'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 4]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 6, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['reject', [4, 5, 6, 7, 8, 9]]]}])], 5: [('free/request', 'free', ['request'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/confirm', 'tentative', ['confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/decline', 'tentative', ['decline'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}]), ('tentative/hold_expired', 'tentative', ['hold_expired'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED', 5]]}]), ('reserved/use', 'reserved', ['use'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': []}]), ('in_use/finish', 'in_use', ['finish'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 1, 'receipts': ['finished']}, 'frames': []}]), ('reserved/cancel', 'reserved', ['cancel'], [{'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}]), ('free/confirm', 'free', ['confirm'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('in_use/cancel', 'in_use', ['cancel'], [{'phase': 'in_use', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 1, 'receipts': []}, 'frames': [['BUSY', 5]]}]), ('reserved/duplicate_confirm', 'reserved', ['duplicate_confirm'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': [['RESERVED', 5]]}]), ('ordered trace 0', 'free', ['request', 'decline', 'request', 'confirm', 'cancel', 'confirm', 'request', 'decline'], [{'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'reserved', 'registers': {'available': 6, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 6, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('ordered trace 3', 'tentative', ['confirm', 'cancel', 'confirm', 'request', 'decline', 'request', 'confirm', 'cancel'], [{'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': []}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': []}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'tentative', 'registers': {'available': 7, 'held': 1, 'committed': 0, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'reserved', 'registers': {'available': 7, 'held': 0, 'committed': 1, 'uses': 0, 'receipts': ['cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}, {'phase': 'free', 'registers': {'available': 8, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': ['cancelled', 'cancelled']}, 'frames': [['EXPIRED_CONFIRM', 5]]}]), ('empty input', 'free', [], []), ('unknown event', 'free', ['unsupported'], [{'phase': 'free', 'registers': {'available': 7, 'held': 0, 'committed': 0, 'uses': 0, 'receipts': []}, '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 free, event confirm produces reserved/allocate instead of free/reject_expired.

For the stipulated Two-party resource reservation 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