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

N = 1
observations = []
def solve(s):
    return {
        'publish': s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected'],
        'reject': s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel'],
        'outstanding': max(0,s['outstanding']-int(not s['duplicate'])),
        'release': s['acquired'] and not s['duplicate'],
        'value': [s['value']] if not s['rejected'] else [],
        'error': {'generation':s['generation'],'reason':s['error']} if s['rejected'] else None,
        'unhandled': ([s['error'],s['handler_failure']] if s['handler_failure'] is not None else ([] if s['handler'] else [s['error']])) if s['rejected'] else [],
        'finalize': s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0,
        'stale': s['generation']!=s['settled_generation'],
        'consumed': not s['duplicate'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 2, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 3, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 2, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 3, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': [], 'error': {'generation': 2, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 2: [({'generation': 0, 'settled_generation': 4, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 5, 'release': True, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 6, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': None}, 'unhandled': [None], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 3: [({'generation': 6, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 6, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': True, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': None, 'outstanding': 9, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': True, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 9, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 4: [({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 8, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 8, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 8, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 12, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 12, 'release': False, 'value': [], 'error': {'generation': 8, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 5: [({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': True, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 15, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': 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 {
        'publish': s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected'],
        'reject': s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel'],
        'outstanding': max(0,s['outstanding']-int(not s['duplicate'])),
        'release': s['acquired'] and not s['duplicate'],
        'value': [s['value']] if not s['rejected'] else [],
        'error': {'generation':s['settled_generation'],'reason':s['value']} if s['rejected'] else None,
        'unhandled': ([s['error'],s['handler_failure']] if s['handler_failure'] is not None else ([] if s['handler'] else [s['error']])) if s['rejected'] else [],
        'finalize': s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0,
        'stale': s['generation']!=s['settled_generation'],
        'consumed': not s['duplicate'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 2, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 3, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 2, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 3, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': [], 'error': {'generation': 2, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 2: [({'generation': 0, 'settled_generation': 4, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 5, 'release': True, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 6, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': None}, 'unhandled': [None], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 3: [({'generation': 6, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 6, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': True, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': None, 'outstanding': 9, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': True, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 9, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 4: [({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 8, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 8, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 8, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 12, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 12, 'release': False, 'value': [], 'error': {'generation': 8, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 5: [({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': True, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 15, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': 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:
Asynchronous rejection diagnostics attribute an old callback to the current generation; the returned lifecycle plan violates the stated transition contract.

Plan settlement of one asynchronous observer callback. Only the current generation may publish a result. Cancellation suppresses publication but still releases acquired resources. Settled callback IDs are ignored on duplicate completion. Outstanding count decreases once and never below zero. Rejections route to the error observer, not the value observer; an absent successful value is a legitimate None payload. If the error observer itself fails, report the original rejection followed by its handler failure, preserving both causes; successful handlers consume the original. Rejection diagnostics retain the actual completing generation and error reason even when the current subscription generation has advanced. 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: publish = s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected']; reject = s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel']; outstanding = max(0,s['outstanding']-int(not s['duplicate'])); release = s['acquired'] and not s['duplicate']; value = [s['value']] if not s['rejected'] else []; error = {'generation':s['settled_generation'],'reason':s['error']} if s['rejected'] else None; unhandled = ([s['error'],s['handler_failure']] if s['handler_failure'] is not None else ([] if s['handler'] else [s['error']])) if s['rejected'] else []; finalize = s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0; stale = s['generation']!=s['settled_generation']; consumed = not s['duplicate']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'publish': s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected'],
        'reject': s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel'],
        'outstanding': max(0,s['outstanding']-int(not s['duplicate'])),
        'release': s['acquired'] and not s['duplicate'],
        'value': [s['value']] if not s['rejected'] else [],
        'error': {'generation':s['settled_generation'],'reason':s['error']} if s['rejected'] else None,
        'unhandled': ([s['handler_failure']] if s['handler_failure'] is not None else ([] if s['handler'] else [s['error']])) if s['rejected'] else [],
        'finalize': s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0,
        'stale': s['generation']!=s['settled_generation'],
        'consumed': not s['duplicate'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 2, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 3, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 2, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 3, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': [], 'error': {'generation': 2, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 2: [({'generation': 0, 'settled_generation': 4, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 5, 'release': True, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 6, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': None}, 'unhandled': [None], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 3: [({'generation': 6, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 6, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': True, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': None, 'outstanding': 9, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': True, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 9, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 4: [({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 8, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 8, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 8, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 12, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 12, 'release': False, 'value': [], 'error': {'generation': 8, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 5: [({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': True, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 15, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': 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 {
        'publish': s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected'],
        'reject': s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel'],
        'outstanding': max(0,s['outstanding']-int(not s['duplicate'])),
        'release': s['acquired'] and not s['duplicate'],
        'value': [s['value']] if not s['rejected'] else [],
        'error': {'generation':s['settled_generation'],'reason':s['error']} if s['rejected'] else None,
        'unhandled': [s['error']] if s['rejected'] and (not s['handler'] or s['handler_failure'] is not None) else [],
        'finalize': s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0,
        'stale': s['generation']!=s['settled_generation'],
        'consumed': not s['duplicate'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 2, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': None, 'outstanding': 3, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 2, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 2, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 2, 'settled_generation': 2, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 3, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 3, 'release': False, 'value': [], 'error': {'generation': 2, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 2: [({'generation': 0, 'settled_generation': 4, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 5, 'release': True, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 6, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 4, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': [], 'finalize': True, 'stale': True, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': None}, 'unhandled': [None], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 4, 'settled_generation': 4, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 6, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 6, 'release': False, 'value': [], 'error': {'generation': 4, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 3: [({'generation': 6, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 6, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': True, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': False, 'duplicate': False, 'rejected': True, 'value': None, 'error': None, 'outstanding': 9, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': True, 'outstanding': 8, 'release': True, 'value': [], 'error': {'generation': 6, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 6, 'settled_generation': 6, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 9, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 9, 'release': False, 'value': [], 'error': {'generation': 6, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 4: [({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': None, 'outstanding': 0, 'acquired': True, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [None, 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 8, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 0, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 8, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': 0, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': True, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 8, 'settled_generation': 8, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 12, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 12, 'release': False, 'value': [], 'error': {'generation': 8, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': False})], 5: [({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 1, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 1, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 0, 'cancel': True, 'duplicate': False, 'rejected': True, 'value': 0, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': True, 'closing': False, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 0, 'reason': None}, 'unhandled': [], 'finalize': False, 'stale': True, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': False, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': ['value'], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': True, 'handler_failure': None}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error'], 'finalize': True, 'stale': True, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': False, 'duplicate': True, 'rejected': True, 'value': None, 'error': 'error', 'outstanding': 0, 'acquired': True, 'handler': False, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 0, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': True, 'stale': False, 'consumed': False}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': False, 'value': 0, 'error': None, 'outstanding': 15, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [0], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': False}), ({'generation': 0, 'settled_generation': 0, 'cancel': False, 'duplicate': False, 'rejected': False, 'value': None, 'error': None, 'outstanding': 0, 'acquired': False, 'handler': False, 'closing': False, 'handler_failure': None}, {'publish': True, 'reject': False, 'outstanding': 0, 'release': False, 'value': [None], 'error': None, 'unhandled': [], 'finalize': False, 'stale': False, 'consumed': True}), ({'generation': 10, 'settled_generation': 10, 'cancel': True, 'duplicate': True, 'rejected': True, 'value': 'value', 'error': 'error', 'outstanding': 15, 'acquired': True, 'handler': True, 'closing': True, 'handler_failure': 'handler-failure'}, {'publish': False, 'reject': False, 'outstanding': 15, 'release': False, 'value': [], 'error': {'generation': 10, 'reason': 'error'}, 'unhandled': ['error', 'handler-failure'], 'finalize': False, 'stale': False, 'consumed': 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 failing asynchronous error observer hides the original callback rejection; the returned lifecycle plan violates the stated transition contract.

Plan settlement of one asynchronous observer callback. Only the current generation may publish a result. Cancellation suppresses publication but still releases acquired resources. Settled callback IDs are ignored on duplicate completion. Outstanding count decreases once and never below zero. Rejections route to the error observer, not the value observer; an absent successful value is a legitimate None payload. If the error observer itself fails, report the original rejection followed by its handler failure, preserving both causes; successful handlers consume the original. Rejection diagnostics retain the actual completing generation and error reason even when the current subscription generation has advanced. 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: publish = s['generation']==s['settled_generation'] and not s['cancel'] and not s['duplicate'] and not s['rejected']; reject = s['rejected'] and not s['duplicate'] and s['generation']==s['settled_generation'] and not s['cancel']; outstanding = max(0,s['outstanding']-int(not s['duplicate'])); release = s['acquired'] and not s['duplicate']; value = [s['value']] if not s['rejected'] else []; error = {'generation':s['settled_generation'],'reason':s['error']} if s['rejected'] else None; unhandled = ([s['error'],s['handler_failure']] if s['handler_failure'] is not None else ([] if s['handler'] else [s['error']])) if s['rejected'] else []; finalize = s['closing'] and max(0,s['outstanding']-int(not s['duplicate']))==0; stale = s['generation']!=s['settled_generation']; consumed = not s['duplicate']

split: open-access