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

N = 1
observations = []
def solve(s):
    return {
        'predicate_index': [r[1] for r in s['guarded_inputs'] if r[0]],
        'input_index': s['input_index']+int(s['has_value']),
        'output_index': s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']),
        'value': [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else [],
        'error': s['predicate_error'] if s['has_value'] and not s['closed'] else None,
        'credit': max(0,s['credit']-int(s['has_value'])),
        'replace_request': s['has_value'] and not s['accepted'] and s['predicate_error'] is None and not s['closed'] and s['upstream_active'],
        'evaluate': list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))),
        'terminal': s['closed'] or (s['has_value'] and s['predicate_error'] is not None),
        'predicate_result': None if s['predicate_error'] is not None else s['accepted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 3, 'output_index': 3, 'value': [], 'error': 'bad', 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 2, 'output_index': 0, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': None, 'credit': 4, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 2: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 6, 'credit': 8, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 5, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 1, 'output_index': 6, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 4, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 3: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 9, 'value': [], 'error': 'bad', 'credit': 12, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 4: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 16, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 12, 'value': [], 'error': 'bad', 'credit': 16, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 12, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 12, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': True, 'evaluate': [0], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 8, 'output_index': 12, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': True, 'predicate_error': None, 'input_index': 8, 'output_index': 0, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 8, 'output_index': 12, 'credit': 16, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 16, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 5: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 10, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 16, 'value': [0], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 15, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})]}
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 {
        'predicate_index': [r[1] for r in s['guarded_inputs'] if r[0]],
        'input_index': s['input_index']+int(s['has_value']),
        'output_index': s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']),
        'value': [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else [],
        'error': s['predicate_error'] if s['has_value'] and not s['closed'] else None,
        'credit': max(0,s['credit']-int(s['accepted'])),
        'replace_request': s['has_value'] and not s['accepted'] and s['predicate_error'] is None and not s['closed'] and s['upstream_active'],
        'evaluate': list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))),
        'terminal': s['closed'] or (s['has_value'] and s['predicate_error'] is not None),
        'predicate_result': None if s['predicate_error'] is not None else s['accepted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 3, 'output_index': 3, 'value': [], 'error': 'bad', 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 2, 'output_index': 0, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': None, 'credit': 4, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 2: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 6, 'credit': 8, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 5, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 1, 'output_index': 6, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 4, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 3: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 9, 'value': [], 'error': 'bad', 'credit': 12, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 4: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 16, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 12, 'value': [], 'error': 'bad', 'credit': 16, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 12, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 12, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': True, 'evaluate': [0], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 8, 'output_index': 12, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': True, 'predicate_error': None, 'input_index': 8, 'output_index': 0, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 8, 'output_index': 12, 'credit': 16, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 16, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 5: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 10, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 16, 'value': [0], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 15, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})]}
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:
Rejected filtered events consume downstream demand; the returned lifecycle plan violates the stated transition contract.

