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

N = 1
observations = []
def solve(s):
    return {
        'order': list(dict.fromkeys(r[0] for r in s['stack'] if not r[1] and r[0]!=s['transfer'])),
        'immediate': [s['added']] if s['closed'] and s['added'] is not None else [],
        'store_added': [s['added']] if not s['closed'] and s['added'] is not None else [],
        'transferred': [r[0] for r in s['stack'] if r[0]==s['transfer']],
        'retained': [r for r in s['stack'] if r[0]!=s['transfer']],
        'already_run': [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])],
        'errors': list(s['errors']),
        'reentrant': list(s['wave_remaining'])+list(reversed(s['added_during'])),
        'owner': s['new_owner'] if s['transfer'] is not None else s['owner'],
        'pending': [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': None, 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': [], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 2, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': 'missing', 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['a', 'b', 'x'], 'owner': 'scope', 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 2: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 4, 'wave_remaining': [], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['x'], 'owner': 'scope', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['c', None]]}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': [], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 3: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 6, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['a'], 'owner': None, 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': ['a'], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 4: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one'], 'reentrant': ['a'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 8, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['a', 'b'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 5: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})]}
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 {
        'order': [r[0] for r in reversed(s['stack']) if not r[1] and r[0]!=s['transfer']],
        'immediate': [s['added']] if s['closed'] and s['added'] is not None else [],
        'store_added': [s['added']] if not s['closed'] and s['added'] is not None else [],
        'transferred': [r[0] for r in s['stack'] if r[0]==s['transfer']],
        'retained': [r for r in s['stack'] if r[0]!=s['transfer']],
        'already_run': [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])],
        'errors': list(s['errors']),
        'reentrant': list(s['wave_remaining'])+list(reversed(s['added_during'])),
        'owner': s['new_owner'] if s['transfer'] is not None else s['owner'],
        'pending': [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': None, 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': [], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 2, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': 'missing', 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['a', 'b', 'x'], 'owner': 'scope', 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 2: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 4, 'wave_remaining': [], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['x'], 'owner': 'scope', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['c', None]]}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': [], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 3: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 6, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['a'], 'owner': None, 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': ['a'], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 4: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one'], 'reentrant': ['a'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 8, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['a', 'b'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 5: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})]}
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:
Composite teardown runs resources in forward acquisition order; the returned lifecycle plan violates the stated transition contract.

