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

N = 1
observations = []
def solve(s):
    return {
        'grant': min(s['cap'],s['credit']+max(0,s['request'])),
        'invalid': s['request']<=0,
        'allow': s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0),
        'consume': max(0,s['credit']-int(s['delivered'] and not s['unlimited'])),
        'cancel_credit': None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])),
        'buffer_space': max(0,s['capacity']-s['pending']),
        'backpressured': s['credit']==0,
        'terminal_wait': s['complete'] and s['pending']>0 and not s['cancel'],
        'request_upstream': max(0,s['request']) if not s['cancel'] and not s['complete'] else 0,
        'saturation': s['credit']>=s['cap'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'credit': 4, 'request': 0, 'cap': 2, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 2, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 3, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [1, 2]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 0, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 4, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 7, 'invalid': False, 'allow': True, 'consume': 3, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 3, 'cap': 2, 'unlimited': False, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 2, 'complete': True, 'requests': []}, {'grant': 2, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 5, 'complete': True, 'requests': [1, 2]}, {'grant': 7, 'invalid': False, 'allow': False, 'consume': 4, 'cancel_credit': 3, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 2: [({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 4, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 6, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 0, 'cap': 4, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': False, 'requests': [1, 4]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 4, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 6, 'cap': 16, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [1, 4]}, {'grant': 14, 'invalid': False, 'allow': False, 'consume': 8, 'cancel_credit': 5, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 3: [({'credit': 1, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 9, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': [1, 6]}, {'grant': 0, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 24, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': 9, 'cap': 24, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': []}, {'grant': 9, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 12, 'request': -1, 'cap': 6, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 6, 'complete': False, 'requests': [1, 6]}, {'grant': 6, 'invalid': True, 'allow': True, 'consume': 12, 'cancel_credit': 6, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 24, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 12, 'request': 9, 'cap': 24, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 15, 'complete': True, 'requests': [1, 6]}, {'grant': 21, 'invalid': False, 'allow': False, 'consume': 12, 'cancel_credit': 7, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 4: [({'credit': 16, 'request': 12, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 20, 'complete': False, 'requests': [8, -1, 12]}, {'grant': 13, 'invalid': False, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 20, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 12, 'saturation': False}), ({'credit': 0, 'request': 12, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 8, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 16, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [1, 8]}, {'grant': 28, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': 9, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 5: [({'credit': 20, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 0, 'complete': True, 'requests': [10, -1, 15]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 15, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 10, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': 15, 'cap': 10, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [1, 10]}, {'grant': 10, 'invalid': False, 'allow': True, 'consume': 19, 'cancel_credit': 10, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 15, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': []}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': 0, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': -1, 'cap': 10, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [10, -1, 15]}, {'grant': 10, 'invalid': True, 'allow': True, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 20, 'request': 15, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': True, 'requests': [1, 10]}, {'grant': 35, 'invalid': False, 'allow': False, 'consume': 20, 'cancel_credit': 11, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(s):
    return {
        'grant': min(s['cap'],s['credit']+max(0,s['request'])),
        'invalid': s['request']<=0,
        'allow': s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0),
        'consume': max(0,s['credit']-int(s['delivered'] and not s['unlimited'])),
        'cancel_credit': None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])),
        'buffer_space': max(0,s['capacity']-s['pending']),
        'backpressured': s['has_value'] and s['credit']==0,
        'terminal_wait': s['complete'] and s['pending']>0 and not s['cancel'],
        'request_upstream': max(0,s['request']) if not s['cancel'] and not s['complete'] else 0,
        'saturation': s['credit']>=s['cap'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'credit': 4, 'request': 0, 'cap': 2, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 2, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 3, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [1, 2]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 0, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 4, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 7, 'invalid': False, 'allow': True, 'consume': 3, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 3, 'cap': 2, 'unlimited': False, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 2, 'complete': True, 'requests': []}, {'grant': 2, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 5, 'complete': True, 'requests': [1, 2]}, {'grant': 7, 'invalid': False, 'allow': False, 'consume': 4, 'cancel_credit': 3, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 2: [({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 4, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 6, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 0, 'cap': 4, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': False, 'requests': [1, 4]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 4, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 6, 'cap': 16, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [1, 4]}, {'grant': 14, 'invalid': False, 'allow': False, 'consume': 8, 'cancel_credit': 5, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 3: [({'credit': 1, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 9, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': [1, 6]}, {'grant': 0, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 24, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': 9, 'cap': 24, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': []}, {'grant': 9, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 12, 'request': -1, 'cap': 6, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 6, 'complete': False, 'requests': [1, 6]}, {'grant': 6, 'invalid': True, 'allow': True, 'consume': 12, 'cancel_credit': 6, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 24, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 12, 'request': 9, 'cap': 24, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 15, 'complete': True, 'requests': [1, 6]}, {'grant': 21, 'invalid': False, 'allow': False, 'consume': 12, 'cancel_credit': 7, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 4: [({'credit': 16, 'request': 12, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 20, 'complete': False, 'requests': [8, -1, 12]}, {'grant': 13, 'invalid': False, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 20, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 12, 'saturation': False}), ({'credit': 0, 'request': 12, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 8, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 16, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [1, 8]}, {'grant': 28, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': 9, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 5: [({'credit': 20, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 0, 'complete': True, 'requests': [10, -1, 15]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 15, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 10, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': 15, 'cap': 10, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [1, 10]}, {'grant': 10, 'invalid': False, 'allow': True, 'consume': 19, 'cancel_credit': 10, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 15, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': []}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': 0, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': -1, 'cap': 10, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [10, -1, 15]}, {'grant': 10, 'invalid': True, 'allow': True, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 20, 'request': 15, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': True, 'requests': [1, 10]}, {'grant': 35, 'invalid': False, 'allow': False, 'consume': 20, 'cancel_credit': 11, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Empty input is misreported as blocked observer demand; the returned lifecycle plan violates the stated transition contract.

Plan local observer demand credit, not a network queue. A positive request adds credit up to a configured cap; nonpositive requests are rejected without consuming credit. Unlimited mode bypasses credit checks but not cancellation. A delivery consumes one credit only if delivered; buffered callbacks count against pending capacity, not demand. Cancellation clears outstanding demand. For the request-batch projection only, -1 is an explicit unlimited sentinel and the normalized result is None, otherwise positive requests saturate at cap. 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: grant = min(s['cap'],s['credit']+max(0,s['request'])); invalid = s['request']<=0; allow = s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0); consume = max(0,s['credit']-int(s['delivered'] and not s['unlimited'])); cancel_credit = None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])); buffer_space = max(0,s['capacity']-s['pending']); backpressured = s['has_value'] and not s['unlimited'] and s['credit']==0 and not s['cancel']; terminal_wait = s['complete'] and s['pending']>0 and not s['cancel']; request_upstream = max(0,s['request']) if not s['cancel'] and not s['complete'] else 0; saturation = s['credit']>=s['cap']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'grant': min(s['cap'],s['credit']+max(0,s['request'])),
        'invalid': s['request']<=0,
        'allow': s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0),
        'consume': max(0,s['credit']-int(s['delivered'] and not s['unlimited'])),
        'cancel_credit': None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])),
        'buffer_space': max(0,s['capacity']-s['pending']),
        'backpressured': s['has_value'] and not s['unlimited'] and s['credit']==0 and not s['cancel'],
        'terminal_wait': s['complete'] and s['credit']>0,
        'request_upstream': max(0,s['request']) if not s['cancel'] and not s['complete'] else 0,
        'saturation': s['credit']>=s['cap'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'credit': 4, 'request': 0, 'cap': 2, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 2, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 3, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [1, 2]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 0, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 4, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 7, 'invalid': False, 'allow': True, 'consume': 3, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 3, 'cap': 2, 'unlimited': False, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 2, 'complete': True, 'requests': []}, {'grant': 2, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 5, 'complete': True, 'requests': [1, 2]}, {'grant': 7, 'invalid': False, 'allow': False, 'consume': 4, 'cancel_credit': 3, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 2: [({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 4, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 6, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 0, 'cap': 4, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': False, 'requests': [1, 4]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 4, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 6, 'cap': 16, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [1, 4]}, {'grant': 14, 'invalid': False, 'allow': False, 'consume': 8, 'cancel_credit': 5, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 3: [({'credit': 1, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 9, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': [1, 6]}, {'grant': 0, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 24, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': 9, 'cap': 24, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': []}, {'grant': 9, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 12, 'request': -1, 'cap': 6, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 6, 'complete': False, 'requests': [1, 6]}, {'grant': 6, 'invalid': True, 'allow': True, 'consume': 12, 'cancel_credit': 6, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 24, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 12, 'request': 9, 'cap': 24, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 15, 'complete': True, 'requests': [1, 6]}, {'grant': 21, 'invalid': False, 'allow': False, 'consume': 12, 'cancel_credit': 7, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 4: [({'credit': 16, 'request': 12, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 20, 'complete': False, 'requests': [8, -1, 12]}, {'grant': 13, 'invalid': False, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 20, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 12, 'saturation': False}), ({'credit': 0, 'request': 12, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 8, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 16, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [1, 8]}, {'grant': 28, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': 9, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 5: [({'credit': 20, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 0, 'complete': True, 'requests': [10, -1, 15]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 15, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 10, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': 15, 'cap': 10, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [1, 10]}, {'grant': 10, 'invalid': False, 'allow': True, 'consume': 19, 'cancel_credit': 10, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 15, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': []}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': 0, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': -1, 'cap': 10, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [10, -1, 15]}, {'grant': 10, 'invalid': True, 'allow': True, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 20, 'request': 15, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': True, 'requests': [1, 10]}, {'grant': 35, 'invalid': False, 'allow': False, 'consume': 20, 'cancel_credit': 11, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(s):
    return {
        'grant': min(s['cap'],s['credit']+max(0,s['request'])),
        'invalid': s['request']<=0,
        'allow': s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0),
        'consume': max(0,s['credit']-int(s['delivered'] and not s['unlimited'])),
        'cancel_credit': None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])),
        'buffer_space': max(0,s['capacity']-s['pending']),
        'backpressured': s['has_value'] and not s['unlimited'] and s['credit']==0 and not s['cancel'],
        'terminal_wait': s['complete'] and s['pending']>0,
        'request_upstream': max(0,s['request']) if not s['cancel'] and not s['complete'] else 0,
        'saturation': s['credit']>=s['cap'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'credit': 4, 'request': 0, 'cap': 2, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 2, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 3, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [1, 2]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 0, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [2, -1, 3]}, {'grant': 4, 'invalid': True, 'allow': False, 'consume': 4, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 0, 'complete': True, 'requests': [2, -1, 3]}, {'grant': 7, 'invalid': False, 'allow': True, 'consume': 3, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 3, 'cap': 2, 'unlimited': False, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 2, 'complete': True, 'requests': []}, {'grant': 2, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 4, 'request': 3, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 3, 'capacity': 5, 'complete': True, 'requests': [1, 2]}, {'grant': 7, 'invalid': False, 'allow': False, 'consume': 4, 'cancel_credit': 3, 'buffer_space': 2, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 2: [({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 4, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 6, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 0, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 6, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 8, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 0, 'cap': 4, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 10, 'complete': False, 'requests': [1, 4]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 4, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 8, 'request': 6, 'cap': 16, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 6, 'capacity': 10, 'complete': True, 'requests': [1, 4]}, {'grant': 14, 'invalid': False, 'allow': False, 'consume': 8, 'cancel_credit': 5, 'buffer_space': 4, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 3: [({'credit': 1, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 9, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': [1, 6]}, {'grant': 0, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 24, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 6, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': 9, 'cap': 24, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 6, 'complete': True, 'requests': []}, {'grant': 9, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 12, 'request': -1, 'cap': 6, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 6, 'complete': False, 'requests': [1, 6]}, {'grant': 6, 'invalid': True, 'allow': True, 'consume': 12, 'cancel_credit': 6, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 24, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 9, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 12, 'request': 9, 'cap': 24, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 9, 'capacity': 15, 'complete': True, 'requests': [1, 6]}, {'grant': 21, 'invalid': False, 'allow': False, 'consume': 12, 'cancel_credit': 7, 'buffer_space': 6, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 4: [({'credit': 16, 'request': 12, 'cap': 8, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': True, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 8, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 8, 'complete': True, 'requests': [8, -1, 12]}, {'grant': 8, 'invalid': False, 'allow': True, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': True, 'request_upstream': 0, 'saturation': False}), ({'credit': 1, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 20, 'complete': False, 'requests': [8, -1, 12]}, {'grant': 13, 'invalid': False, 'allow': False, 'consume': 1, 'cancel_credit': None, 'buffer_space': 20, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 12, 'saturation': False}), ({'credit': 0, 'request': 12, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': False, 'pending': 0, 'capacity': 8, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 16, 'request': 12, 'cap': 32, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 12, 'capacity': 20, 'complete': True, 'requests': [1, 8]}, {'grant': 28, 'invalid': False, 'allow': False, 'consume': 16, 'cancel_credit': 9, 'buffer_space': 8, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})], 5: [({'credit': 20, 'request': 0, 'cap': 0, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 0, 'complete': True, 'requests': [10, -1, 15]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': 15, 'cap': 0, 'unlimited': True, 'cancel': False, 'has_value': False, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': True, 'requests': [-1]}, {'grant': 0, 'invalid': False, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 10, 'unlimited': False, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': [-1]}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': None, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': 15, 'cap': 10, 'unlimited': False, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [1, 10]}, {'grant': 10, 'invalid': False, 'allow': True, 'consume': 19, 'cancel_credit': 10, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 15, 'saturation': True}), ({'credit': 1, 'request': 0, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': False, 'requests': []}, {'grant': 1, 'invalid': True, 'allow': False, 'consume': 1, 'cancel_credit': 0, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False}), ({'credit': 20, 'request': -1, 'cap': 10, 'unlimited': True, 'cancel': False, 'has_value': True, 'delivered': True, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': [10, -1, 15]}, {'grant': 10, 'invalid': True, 'allow': True, 'consume': 20, 'cancel_credit': None, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 0, 'request': -1, 'cap': 0, 'unlimited': False, 'cancel': False, 'has_value': False, 'delivered': False, 'pending': 0, 'capacity': 0, 'complete': False, 'requests': []}, {'grant': 0, 'invalid': True, 'allow': False, 'consume': 0, 'cancel_credit': 0, 'buffer_space': 0, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': True}), ({'credit': 20, 'request': 15, 'cap': 40, 'unlimited': True, 'cancel': True, 'has_value': True, 'delivered': True, 'pending': 15, 'capacity': 25, 'complete': True, 'requests': [1, 10]}, {'grant': 35, 'invalid': False, 'allow': False, 'consume': 20, 'cancel_credit': 11, 'buffer_space': 10, 'backpressured': False, 'terminal_wait': False, 'request_upstream': 0, 'saturation': False})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Observer completion waits for unused demand credit; the returned lifecycle plan violates the stated transition contract.

Plan local observer demand credit, not a network queue. A positive request adds credit up to a configured cap; nonpositive requests are rejected without consuming credit. Unlimited mode bypasses credit checks but not cancellation. A delivery consumes one credit only if delivered; buffered callbacks count against pending capacity, not demand. Cancellation clears outstanding demand. For the request-batch projection only, -1 is an explicit unlimited sentinel and the normalized result is None, otherwise positive requests saturate at cap. 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: grant = min(s['cap'],s['credit']+max(0,s['request'])); invalid = s['request']<=0; allow = s['has_value'] and not s['cancel'] and (s['unlimited'] or s['credit']>0); consume = max(0,s['credit']-int(s['delivered'] and not s['unlimited'])); cancel_credit = None if -1 in s['requests'] else min(s['cap'],sum(max(0,x) for x in s['requests'])); buffer_space = max(0,s['capacity']-s['pending']); backpressured = s['has_value'] and not s['unlimited'] and s['credit']==0 and not s['cancel']; terminal_wait = s['complete'] and s['pending']>0 and not s['cancel']; request_upstream = max(0,s['request']) if not s['cancel'] and not s['complete'] else 0; saturation = s['credit']>=s['cap']

split: open-access