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

N = 1
observations = []
def solve(s):
    return {
        'queue': s['serial'] and s['depth']>0 and s['event'] is not None,
        'enter': s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit'],
        'outer_event': s['outer'],
        'context': s['context'],
        'unwind': s['frames'][:-1] if s['complete'] else list(s['frames']),
        'drain': list(s['pending']) if s['complete'] else [],
        'parent_cancel': False,
        'overflow': s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0),
        'next_depth': max(0,s['depth']-int(s['complete'])),
        'queued_order': list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else []),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 3, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 4, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': True, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 4, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 1, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 3, 'limit': 4, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b']})], 2: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 6, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 8, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': None, 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 1, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': []}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 6, 'limit': 1, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 6, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 1, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 6, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b']})], 3: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 9, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 12, 'serial': False, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 9, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 9, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']})], 4: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 12, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 16, 'serial': True, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 0, 'limit': 16, 'serial': False, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 12, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b']})], 5: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 20, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 15, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b']})]}
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 {
        'queue': s['serial'] and s['depth']>0 and s['event'] is not None,
        'enter': s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit'],
        'outer_event': s['outer'],
        'context': s['context'],
        'unwind': s['frames'][:-1] if s['complete'] else list(s['frames']),
        'drain': list(s['pending']) if s['depth']<=1 else [],
        'parent_cancel': False,
        'overflow': s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0),
        'next_depth': max(0,s['depth']-int(s['complete'])),
        'queued_order': list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else []),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 3, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 4, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': True, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 4, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 1, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 3, 'limit': 4, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b']})], 2: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 6, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 8, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': None, 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 1, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': []}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 6, 'limit': 1, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 6, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 1, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 6, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b']})], 3: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 9, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 12, 'serial': False, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 9, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 9, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']})], 4: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 12, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 16, 'serial': True, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 0, 'limit': 16, 'serial': False, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 12, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b']})], 5: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 20, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 15, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b']})]}
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:
Inner callback completion drains outer deferred emissions; the returned lifecycle plan violates the stated transition contract.

