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

N = 1
observations = []
def solve(s):
    return {
        'slots': max(0,s['limit']-len(s['active'])-s['reserved']),
        'starts': s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])],
        'pending': s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):],
        'active': [x for x in s['active'] if x!=s['done']],
        'finish': s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'cancel_siblings': s['cancel'] or (s['error'] is not None and not s['delay_error']),
        'errors': list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []),
        'report_delayed': s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'unknown_completion': False,
        'release_slots': int(s['done'] is not None and s['done'] in s['active']),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 3, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 2, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 3, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 2: [({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 6, 'limit': 6, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 1, 'pending': ['x'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 0, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 3, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 6, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 5, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 3: [({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 9, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 7, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 7, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 4: [({'active': ['a', 'b'], 'reserved': 12, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 12, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 1, 'pending': ['x'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': ['a'], 'reserved': 1, 'limit': 12, 'pending': [], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0})], 5: [({'active': ['a'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': False, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': ['x'], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': None, 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})]}
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 {
        'slots': max(0,s['limit']-len(s['active'])-s['reserved']),
        'starts': s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])],
        'pending': s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):],
        'active': [x for x in s['active'] if x!=s['done']],
        'finish': s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'cancel_siblings': s['cancel'] or (s['error'] is not None and not s['delay_error']),
        'errors': list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []),
        'report_delayed': s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'unknown_completion': s['done'] not in s['active'],
        'release_slots': int(s['done'] is not None and s['done'] in s['active']),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 3, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 2, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 3, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 2: [({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 6, 'limit': 6, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 1, 'pending': ['x'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 0, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 3, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 6, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 5, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 3: [({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 9, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 7, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 7, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 4: [({'active': ['a', 'b'], 'reserved': 12, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 12, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 1, 'pending': ['x'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': ['a'], 'reserved': 1, 'limit': 12, 'pending': [], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0})], 5: [({'active': ['a'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': False, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': ['x'], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': None, 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})]}
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:
Merge accepts completion from an untracked inner subscription; the returned lifecycle plan violates the stated transition contract.

Plan a bounded-concurrency merge observer. Active inner IDs occupy slots, reserved synchronous starts also occupy slots, and pending outer items are FIFO. Fill only free slots; completion removes the matching inner ID. Outer completion waits for active, reserved and pending work. Fail-fast cancels siblings; delay-error retains them and accumulates errors until all work drains. New delayed-error entries are [failing_inner_id,error] records; preserve the supplied done identity instead of storing only the message. 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: slots = max(0,s['limit']-len(s['active'])-s['reserved']); starts = s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])]; pending = s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):]; active = [x for x in s['active'] if x!=s['done']]; finish = s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0; cancel_siblings = s['cancel'] or (s['error'] is not None and not s['delay_error']); errors = list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []); report_delayed = s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0; unknown_completion = s['done'] is not None and s['done'] not in s['active']; release_slots = int(s['done'] is not None and s['done'] in s['active'])

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'slots': max(0,s['limit']-len(s['active'])-s['reserved']),
        'starts': s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])],
        'pending': s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):],
        'active': [x for x in s['active'] if x!=s['done']],
        'finish': s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'cancel_siblings': s['cancel'] or (s['error'] is not None and not s['delay_error']),
        'errors': list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []),
        'report_delayed': s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'unknown_completion': s['done'] is not None and s['done'] not in s['active'],
        'release_slots': int(s['done'] is not None),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 3, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 2, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 3, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 2: [({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 6, 'limit': 6, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 1, 'pending': ['x'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 0, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 3, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 6, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 5, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 3: [({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 9, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 7, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 7, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 4: [({'active': ['a', 'b'], 'reserved': 12, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 12, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 1, 'pending': ['x'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': ['a'], 'reserved': 1, 'limit': 12, 'pending': [], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0})], 5: [({'active': ['a'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': False, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': ['x'], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': None, 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})]}
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 {
        'slots': max(0,s['limit']-len(s['active'])-s['reserved']),
        'starts': s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])],
        'pending': s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):],
        'active': [x for x in s['active'] if x!=s['done']],
        'finish': s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'cancel_siblings': s['cancel'] or (s['error'] is not None and not s['delay_error']),
        'errors': list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []),
        'report_delayed': s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0,
        'unknown_completion': s['done'] is not None and s['done'] not in s['active'],
        'release_slots': int(bool(s['active'])),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 3, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': False, 'errors': [], 'cancel': True}, {'slots': 2, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 3, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 3, 'limit': 3, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 2: [({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 6, 'limit': 6, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 1, 'pending': ['x'], 'done': None, 'outer_done': False, 'error': None, 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 0, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 3, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 6, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 5, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 6, 'limit': 6, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 3: [({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 9, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 7, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': False, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 1, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 9, 'pending': [], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 7, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': [['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 9, 'limit': 9, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})], 4: [({'active': ['a', 'b'], 'reserved': 12, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 12, 'limit': 1, 'pending': [], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 12, 'pending': ['x', 'y', 'z'], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': ['x', 'y', 'z'], 'pending': [], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 0, 'limit': 1, 'pending': ['x'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x'], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': ['a'], 'reserved': 1, 'limit': 12, 'pending': [], 'done': None, 'outer_done': False, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': True}, {'slots': 10, 'starts': [], 'pending': [], 'active': ['a'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': True, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0})], 5: [({'active': ['a'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': [], 'done': None, 'outer_done': True, 'error': None, 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old'], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': [], 'reserved': 1, 'limit': 0, 'pending': ['x', 'y', 'z'], 'done': 'a', 'outer_done': True, 'error': 'bad', 'delay_error': False, 'errors': ['old'], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['a', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 0, 'limit': 1, 'pending': [], 'done': 'a', 'outer_done': False, 'error': 'bad', 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': ['b'], 'finish': False, 'cancel_siblings': False, 'errors': [['a', 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 1}), ({'active': [], 'reserved': 1, 'limit': 15, 'pending': ['x'], 'done': None, 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 14, 'starts': ['x'], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': True, 'errors': ['old', [None, 'bad']], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a'], 'reserved': 1, 'limit': 1, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': None, 'delay_error': True, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a'], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0}), ({'active': [], 'reserved': 0, 'limit': 0, 'pending': [], 'done': None, 'outer_done': False, 'error': None, 'delay_error': False, 'errors': [], 'cancel': False}, {'slots': 0, 'starts': [], 'pending': [], 'active': [], 'finish': False, 'cancel_siblings': False, 'errors': [], 'report_delayed': False, 'unknown_completion': False, 'release_slots': 0}), ({'active': ['a', 'b'], 'reserved': 15, 'limit': 15, 'pending': ['x', 'y', 'z'], 'done': 'missing', 'outer_done': True, 'error': 'bad', 'delay_error': True, 'errors': ['old'], 'cancel': True}, {'slots': 0, 'starts': [], 'pending': ['x', 'y', 'z'], 'active': ['a', 'b'], 'finish': False, 'cancel_siblings': True, 'errors': ['old', ['missing', 'bad']], 'report_delayed': False, 'unknown_completion': True, 'release_slots': 0})]}
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:
Merge completion releases a slot for an unknown inner; the returned lifecycle plan violates the stated transition contract.

Plan a bounded-concurrency merge observer. Active inner IDs occupy slots, reserved synchronous starts also occupy slots, and pending outer items are FIFO. Fill only free slots; completion removes the matching inner ID. Outer completion waits for active, reserved and pending work. Fail-fast cancels siblings; delay-error retains them and accumulates errors until all work drains. New delayed-error entries are [failing_inner_id,error] records; preserve the supplied done identity instead of storing only the message. 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: slots = max(0,s['limit']-len(s['active'])-s['reserved']); starts = s['pending'][:max(0,s['limit']-len(s['active'])-s['reserved'])]; pending = s['pending'][max(0,s['limit']-len(s['active'])-s['reserved']):]; active = [x for x in s['active'] if x!=s['done']]; finish = s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0; cancel_siblings = s['cancel'] or (s['error'] is not None and not s['delay_error']); errors = list(s['errors'])+([[s['done'],s['error']]] if s['error'] is not None else []); report_delayed = s['delay_error'] and bool(s['errors']) and s['outer_done'] and not s['active'] and not s['pending'] and s['reserved']==0; unknown_completion = s['done'] is not None and s['done'] not in s['active']; release_slots = int(s['done'] is not None and s['done'] in s['active'])

split: open-access