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

N = 1
observations = []
def solve(s):
    return {
        'kind': None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)),
        'closed': s['closed'] or s['complete'] or s['error'] is not None or s['cancel'],
        'drain': list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else [],
        'error_payload': s['error'] if not s['closed'] and not s['cancel'] else None,
        'release': s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'teardown': not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'inflight': 0 if s['error'] is not None or s['cancel'] else s['inflight'],
        'late_error': False,
        'cancel_reason': s['reason'] if s['cancel'] else None,
        'completion_wait': s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 2, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 2: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 4], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 4, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 3: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 6, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [1, 6], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 6, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 4: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': False, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 8], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 8, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 5: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 10, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': False, 'inflight': 0, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': False, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 10], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 10, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})]}
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 {
        'kind': None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)),
        'closed': s['closed'] or s['complete'] or s['error'] is not None or s['cancel'],
        'drain': list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else [],
        'error_payload': s['error'] if not s['closed'] and not s['cancel'] else None,
        'release': s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'teardown': not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'inflight': 0 if s['error'] is not None or s['cancel'] else s['inflight'],
        'late_error': s['closed'] and s['error'] is not None,
        'cancel_reason': s['reason'] if s['cancel'] else None,
        'completion_wait': s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 2, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 2: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 4], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 4, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 3: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 6, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [1, 6], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 6, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 4: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': False, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 8], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 8, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 5: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 10, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': False, 'inflight': 0, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': False, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 10], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 10, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})]}
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 late observer error is silently discarded; the returned lifecycle plan violates the stated transition contract.

Plan an observer terminal notification. First completion or error closes the observer. Cancellation is silent; an error has precedence over completion. An already closed observer never receives another terminal callback. Queued values are discarded on error or cancellation but drain before normal completion. Release owned resources on first closure. 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: kind = None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)); closed = s['closed'] or s['complete'] or s['error'] is not None or s['cancel']; drain = list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else []; error_payload = s['error'] if not s['closed'] and not s['cancel'] else None; release = s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']); teardown = not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']); inflight = 0 if s['error'] is not None or s['cancel'] else s['inflight']; late_error = s['closed'] and s['error'] is not None and not s['reported']; cancel_reason = s['reason'] if s['cancel'] else None; completion_wait = s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'kind': None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)),
        'closed': s['closed'] or s['complete'] or s['error'] is not None or s['cancel'],
        'drain': list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else [],
        'error_payload': s['error'] if not s['closed'] and not s['cancel'] else None,
        'release': s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'teardown': not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'inflight': 0 if s['error'] is not None or s['cancel'] else s['inflight'],
        'late_error': s['closed'] and s['error'] is not None and not s['reported'],
        'cancel_reason': s['error'] if s['cancel'] else None,
        'completion_wait': s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 2, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 2: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 4], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 4, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 3: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 6, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [1, 6], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 6, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 4: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': False, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 8], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 8, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 5: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 10, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': False, 'inflight': 0, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': False, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 10], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 10, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})]}
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 {
        'kind': None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)),
        'closed': s['closed'] or s['complete'] or s['error'] is not None or s['cancel'],
        'drain': list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else [],
        'error_payload': s['error'] if not s['closed'] and not s['cancel'] else None,
        'release': s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'teardown': not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']),
        'inflight': 0 if s['error'] is not None or s['cancel'] else s['inflight'],
        'late_error': s['closed'] and s['error'] is not None and not s['reported'],
        'cancel_reason': s['reason'],
        'completion_wait': s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 2], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 2, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 2, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 2], 'owned': True, 'inflight': 2, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 2: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 4], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 4, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 4], 'owned': True, 'inflight': 4, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 3: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 6, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [1, 6], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 6, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 6], 'owned': True, 'inflight': 6, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 4: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [], 'owned': True, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': False, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': False, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 8], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': True, 'reason': 'stop'}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': True, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [], 'owned': True, 'inflight': 8, 'teardown': False, 'reported': False, 'reason': None}, {'kind': 'complete', 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': True, 'inflight': 8, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 8], 'owned': True, 'inflight': 8, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})], 5: [({'closed': False, 'complete': False, 'error': None, 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [], 'owned': False, 'inflight': 10, 'teardown': False, 'reported': False, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': True, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': False, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': False, 'inflight': 0, 'teardown': True, 'reported': False, 'reason': None}, {'kind': 'error', 'closed': True, 'drain': [], 'error_payload': 'boom', 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': False, 'reported': True, 'reason': None}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': False, 'complete': True, 'error': None, 'cancel': False, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': False, 'reason': 'stop'}, {'kind': 'complete', 'closed': True, 'drain': [1, 10], 'error_payload': None, 'release': True, 'teardown': False, 'inflight': 10, 'late_error': False, 'cancel_reason': None, 'completion_wait': True}), ({'closed': False, 'complete': False, 'error': None, 'cancel': False, 'values': [], 'owned': False, 'inflight': 0, 'teardown': False, 'reported': False, 'reason': None}, {'kind': None, 'closed': False, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': None, 'completion_wait': False}), ({'closed': True, 'complete': True, 'error': 'boom', 'cancel': True, 'values': [1, 10], 'owned': True, 'inflight': 10, 'teardown': True, 'reported': True, 'reason': 'stop'}, {'kind': None, 'closed': True, 'drain': [], 'error_payload': None, 'release': False, 'teardown': False, 'inflight': 0, 'late_error': False, 'cancel_reason': 'stop', 'completion_wait': False})]}
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:
Silent cancellation overwrites the recorded reason with an error; the returned lifecycle plan violates the stated transition contract.

Plan an observer terminal notification. First completion or error closes the observer. Cancellation is silent; an error has precedence over completion. An already closed observer never receives another terminal callback. Queued values are discarded on error or cancellation but drain before normal completion. Release owned resources on first closure. 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: kind = None if s['closed'] or s['cancel'] else ('error' if s['error'] is not None else ('complete' if s['complete'] else None)); closed = s['closed'] or s['complete'] or s['error'] is not None or s['cancel']; drain = list(s['values']) if not s['closed'] and not s['cancel'] and s['error'] is None else []; error_payload = s['error'] if not s['closed'] and not s['cancel'] else None; release = s['owned'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']); teardown = not s['teardown'] and not s['closed'] and (s['complete'] or s['error'] is not None or s['cancel']); inflight = 0 if s['error'] is not None or s['cancel'] else s['inflight']; late_error = s['closed'] and s['error'] is not None and not s['reported']; cancel_reason = s['reason'] if s['cancel'] else None; completion_wait = s['complete'] and s['error'] is None and not s['cancel'] and not s['closed'] and s['inflight']>0

split: open-access