Plan a predicate-filter observer stage. The predicate index counts every upstream value, including rejected values. Predicate errors become error notifications and never value notifications. Falsey input values remain valid data. Rejection does not consume downstream credit; an active filtered stage replaces one upstream request when a value is rejected. Predicate evaluation stops after termination. A stipulated pre-predicate type guard records [valid,payload]; only valid entries invoke user code, and falsey valid payloads remain eligible. Evaluate predicate callbacks left-to-right through the first false result inclusive, then stop; return evaluated callback indices. 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: predicate_index = [r[1] for r in s['guarded_inputs'] if r[0]]; input_index = s['input_index']+int(s['has_value']); output_index = s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']); value = [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else []; error = s['predicate_error'] if s['has_value'] and not s['closed'] else None; credit = max(0,s['credit']-int(s['has_value'] and s['accepted'] and s['predicate_error'] is None)); replace_request = s['has_value'] and not s['accepted'] and s['predicate_error'] is None and not s['closed'] and s['upstream_active']; evaluate = list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))); terminal = s['closed'] or (s['has_value'] and s['predicate_error'] is not None); predicate_result = None if s['predicate_error'] is not None else s['accepted']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'predicate_index': [r[1] for r in s['guarded_inputs'] if r[0]],
        'input_index': s['input_index']+int(s['has_value']),
        'output_index': s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']),
        'value': [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else [],
        'error': s['predicate_error'] if s['has_value'] and not s['closed'] else None,
        'credit': max(0,s['credit']-int(s['has_value'] and s['accepted'] and s['predicate_error'] is None)),
        'replace_request': False,
        'evaluate': list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))),
        'terminal': s['closed'] or (s['has_value'] and s['predicate_error'] is not None),
        'predicate_result': None if s['predicate_error'] is not None else s['accepted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 3, 'output_index': 3, 'value': [], 'error': 'bad', 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 2, 'output_index': 0, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': None, 'credit': 4, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 2: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 6, 'credit': 8, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 5, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 1, 'output_index': 6, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 4, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 3: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 9, 'value': [], 'error': 'bad', 'credit': 12, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 4: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 16, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 12, 'value': [], 'error': 'bad', 'credit': 16, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 12, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 12, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': True, 'evaluate': [0], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 8, 'output_index': 12, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': True, 'predicate_error': None, 'input_index': 8, 'output_index': 0, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 8, 'output_index': 12, 'credit': 16, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 16, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 5: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 10, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 16, 'value': [0], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 15, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})]}
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 {
        'predicate_index': [r[1] for r in s['guarded_inputs'] if r[0]],
        'input_index': s['input_index']+int(s['has_value']),
        'output_index': s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']),
        'value': [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else [],
        'error': s['predicate_error'] if s['has_value'] and not s['closed'] else None,
        'credit': max(0,s['credit']-int(s['has_value'] and s['accepted'] and s['predicate_error'] is None)),
        'replace_request': s['has_value'] and not s['accepted'],
        'evaluate': list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))),
        'terminal': s['closed'] or (s['has_value'] and s['predicate_error'] is not None),
        'predicate_result': None if s['predicate_error'] is not None else s['accepted'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 3, 'output_index': 3, 'value': [], 'error': 'bad', 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 2, 'output_index': 0, 'credit': 4, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': None, 'credit': 4, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 2, 'output_index': 3, 'credit': 4, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 3, 'output_index': 3, 'value': [], 'error': None, 'credit': 4, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 2: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 6, 'credit': 8, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 5, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 1, 'output_index': 6, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': 'bad', 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 4, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': False}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 4, 'output_index': 6, 'credit': 8, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 5, 'output_index': 6, 'value': [], 'error': None, 'credit': 8, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 3: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 9, 'value': [], 'error': 'bad', 'credit': 12, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 1, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 6, 'output_index': 9, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': True, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 6, 'output_index': 9, 'credit': 12, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 7, 'output_index': 9, 'value': [], 'error': None, 'credit': 12, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 4: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 16, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 12, 'value': [], 'error': 'bad', 'credit': 16, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': False, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 12, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': True, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 12, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 12, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 1, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': True, 'evaluate': [0], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': False, 'predicate_error': None, 'input_index': 8, 'output_index': 12, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 1, 'replace_request': False, 'evaluate': [], 'terminal': True, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': True, 'predicate_error': None, 'input_index': 8, 'output_index': 0, 'credit': 1, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 8, 'output_index': 12, 'credit': 16, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 9, 'output_index': 12, 'value': [], 'error': None, 'credit': 16, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})], 5: [({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None}), ({'value': None, 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 10, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0], 'terminal': False, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 0, 'credit': 1, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 0, 'value': [], 'error': 'bad', 'credit': 1, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 'x', 'accepted': False, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': []}, {'predicate_index': [0, 'ok'], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 0, 'replace_request': True, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 0, 'accepted': True, 'predicate_error': 'bad', 'input_index': 0, 'output_index': 0, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 'bad'], [True, 0], [True, 'ok']], 'predicate_chain': [True, False, True]}, {'predicate_index': [0, 'ok'], 'input_index': 1, 'output_index': 0, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0, 1], 'terminal': True, 'predicate_result': None}), ({'value': 0, 'accepted': True, 'predicate_error': None, 'input_index': 10, 'output_index': 15, 'credit': 0, 'closed': False, 'has_value': True, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [[False, 0]], 'predicate_chain': [True, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 16, 'value': [0], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [0, 1], 'terminal': False, 'predicate_result': True}), ({'value': None, 'accepted': False, 'predicate_error': None, 'input_index': 0, 'output_index': 0, 'credit': 0, 'closed': False, 'has_value': False, 'upstream_active': False, 'evaluated': False, 'guarded_inputs': [], 'predicate_chain': []}, {'predicate_index': [], 'input_index': 0, 'output_index': 0, 'value': [], 'error': None, 'credit': 0, 'replace_request': False, 'evaluate': [], 'terminal': False, 'predicate_result': False}), ({'value': 'x', 'accepted': True, 'predicate_error': 'bad', 'input_index': 10, 'output_index': 15, 'credit': 20, 'closed': True, 'has_value': True, 'upstream_active': True, 'evaluated': True, 'guarded_inputs': [[False, 0]], 'predicate_chain': [False, True]}, {'predicate_index': [], 'input_index': 11, 'output_index': 15, 'value': [], 'error': None, 'credit': 20, 'replace_request': False, 'evaluate': [0], 'terminal': True, 'predicate_result': None})]}
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 rejected value permanently loses upstream demand; the returned lifecycle plan violates the stated transition contract.

Plan a predicate-filter observer stage. The predicate index counts every upstream value, including rejected values. Predicate errors become error notifications and never value notifications. Falsey input values remain valid data. Rejection does not consume downstream credit; an active filtered stage replaces one upstream request when a value is rejected. Predicate evaluation stops after termination. A stipulated pre-predicate type guard records [valid,payload]; only valid entries invoke user code, and falsey valid payloads remain eligible. Evaluate predicate callbacks left-to-right through the first false result inclusive, then stop; return evaluated callback indices. 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: predicate_index = [r[1] for r in s['guarded_inputs'] if r[0]]; input_index = s['input_index']+int(s['has_value']); output_index = s['output_index']+int(s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed']); value = [s['value']] if s['has_value'] and s['accepted'] and s['predicate_error'] is None and not s['closed'] else []; error = s['predicate_error'] if s['has_value'] and not s['closed'] else None; credit = max(0,s['credit']-int(s['has_value'] and s['accepted'] and s['predicate_error'] is None)); replace_request = s['has_value'] and not s['accepted'] and s['predicate_error'] is None and not s['closed'] and s['upstream_active']; evaluate = list(range(next((i+1 for i,result in enumerate(s['predicate_chain']) if not result),len(s['predicate_chain'])))); terminal = s['closed'] or (s['has_value'] and s['predicate_error'] is not None); predicate_result = None if s['predicate_error'] is not None else s['accepted']

split: open-access