Plan a nested observer emission with bounded depth. A nested event queues when serialization is enabled; otherwise it opens a child frame if below the limit. Preserve the outer event/context, unwind exactly one frame, and drain deferred events only after the outermost callback completes. A cancelled inner frame never cancels its parent. 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: queue = s['serial'] and s['depth']>0 and s['event'] is not None; enter = s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit']; outer_event = s['outer']; context = s['context']; unwind = s['frames'][:-1] if s['complete'] else list(s['frames']); drain = list(s['pending']) if s['complete'] and s['depth']<=1 else []; parent_cancel = False; overflow = s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0); next_depth = max(0,s['depth']-int(s['complete'])); queued_order = list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else [])

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'queue': s['serial'] and s['depth']>0 and s['event'] is not None,
        'enter': s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit'],
        'outer_event': s['outer'],
        'context': s['context'],
        'unwind': s['frames'][:-1] if s['complete'] else list(s['frames']),
        'drain': list(s['pending']) if s['complete'] and s['depth']<=1 else [],
        'parent_cancel': s['cancel'],
        'overflow': s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0),
        'next_depth': max(0,s['depth']-int(s['complete'])),
        'queued_order': list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else []),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 3, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 4, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': True, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 4, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 1, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 3, 'limit': 4, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b']})], 2: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 6, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 8, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': None, 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 1, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': []}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 6, 'limit': 1, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 6, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 1, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 6, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b']})], 3: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 9, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 12, 'serial': False, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 9, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 9, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']})], 4: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 12, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 16, 'serial': True, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 0, 'limit': 16, 'serial': False, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 12, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b']})], 5: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 20, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 15, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b']})]}
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 {
        'queue': s['serial'] and s['depth']>0 and s['event'] is not None,
        'enter': s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit'],
        'outer_event': s['outer'],
        'context': s['context'],
        'unwind': s['frames'][:-1] if s['complete'] else list(s['frames']),
        'drain': list(s['pending']) if s['complete'] and s['depth']<=1 else [],
        'parent_cancel': s['cancel'] and s['depth']>1,
        'overflow': s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0),
        'next_depth': max(0,s['depth']-int(s['complete'])),
        'queued_order': list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else []),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 3, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 4, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': True, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 4, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 1, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 3, 'limit': 4, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 2, 'queued_order': ['a', 'b']})], 2: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 6, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 8, 'serial': False, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': None, 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 1, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': True, 'complete': True, 'frames': []}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 6, 'limit': 1, 'serial': True, 'pending': [], 'event': 'inner', 'outer': None, 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 6, 'queued_order': ['inner']}), ({'depth': 1, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 1, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 6, 'limit': 8, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 5, 'queued_order': ['a', 'b']})], 3: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': True, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 9, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']}), ({'depth': 9, 'limit': 12, 'serial': False, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 9, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 9, 'limit': 12, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 8, 'queued_order': ['a', 'b']})], 4: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 12, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 1, 'limit': 16, 'serial': True, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': None, 'cancel': False, 'complete': False, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 1, 'queued_order': ['inner']}), ({'depth': 0, 'limit': 16, 'serial': False, 'pending': [], 'event': None, 'outer': 'outer', 'context': None, 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': None, 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 12, 'limit': 16, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 11, 'queued_order': ['a', 'b']})], 5: [({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root', 'child'], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 0, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': True, 'complete': True, 'frames': ['root']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': ['a', 'b'], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': ['a', 'b']}), ({'depth': 15, 'limit': 1, 'serial': True, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': True, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b', 'inner']}), ({'depth': 0, 'limit': 20, 'serial': True, 'pending': [], 'event': None, 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 1, 'serial': False, 'pending': ['a', 'b'], 'event': 'inner', 'outer': None, 'context': 'ctx', 'cancel': True, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': None, 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 15, 'queued_order': ['a', 'b']}), ({'depth': 0, 'limit': 0, 'serial': False, 'pending': [], 'event': 'inner', 'outer': 'outer', 'context': 'ctx', 'cancel': False, 'complete': False, 'frames': []}, {'queue': False, 'enter': False, 'outer_event': 'outer', 'context': 'ctx', 'unwind': [], 'drain': [], 'parent_cancel': False, 'overflow': True, 'next_depth': 0, 'queued_order': []}), ({'depth': 15, 'limit': 20, 'serial': True, 'pending': ['a', 'b'], 'event': None, 'outer': None, 'context': None, 'cancel': True, 'complete': True, 'frames': ['root', 'child']}, {'queue': False, 'enter': False, 'outer_event': None, 'context': None, 'unwind': ['root'], 'drain': [], 'parent_cancel': False, 'overflow': False, 'next_depth': 14, 'queued_order': ['a', 'b']})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A cancelled nested frame cancels its parent emission; the returned lifecycle plan violates the stated transition contract.

Plan a nested observer emission with bounded depth. A nested event queues when serialization is enabled; otherwise it opens a child frame if below the limit. Preserve the outer event/context, unwind exactly one frame, and drain deferred events only after the outermost callback completes. A cancelled inner frame never cancels its parent. 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: queue = s['serial'] and s['depth']>0 and s['event'] is not None; enter = s['event'] is not None and not(s['serial'] and s['depth']>0) and s['depth']<s['limit']; outer_event = s['outer']; context = s['context']; unwind = s['frames'][:-1] if s['complete'] else list(s['frames']); drain = list(s['pending']) if s['complete'] and s['depth']<=1 else []; parent_cancel = False; overflow = s['event'] is not None and s['depth']>=s['limit'] and not(s['serial'] and s['depth']>0); next_depth = max(0,s['depth']-int(s['complete'])); queued_order = list(s['pending'])+([s['event']] if s['serial'] and s['depth']>0 and s['event'] is not None else [])

split: open-access