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

N = 1
observations = []
def solve(s):
    return {
        'accept': s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None,
        'drop': s['outer_value'] and (s['active'] or s['subscribing']),
        'queue': [r[0] for r in s['discarded_resources'] if r[1]],
        'replace': [r[0] for r in s['outer_arrivals'] if not r[1]],
        'reserved': ['reserve' in s['reservation_trace'][:i+1] and 'return' not in s['reservation_trace'][:i+1] for i in range(len(s['reservation_trace']))],
        'release': s['inner_done'] and s['done_generation']==s['generation'],
        'finish': max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None,
        'generation': s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']),
        'drops': s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])),
        'detach_inner': (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 2, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 3, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 0, 'drops': 4, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': 1, 'generation': 2, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 3, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 2, 'drops': 4, 'detach_inner': True})], 2: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 0, 'drops': 6, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 4, 'drops': 7, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 1, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 7, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 4, 'drops': 6, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 4, 'drops': 7, 'detach_inner': True})], 3: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 6, 'drops': 10, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 9, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 7, 'drops': 9, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 1, 'generation': 6, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 6, 'drops': 0, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 9, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 6, 'drops': 10, 'detach_inner': True})], 4: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': False, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 9, 'drops': 12, 'detach_inner': False}), ({'active': True, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 12, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 8, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': True, 'finish': None, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 8, 'drops': 13, 'detach_inner': True})], 5: [({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 10, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 10, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 15, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': True, 'finish': 1, 'generation': 1, 'drops': 15, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 10, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 10, 'done_generation': 0, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': 1, 'generation': 10, 'drops': 15, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 10, 'drops': 16, 'detach_inner': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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(s):
    return {
        'accept': s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None,
        'drop': s['outer_value'] and (s['active'] or s['subscribing']),
        'queue': [r[0] for r in s['discarded_resources'] if r[1]],
        'replace': [r[0] for r in s['outer_arrivals'] if not r[1]],
        'reserved': ['reserve' in s['reservation_trace'][:i+1] for i in range(len(s['reservation_trace']))],
        'release': s['inner_done'] and s['done_generation']==s['generation'],
        'finish': max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None,
        'generation': s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']),
        'drops': s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])),
        'detach_inner': (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 2, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 3, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 0, 'drops': 4, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': 1, 'generation': 2, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 3, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 2, 'drops': 4, 'detach_inner': True})], 2: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 0, 'drops': 6, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 4, 'drops': 7, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 1, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 7, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 4, 'drops': 6, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 4, 'drops': 7, 'detach_inner': True})], 3: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 6, 'drops': 10, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 9, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 7, 'drops': 9, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 1, 'generation': 6, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 6, 'drops': 0, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 9, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 6, 'drops': 10, 'detach_inner': True})], 4: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': False, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 9, 'drops': 12, 'detach_inner': False}), ({'active': True, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 12, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 8, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': True, 'finish': None, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 8, 'drops': 13, 'detach_inner': True})], 5: [({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 10, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 10, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 15, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': True, 'finish': 1, 'generation': 1, 'drops': 15, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 10, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 10, 'done_generation': 0, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': 1, 'generation': 10, 'drops': 15, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 10, 'drops': 16, 'detach_inner': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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:
Synchronous inner completion leaves the exhaust startup reservation occupied; the returned lifecycle plan violates the stated transition contract.

Plan an exhaust-style observer: accept a new outer value only while no inner is active; otherwise drop it, never queue or replace. An accepted inner occupies its slot before synchronous subscription side effects. Releasing the current inner allows the next outer value. Outer completion waits for the accepted inner. An error is terminal and rejected outer values consume no inner generation. For one accepted inner, report the earliest trace index at which both outer and inner completion have occurred, independent of later trace records. Suppressed outer values are never queued; their [resource_id,owned] resources are released only when owned by the operator. For recorded [outer_value,inner_active_at_arrival] observations, invoke the inner factory only for arrivals that found the slot idle. For one inner startup, reservation is occupied from reserve until complete, even if completion is synchronous before subscribe returns; return alone does not release it. Inputs are finite state snapshots, including transitional and stale states; output fields are the exact independent actions/metadata defined by the corrected expression table. Numeric fixture capacities and counts vary with N.
Field definitions, each independently computed from the input snapshot: accept = s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None; drop = s['outer_value'] and (s['active'] or s['subscribing']); queue = [r[0] for r in s['discarded_resources'] if r[1]]; replace = [r[0] for r in s['outer_arrivals'] if not r[1]]; reserved = [sum(op=='reserve' for op in s['reservation_trace'][:i+1])>sum(op=='complete' for op in s['reservation_trace'][:i+1]) for i in range(len(s['reservation_trace']))]; release = s['inner_done'] and s['done_generation']==s['generation']; finish = max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None; generation = s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']); drops = s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])); detach_inner = (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None)

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'accept': s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None,
        'drop': s['outer_value'] and (s['active'] or s['subscribing']),
        'queue': [r[0] for r in s['discarded_resources'] if r[1]],
        'replace': [r[0] for r in s['outer_arrivals'] if not r[1]],
        'reserved': [sum(op=='reserve' for op in s['reservation_trace'][:i+1])>sum(op=='complete' for op in s['reservation_trace'][:i+1]) for i in range(len(s['reservation_trace']))],
        'release': s['inner_done'],
        'finish': max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None,
        'generation': s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']),
        'drops': s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])),
        'detach_inner': (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 2, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 3, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 0, 'drops': 4, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': 1, 'generation': 2, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 3, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 2, 'drops': 4, 'detach_inner': True})], 2: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 0, 'drops': 6, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 4, 'drops': 7, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 1, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 7, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 4, 'drops': 6, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 4, 'drops': 7, 'detach_inner': True})], 3: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 6, 'drops': 10, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 9, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 7, 'drops': 9, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 1, 'generation': 6, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 6, 'drops': 0, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 9, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 6, 'drops': 10, 'detach_inner': True})], 4: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': False, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 9, 'drops': 12, 'detach_inner': False}), ({'active': True, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 12, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 8, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': True, 'finish': None, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 8, 'drops': 13, 'detach_inner': True})], 5: [({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 10, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 10, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 15, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': True, 'finish': 1, 'generation': 1, 'drops': 15, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 10, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 10, 'done_generation': 0, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': 1, 'generation': 10, 'drops': 15, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 10, 'drops': 16, 'detach_inner': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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(s):
    return {
        'accept': s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None,
        'drop': s['outer_value'] and (s['active'] or s['subscribing']),
        'queue': [r[0] for r in s['discarded_resources'] if r[1]],
        'replace': [r[0] for r in s['outer_arrivals'] if not r[1]],
        'reserved': [sum(op=='reserve' for op in s['reservation_trace'][:i+1])>sum(op=='complete' for op in s['reservation_trace'][:i+1]) for i in range(len(s['reservation_trace']))],
        'release': s['inner_done'] and s['done_generation']<=s['generation'],
        'finish': max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None,
        'generation': s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']),
        'drops': s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])),
        'detach_inner': (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 2, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 3, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 0, 'drops': 4, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': 1, 'generation': 2, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 3, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 2, 'done_generation': 2, 'drops': 3, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 2, 'drops': 4, 'detach_inner': True})], 2: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 0, 'drops': 6, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 4, 'drops': 7, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 1, 'generation': 1, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 6, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, True], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 4, 'drops': 6, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 7, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 4, 'done_generation': 4, 'drops': 6, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 4, 'drops': 7, 'detach_inner': True})], 3: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 6, 'drops': 10, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 9, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 2, 'generation': 7, 'drops': 9, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 0, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': []}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [], 'release': False, 'finish': 1, 'generation': 6, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 6, 'drops': 0, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': None, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': True, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 6, 'drops': 9, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 6, 'done_generation': 6, 'drops': 9, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 6, 'drops': 10, 'detach_inner': True})], 4: [({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, False, False], 'release': False, 'finish': 1, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 0, 'drops': 12, 'subscribing': False, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 9, 'drops': 12, 'detach_inner': False}), ({'active': True, 'outer_value': False, 'outer_done': True, 'inner_done': False, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 12, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [True, False, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 8, 'drops': 0, 'subscribing': False, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 0, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': [], 'reserved': [True, True, False], 'release': True, 'finish': None, 'generation': 8, 'drops': 13, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 8, 'done_generation': 8, 'drops': 12, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 8, 'drops': 13, 'detach_inner': True})], 5: [({'active': False, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': None, 'cancel': True, 'generation': 10, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': False, 'finish': 2, 'generation': 10, 'drops': 1, 'detach_inner': True}), ({'active': False, 'outer_value': True, 'outer_done': False, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 15, 'subscribing': False, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['a', True], ['b', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': False, 'queue': ['a'], 'replace': ['b'], 'reserved': [True, True, False], 'release': True, 'finish': 1, 'generation': 1, 'drops': 15, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': False, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 10, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'complete', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, False, False], 'release': True, 'finish': 1, 'generation': 0, 'drops': 0, 'detach_inner': True}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 0, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': False, 'finish': None, 'generation': 0, 'drops': 16, 'detach_inner': True}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 10, 'done_generation': 0, 'drops': 15, 'subscribing': True, 'finish_trace': ['outer-done', 'inner-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', True], ['b', False]], 'reservation_trace': ['reserve', 'return']}, {'accept': False, 'drop': False, 'queue': [], 'replace': ['b'], 'reserved': [True, True], 'release': False, 'finish': 1, 'generation': 10, 'drops': 15, 'detach_inner': False}), ({'active': False, 'outer_value': False, 'outer_done': False, 'inner_done': False, 'error': None, 'cancel': False, 'generation': 0, 'done_generation': 0, 'drops': 0, 'subscribing': False, 'finish_trace': [], 'discarded_resources': [], 'outer_arrivals': [], 'reservation_trace': []}, {'accept': False, 'drop': False, 'queue': [], 'replace': [], 'reserved': [], 'release': False, 'finish': None, 'generation': 0, 'drops': 0, 'detach_inner': False}), ({'active': True, 'outer_value': True, 'outer_done': True, 'inner_done': True, 'error': 'error', 'cancel': True, 'generation': 10, 'done_generation': 10, 'drops': 15, 'subscribing': True, 'finish_trace': ['inner-done', 'tick', 'outer-done', 'late'], 'discarded_resources': [['c', False]], 'outer_arrivals': [['a', False], ['b', True], ['c', False]], 'reservation_trace': ['reserve', 'return', 'complete']}, {'accept': False, 'drop': True, 'queue': [], 'replace': ['a', 'c'], 'reserved': [True, True, False], 'release': True, 'finish': 2, 'generation': 10, 'drops': 16, 'detach_inner': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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:
A stale inner completion releases the exhaust slot; the returned lifecycle plan violates the stated transition contract.

Plan an exhaust-style observer: accept a new outer value only while no inner is active; otherwise drop it, never queue or replace. An accepted inner occupies its slot before synchronous subscription side effects. Releasing the current inner allows the next outer value. Outer completion waits for the accepted inner. An error is terminal and rejected outer values consume no inner generation. For one accepted inner, report the earliest trace index at which both outer and inner completion have occurred, independent of later trace records. Suppressed outer values are never queued; their [resource_id,owned] resources are released only when owned by the operator. For recorded [outer_value,inner_active_at_arrival] observations, invoke the inner factory only for arrivals that found the slot idle. For one inner startup, reservation is occupied from reserve until complete, even if completion is synchronous before subscribe returns; return alone does not release it. Inputs are finite state snapshots, including transitional and stale states; output fields are the exact independent actions/metadata defined by the corrected expression table. Numeric fixture capacities and counts vary with N.
Field definitions, each independently computed from the input snapshot: accept = s['outer_value'] and not s['active'] and not s['subscribing'] and not s['outer_done'] and not s['cancel'] and s['error'] is None; drop = s['outer_value'] and (s['active'] or s['subscribing']); queue = [r[0] for r in s['discarded_resources'] if r[1]]; replace = [r[0] for r in s['outer_arrivals'] if not r[1]]; reserved = [sum(op=='reserve' for op in s['reservation_trace'][:i+1])>sum(op=='complete' for op in s['reservation_trace'][:i+1]) for i in range(len(s['reservation_trace']))]; release = s['inner_done'] and s['done_generation']==s['generation']; finish = max(s['finish_trace'].index('outer-done'),s['finish_trace'].index('inner-done')) if 'outer-done' in s['finish_trace'] and 'inner-done' in s['finish_trace'] else None; generation = s['generation']+int(s['outer_value'] and not s['active'] and not s['subscribing']); drops = s['drops']+int(s['outer_value'] and (s['active'] or s['subscribing'])); detach_inner = (s['active'] or s['subscribing']) and (s['cancel'] or s['error'] is not None)

split: open-access