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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'],
        'accept': s['active'] and not s['disposed'] and not s['aborted'],
        'refcount': max(0,s['refs']-int(s['hook'] and s['aborted'])),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'] and not s['notified'] and s['active'],
        'accept': s['active'] and not s['disposed'] and not s['aborted'],
        'refcount': max(0,s['refs']-int(s['hook'] and s['aborted'])),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Repeated cancellation notifies the observer twice; the returned lifecycle plan violates the stated transition contract.

Plan linking a subscription to a cancellation signal. Already-aborted signals reject attachment, immediately dispose existing work, and deliver the reason exactly once. A fresh signal attaches one hook only while the subscription is active. Preserve independent signal and subscription ownership; no callback invocation is modeled. 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: attach = s['active'] and not s['aborted'] and not s['hook']; dispose = s['aborted'] and not s['disposed']; detach = s['hook'] and (s['aborted'] or not s['active']); reason = s['reason'] if s['aborted'] else None; clear_pending = 0 if s['aborted'] else s['pending']; release = s['owns'] and not s['borrowed'] and s['aborted']; notify = s['aborted'] and not s['notified']; accept = s['active'] and not s['disposed'] and not s['aborted']; refcount = max(0,s['refs']-int(s['hook'] and s['aborted'])); terminal = s['disposed'] or s['aborted']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'] and not s['notified'],
        'accept': s['active'],
        'refcount': max(0,s['refs']-int(s['hook'] and s['aborted'])),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'] and not s['notified'],
        'accept': s['active'] and not s['aborted'],
        'refcount': max(0,s['refs']-int(s['hook'] and s['aborted'])),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A disposed listener accepts a new cancellation linkage; the returned lifecycle plan violates the stated transition contract.

Plan linking a subscription to a cancellation signal. Already-aborted signals reject attachment, immediately dispose existing work, and deliver the reason exactly once. A fresh signal attaches one hook only while the subscription is active. Preserve independent signal and subscription ownership; no callback invocation is modeled. 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: attach = s['active'] and not s['aborted'] and not s['hook']; dispose = s['aborted'] and not s['disposed']; detach = s['hook'] and (s['aborted'] or not s['active']); reason = s['reason'] if s['aborted'] else None; clear_pending = 0 if s['aborted'] else s['pending']; release = s['owns'] and not s['borrowed'] and s['aborted']; notify = s['aborted'] and not s['notified']; accept = s['active'] and not s['disposed'] and not s['aborted']; refcount = max(0,s['refs']-int(s['hook'] and s['aborted'])); terminal = s['disposed'] or s['aborted']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'] and not s['notified'],
        'accept': s['active'] and not s['disposed'] and not s['aborted'],
        'refcount': s['refs']-int(s['aborted']),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(s):
    return {
        'attach': s['active'] and not s['aborted'] and not s['hook'],
        'dispose': s['aborted'] and not s['disposed'],
        'detach': s['hook'] and (s['aborted'] or not s['active']),
        'reason': s['reason'] if s['aborted'] else None,
        'clear_pending': 0 if s['aborted'] else s['pending'],
        'release': s['owns'] and not s['borrowed'] and s['aborted'],
        'notify': s['aborted'] and not s['notified'],
        'accept': s['active'] and not s['disposed'] and not s['aborted'],
        'refcount': s['refs']-int(s['hook'] and s['aborted']),
        'terminal': s['disposed'] or s['aborted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 2, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 1, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 2, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': True}), ({'aborted': True, 'active': False, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 2, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 2, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 2, 'refs': 2, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 1, 'terminal': True})], 2: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': None, 'owns': False, 'pending': 4, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 4, 'notified': False, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 4, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': True, 'notify': False, 'accept': False, 'refcount': 4, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 4, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 4, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 4, 'refs': 4, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 3, 'terminal': True})], 3: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 6, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 6, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 6, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 6, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 6, 'refs': 6, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 5, 'terminal': True})], 4: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': True, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': None, 'owns': False, 'pending': 8, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': True, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 8, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': None, 'owns': True, 'pending': 0, 'refs': 0, 'notified': True, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 8, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 8, 'refs': 8, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 7, 'terminal': True})], 5: [({'aborted': True, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': False, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': False, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': False, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': False, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': True, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': True, 'accept': False, 'refcount': 9, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': True, 'reason': None, 'owns': True, 'pending': 0, 'refs': 10, 'notified': False, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 10, 'terminal': True}), ({'aborted': False, 'active': False, 'hook': True, 'disposed': False, 'reason': 'cancel', 'owns': True, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': True, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': False, 'active': False, 'hook': False, 'disposed': False, 'reason': None, 'owns': False, 'pending': 0, 'refs': 0, 'notified': False, 'borrowed': False}, {'attach': False, 'dispose': False, 'detach': False, 'reason': None, 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 0, 'terminal': False}), ({'aborted': True, 'active': True, 'hook': True, 'disposed': True, 'reason': 'cancel', 'owns': True, 'pending': 10, 'refs': 10, 'notified': True, 'borrowed': True}, {'attach': False, 'dispose': False, 'detach': True, 'reason': 'cancel', 'clear_pending': 0, 'release': False, 'notify': False, 'accept': False, 'refcount': 9, 'terminal': True})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Cancellation underflows an unattached hook reference; the returned lifecycle plan violates the stated transition contract.

Plan linking a subscription to a cancellation signal. Already-aborted signals reject attachment, immediately dispose existing work, and deliver the reason exactly once. A fresh signal attaches one hook only while the subscription is active. Preserve independent signal and subscription ownership; no callback invocation is modeled. 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: attach = s['active'] and not s['aborted'] and not s['hook']; dispose = s['aborted'] and not s['disposed']; detach = s['hook'] and (s['aborted'] or not s['active']); reason = s['reason'] if s['aborted'] else None; clear_pending = 0 if s['aborted'] else s['pending']; release = s['owns'] and not s['borrowed'] and s['aborted']; notify = s['aborted'] and not s['notified']; accept = s['active'] and not s['disposed'] and not s['aborted']; refcount = max(0,s['refs']-int(s['hook'] and s['aborted'])); terminal = s['disposed'] or s['aborted']

split: open-access