Plan a subscription composite teardown stack. Disposers are [id,already_run] entries and run in reverse acquisition order. Duplicate disposer IDs run at most once, keeping the latest acquisition position. Disposers added after closure run immediately. Teardown failures accumulate without suppressing later cleanup. Ownership transfer removes the transferred disposer from this stack without executing it. The current disposal wave finishes in its existing order; disposers added reentrantly form a subsequent wave in reverse acquisition order. Relinquishing a scope severs only capture references to that exact owner; unrelated receiver captures survive. The already-run projection groups aliases by disposer identity: any completed alias marks the identity completed, preserving first identity order. 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: order = list(dict.fromkeys(r[0] for r in reversed(s['stack']) if not r[1] and r[0]!=s['transfer'])); immediate = [s['added']] if s['closed'] and s['added'] is not None else []; store_added = [s['added']] if not s['closed'] and s['added'] is not None else []; transferred = [r[0] for r in s['stack'] if r[0]==s['transfer']]; retained = [r for r in s['stack'] if r[0]!=s['transfer']]; already_run = [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])]; errors = list(s['errors']); reentrant = list(s['wave_remaining'])+list(reversed(s['added_during'])); owner = s['new_owner'] if s['transfer'] is not None else s['owner']; pending = [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']]

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'order': list(dict.fromkeys(r[0] for r in reversed(s['stack']) if not r[1] and r[0]!=s['transfer'])),
        'immediate': [],
        'store_added': [s['added']] if not s['closed'] and s['added'] is not None else [],
        'transferred': [r[0] for r in s['stack'] if r[0]==s['transfer']],
        'retained': [r for r in s['stack'] if r[0]!=s['transfer']],
        'already_run': [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])],
        'errors': list(s['errors']),
        'reentrant': list(s['wave_remaining'])+list(reversed(s['added_during'])),
        'owner': s['new_owner'] if s['transfer'] is not None else s['owner'],
        'pending': [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': None, 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': [], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 2, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': 'missing', 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['a', 'b', 'x'], 'owner': 'scope', 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 2: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 4, 'wave_remaining': [], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['x'], 'owner': 'scope', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['c', None]]}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': [], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 3: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 6, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['a'], 'owner': None, 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': ['a'], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 4: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one'], 'reentrant': ['a'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 8, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['a', 'b'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 5: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})]}
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 {
        'order': list(dict.fromkeys(r[0] for r in reversed(s['stack']) if not r[1] and r[0]!=s['transfer'])),
        'immediate': [s['added']] if s['added'] is not None else [],
        'store_added': [s['added']] if not s['closed'] and s['added'] is not None else [],
        'transferred': [r[0] for r in s['stack'] if r[0]==s['transfer']],
        'retained': [r for r in s['stack'] if r[0]!=s['transfer']],
        'already_run': [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])],
        'errors': list(s['errors']),
        'reentrant': list(s['wave_remaining'])+list(reversed(s['added_during'])),
        'owner': s['new_owner'] if s['transfer'] is not None else s['owner'],
        'pending': [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': None, 'pending': 2, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': [], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 2, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': 'missing', 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['a', 'b', 'x'], 'owner': 'scope', 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 2, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 2: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 4, 'wave_remaining': [], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one', 'two'], 'reentrant': ['x'], 'owner': 'scope', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 4, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['c', None]]}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': [], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 4, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 3: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 6, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['a'], 'owner': None, 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': [], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': ['a'], 'retained': [], 'already_run': [], 'errors': ['one'], 'reentrant': ['y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': None, 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': None, 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 6, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 4: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': ['new'], 'store_added': [], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': ['one'], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': ['one'], 'reentrant': ['a'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', False]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': [], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 8, 'wave_remaining': [], 'added_during': ['x'], 'captures': [['c', None]], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['x'], 'owner': None, 'pending': [['c', None]]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': [], 'reentrant': ['a', 'b'], 'owner': 'scope', 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 8, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})], 5: [({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': False, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['b'], 'immediate': [], 'store_added': ['new'], 'transferred': ['a', 'a'], 'retained': [['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'y', 'x'], 'owner': 'other', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', False], ['b', True], ['a', False], ['c', False]], 'closed': True, 'added': 'new', 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': 'scope', 'new_owner': None, 'pending': 0, 'wave_remaining': ['a'], 'added_during': ['x', 'y'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': ['c', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', False], ['b', True], ['a', False], ['c', False]], 'already_run': ['b'], 'errors': [], 'reentrant': ['a', 'y', 'x'], 'owner': 'scope', 'pending': [['a', None], ['b', 'other']]}), ({'stack': [], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': None, 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': [], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b'], 'owner': None, 'pending': [['a', None], ['b', 'other']]}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': False, 'added': 'new', 'transfer': 'missing', 'errors': ['one'], 'disposing': True, 'completed': False, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'old'}, {'order': ['b', 'a'], 'immediate': [], 'store_added': ['new'], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': True, 'added': 'new', 'transfer': 'a', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x'], 'captures': [['a', 'old'], ['b', 'other']], 'relinquished_owner': 'missing'}, {'order': [], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'x'], 'owner': 'other', 'pending': [['a', 'old'], ['b', 'other']]}), ({'stack': [['a', False]], 'closed': True, 'added': None, 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': None, 'new_owner': 'other', 'pending': 0, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [], 'relinquished_owner': 'missing'}, {'order': ['a'], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [['a', False]], 'already_run': [], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': []}), ({'stack': [], 'closed': False, 'added': None, 'transfer': None, 'errors': [], 'disposing': False, 'completed': False, 'owner': None, 'new_owner': None, 'pending': 0, 'wave_remaining': [], 'added_during': [], 'captures': [], 'relinquished_owner': 'old'}, {'order': [], 'immediate': [], 'store_added': [], 'transferred': [], 'retained': [], 'already_run': [], 'errors': [], 'reentrant': [], 'owner': None, 'pending': []}), ({'stack': [['a', True], ['a', False], ['b', False], ['b', True]], 'closed': True, 'added': 'new', 'transfer': 'missing', 'errors': ['one', 'two'], 'disposing': True, 'completed': True, 'owner': 'scope', 'new_owner': 'other', 'pending': 10, 'wave_remaining': ['a', 'b'], 'added_during': ['x', 'y'], 'captures': [['c', None]], 'relinquished_owner': 'missing'}, {'order': ['b', 'a'], 'immediate': ['new'], 'store_added': [], 'transferred': [], 'retained': [['a', True], ['a', False], ['b', False], ['b', True]], 'already_run': ['a', 'b'], 'errors': ['one', 'two'], 'reentrant': ['a', 'b', 'y', 'x'], 'owner': 'other', 'pending': [['c', None]]})]}
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:
Adding teardown to a closed subscription silently drops cleanup; the returned lifecycle plan violates the stated transition contract.

Plan a subscription composite teardown stack. Disposers are [id,already_run] entries and run in reverse acquisition order. Duplicate disposer IDs run at most once, keeping the latest acquisition position. Disposers added after closure run immediately. Teardown failures accumulate without suppressing later cleanup. Ownership transfer removes the transferred disposer from this stack without executing it. The current disposal wave finishes in its existing order; disposers added reentrantly form a subsequent wave in reverse acquisition order. Relinquishing a scope severs only capture references to that exact owner; unrelated receiver captures survive. The already-run projection groups aliases by disposer identity: any completed alias marks the identity completed, preserving first identity order. 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: order = list(dict.fromkeys(r[0] for r in reversed(s['stack']) if not r[1] and r[0]!=s['transfer'])); immediate = [s['added']] if s['closed'] and s['added'] is not None else []; store_added = [s['added']] if not s['closed'] and s['added'] is not None else []; transferred = [r[0] for r in s['stack'] if r[0]==s['transfer']]; retained = [r for r in s['stack'] if r[0]!=s['transfer']]; already_run = [k for k in dict.fromkeys(r[0] for r in s['stack']) if any(r[0]==k and r[1] for r in s['stack'])]; errors = list(s['errors']); reentrant = list(s['wave_remaining'])+list(reversed(s['added_during'])); owner = s['new_owner'] if s['transfer'] is not None else s['owner']; pending = [[r[0],None if r[1]==s['relinquished_owner'] else r[1]] for r in s['captures']]

split: open-access