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

N = 1
observations = []
def solve(s):
    return {
        'deadline': s['now']+s['delay'] if s['incoming'] is not None else s['due'],
        'pending': s['incoming'] if s['incoming'] is not None else s['pending'],
        'token': s['token']+int(s['incoming'] is not None),
        'current_timer': s['fired']==s['token'],
        'due': max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))),
        'timer_flush': s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused'],
        'complete_flush': s['complete'] and s['pending'] is not None,
        'cancel_timer': s['cancel'] or s['complete'],
        'cancel_payload': min(s['now']+s['delay'],s['burst_start']+s['max_wait']),
        'schedule': s['incoming'] is not None and not s['cancel'] and not s['complete'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'now': 3, 'delay': 2, 'due': 0, 'token': 3, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 4, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 4, 'max_wait': 2, 'timer_start': 0, 'pause_spans': []}, {'deadline': 3, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 3, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 4, 'max_wait': 5, 'timer_start': 1, 'pause_spans': [[0, 2]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': None, 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[0, 2]]}, {'deadline': 3, 'pending': None, 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 0, 'token': 1, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 1, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 3, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 8, 'token': 3, 'fired': 3, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 5, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 10, 'pending': 'new', 'token': 4, 'current_timer': True, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False})], 2: [({'now': 6, 'delay': 4, 'due': 0, 'token': 6, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 5, 'schedule': False}), ({'now': 16, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 4]]}, {'deadline': 6, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 0, 'due': 0, 'token': 1, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 6, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 6, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 4]]}, {'deadline': 20, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 8, 'max_wait': 10, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 4, 'due': 6, 'token': 6, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': []}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 5, 'schedule': True}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 16, 'token': 6, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 8, 'max_wait': 10, 'timer_start': 8, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 20, 'pending': 'new', 'token': 7, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 18, 'schedule': False})], 3: [({'now': 9, 'delay': 6, 'due': 9, 'token': 9, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 15, 'pending': 'new', 'token': 10, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 0, 'token': 9, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 0, 'pending': 'old', 'token': 9, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 7, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 0, 'max_wait': 15, 'timer_start': 1, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 24, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 9, 'delay': 0, 'due': 24, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 6, 'timer_start': 12, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 9, 'token': 0, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 24, 'token': 9, 'fired': 9, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 15, 'timer_start': 12, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 30, 'pending': 'new', 'token': 10, 'current_timer': True, 'due': 6, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 27, 'schedule': False})], 4: [({'now': 12, 'delay': 8, 'due': 0, 'token': 12, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 8]]}, {'deadline': 20, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 0, 'due': 0, 'token': 12, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': True, 'burst_start': 16, 'max_wait': 8, 'timer_start': 0, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 0, 'pending': 'old', 'token': 12, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 24, 'schedule': False}), ({'now': 0, 'delay': 8, 'due': 12, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 20, 'timer_start': 1, 'pause_spans': []}, {'deadline': 8, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 8, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 32, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 16, 'max_wait': 20, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 12, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 12, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 12, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 16, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 0, 'token': 0, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 8, 'due': 32, 'token': 12, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 16, 'max_wait': 20, 'timer_start': 16, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 40, 'pending': 'new', 'token': 13, 'current_timer': True, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 36, 'schedule': False})], 5: [({'now': 15, 'delay': 10, 'due': 0, 'token': 1, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 25, 'pending': 'new', 'token': 2, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 0, 'token': 15, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 20, 'max_wait': 0, 'timer_start': 20, 'pause_spans': [[0, 10]]}, {'deadline': 0, 'pending': 'old', 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 40, 'token': 15, 'fired': 15, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 0, 'pause_spans': []}, {'deadline': 40, 'pending': 'old', 'token': 15, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 15, 'token': 15, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 25, 'timer_start': 1, 'pause_spans': []}, {'deadline': 15, 'pending': None, 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 25, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 40, 'token': 1, 'fired': 0, 'incoming': None, 'pending': None, 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[0, 10]]}, {'deadline': 40, 'pending': None, 'token': 1, 'current_timer': False, 'due': 5, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 11, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 15, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 25, 'timer_start': 20, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 40, 'delay': 10, 'due': 40, 'token': 15, 'fired': 15, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 20, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 50, 'pending': 'new', 'token': 16, 'current_timer': True, 'due': 10, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 45, 'schedule': 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 {
        'deadline': s['now']+s['delay'] if s['incoming'] is not None else s['due'],
        'pending': s['incoming'] if s['incoming'] is not None else s['pending'],
        'token': s['token']+int(s['incoming'] is not None),
        'current_timer': s['fired']==s['token'],
        'due': max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))),
        'timer_flush': s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused'],
        'complete_flush': s['complete'] and s['flush'] and s['pending'] is not None,
        'cancel_timer': s['cancel'] or s['complete'],
        'cancel_payload': min(s['now']+s['delay'],s['burst_start']+s['max_wait']),
        'schedule': s['incoming'] is not None and not s['cancel'] and not s['complete'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'now': 3, 'delay': 2, 'due': 0, 'token': 3, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 4, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 4, 'max_wait': 2, 'timer_start': 0, 'pause_spans': []}, {'deadline': 3, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 3, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 4, 'max_wait': 5, 'timer_start': 1, 'pause_spans': [[0, 2]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': None, 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[0, 2]]}, {'deadline': 3, 'pending': None, 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 0, 'token': 1, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 1, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 3, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 8, 'token': 3, 'fired': 3, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 5, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 10, 'pending': 'new', 'token': 4, 'current_timer': True, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False})], 2: [({'now': 6, 'delay': 4, 'due': 0, 'token': 6, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 5, 'schedule': False}), ({'now': 16, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 4]]}, {'deadline': 6, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 0, 'due': 0, 'token': 1, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 6, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 6, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 4]]}, {'deadline': 20, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 8, 'max_wait': 10, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 4, 'due': 6, 'token': 6, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': []}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 5, 'schedule': True}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 16, 'token': 6, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 8, 'max_wait': 10, 'timer_start': 8, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 20, 'pending': 'new', 'token': 7, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 18, 'schedule': False})], 3: [({'now': 9, 'delay': 6, 'due': 9, 'token': 9, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 15, 'pending': 'new', 'token': 10, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 0, 'token': 9, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 0, 'pending': 'old', 'token': 9, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 7, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 0, 'max_wait': 15, 'timer_start': 1, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 24, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 9, 'delay': 0, 'due': 24, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 6, 'timer_start': 12, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 9, 'token': 0, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 24, 'token': 9, 'fired': 9, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 15, 'timer_start': 12, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 30, 'pending': 'new', 'token': 10, 'current_timer': True, 'due': 6, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 27, 'schedule': False})], 4: [({'now': 12, 'delay': 8, 'due': 0, 'token': 12, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 8]]}, {'deadline': 20, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 0, 'due': 0, 'token': 12, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': True, 'burst_start': 16, 'max_wait': 8, 'timer_start': 0, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 0, 'pending': 'old', 'token': 12, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 24, 'schedule': False}), ({'now': 0, 'delay': 8, 'due': 12, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 20, 'timer_start': 1, 'pause_spans': []}, {'deadline': 8, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 8, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 32, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 16, 'max_wait': 20, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 12, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 12, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 12, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 16, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 0, 'token': 0, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 8, 'due': 32, 'token': 12, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 16, 'max_wait': 20, 'timer_start': 16, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 40, 'pending': 'new', 'token': 13, 'current_timer': True, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 36, 'schedule': False})], 5: [({'now': 15, 'delay': 10, 'due': 0, 'token': 1, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 25, 'pending': 'new', 'token': 2, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 0, 'token': 15, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 20, 'max_wait': 0, 'timer_start': 20, 'pause_spans': [[0, 10]]}, {'deadline': 0, 'pending': 'old', 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 40, 'token': 15, 'fired': 15, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 0, 'pause_spans': []}, {'deadline': 40, 'pending': 'old', 'token': 15, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 15, 'token': 15, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 25, 'timer_start': 1, 'pause_spans': []}, {'deadline': 15, 'pending': None, 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 25, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 40, 'token': 1, 'fired': 0, 'incoming': None, 'pending': None, 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[0, 10]]}, {'deadline': 40, 'pending': None, 'token': 1, 'current_timer': False, 'due': 5, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 11, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 15, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 25, 'timer_start': 20, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 40, 'delay': 10, 'due': 40, 'token': 15, 'fired': 15, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 20, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 50, 'pending': 'new', 'token': 16, 'current_timer': True, 'due': 10, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 45, 'schedule': 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:
Debounce completion flushes despite an explicit discard policy; the returned lifecycle plan violates the stated transition contract.

Plan a trailing debounce listener. Every accepted event replaces pending payload and restarts a timer at now+delay. A stale timer token cannot flush a newer payload. Completion flushes pending data only under flush policy; cancellation never flushes. At equality a current timer is due. Pause preserves payload while withholding timer delivery. For the maximum-wait projection, use the earlier of the quiet deadline now+delay and the fixed burst deadline burst_start+max_wait. Pause spans are disjoint half-open suspension intervals. Remaining debounce delay counts elapsed active time only, clipping spans to [timer_start,now]. 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: deadline = s['now']+s['delay'] if s['incoming'] is not None else s['due']; pending = s['incoming'] if s['incoming'] is not None else s['pending']; token = s['token']+int(s['incoming'] is not None); current_timer = s['fired']==s['token']; due = max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))); timer_flush = s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused']; complete_flush = s['complete'] and s['flush'] and s['pending'] is not None and not s['cancel']; cancel_timer = s['cancel'] or s['complete']; cancel_payload = min(s['now']+s['delay'],s['burst_start']+s['max_wait']); schedule = s['incoming'] is not None and not s['cancel'] and not s['complete']

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'deadline': s['now']+s['delay'] if s['incoming'] is not None else s['due'],
        'pending': s['incoming'] if s['incoming'] is not None else s['pending'],
        'token': s['token']+int(s['incoming'] is not None),
        'current_timer': s['fired']==s['token'],
        'due': max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))),
        'timer_flush': s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused'],
        'complete_flush': s['complete'] and s['flush'] and s['pending'] is not None and not s['cancel'],
        'cancel_timer': s['cancel'],
        'cancel_payload': min(s['now']+s['delay'],s['burst_start']+s['max_wait']),
        'schedule': s['incoming'] is not None and not s['cancel'] and not s['complete'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'now': 3, 'delay': 2, 'due': 0, 'token': 3, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 4, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 4, 'max_wait': 2, 'timer_start': 0, 'pause_spans': []}, {'deadline': 3, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 3, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 4, 'max_wait': 5, 'timer_start': 1, 'pause_spans': [[0, 2]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': None, 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[0, 2]]}, {'deadline': 3, 'pending': None, 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 0, 'token': 1, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 1, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 3, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 8, 'token': 3, 'fired': 3, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 5, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 10, 'pending': 'new', 'token': 4, 'current_timer': True, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False})], 2: [({'now': 6, 'delay': 4, 'due': 0, 'token': 6, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 5, 'schedule': False}), ({'now': 16, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 4]]}, {'deadline': 6, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 0, 'due': 0, 'token': 1, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 6, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 6, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 4]]}, {'deadline': 20, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 8, 'max_wait': 10, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 4, 'due': 6, 'token': 6, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': []}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 5, 'schedule': True}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 16, 'token': 6, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 8, 'max_wait': 10, 'timer_start': 8, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 20, 'pending': 'new', 'token': 7, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 18, 'schedule': False})], 3: [({'now': 9, 'delay': 6, 'due': 9, 'token': 9, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 15, 'pending': 'new', 'token': 10, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 0, 'token': 9, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 0, 'pending': 'old', 'token': 9, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 7, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 0, 'max_wait': 15, 'timer_start': 1, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 24, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 9, 'delay': 0, 'due': 24, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 6, 'timer_start': 12, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 9, 'token': 0, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 24, 'token': 9, 'fired': 9, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 15, 'timer_start': 12, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 30, 'pending': 'new', 'token': 10, 'current_timer': True, 'due': 6, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 27, 'schedule': False})], 4: [({'now': 12, 'delay': 8, 'due': 0, 'token': 12, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 8]]}, {'deadline': 20, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 0, 'due': 0, 'token': 12, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': True, 'burst_start': 16, 'max_wait': 8, 'timer_start': 0, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 0, 'pending': 'old', 'token': 12, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 24, 'schedule': False}), ({'now': 0, 'delay': 8, 'due': 12, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 20, 'timer_start': 1, 'pause_spans': []}, {'deadline': 8, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 8, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 32, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 16, 'max_wait': 20, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 12, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 12, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 12, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 16, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 0, 'token': 0, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 8, 'due': 32, 'token': 12, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 16, 'max_wait': 20, 'timer_start': 16, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 40, 'pending': 'new', 'token': 13, 'current_timer': True, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 36, 'schedule': False})], 5: [({'now': 15, 'delay': 10, 'due': 0, 'token': 1, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 25, 'pending': 'new', 'token': 2, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 0, 'token': 15, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 20, 'max_wait': 0, 'timer_start': 20, 'pause_spans': [[0, 10]]}, {'deadline': 0, 'pending': 'old', 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 40, 'token': 15, 'fired': 15, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 0, 'pause_spans': []}, {'deadline': 40, 'pending': 'old', 'token': 15, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 15, 'token': 15, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 25, 'timer_start': 1, 'pause_spans': []}, {'deadline': 15, 'pending': None, 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 25, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 40, 'token': 1, 'fired': 0, 'incoming': None, 'pending': None, 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[0, 10]]}, {'deadline': 40, 'pending': None, 'token': 1, 'current_timer': False, 'due': 5, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 11, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 15, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 25, 'timer_start': 20, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 40, 'delay': 10, 'due': 40, 'token': 15, 'fired': 15, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 20, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 50, 'pending': 'new', 'token': 16, 'current_timer': True, 'due': 10, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 45, 'schedule': 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 {
        'deadline': s['now']+s['delay'] if s['incoming'] is not None else s['due'],
        'pending': s['incoming'] if s['incoming'] is not None else s['pending'],
        'token': s['token']+int(s['incoming'] is not None),
        'current_timer': s['fired']==s['token'],
        'due': max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))),
        'timer_flush': s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused'],
        'complete_flush': s['complete'] and s['flush'] and s['pending'] is not None and not s['cancel'],
        'cancel_timer': s['complete'],
        'cancel_payload': min(s['now']+s['delay'],s['burst_start']+s['max_wait']),
        'schedule': s['incoming'] is not None and not s['cancel'] and not s['complete'],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'now': 3, 'delay': 2, 'due': 0, 'token': 3, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 4, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 4, 'max_wait': 2, 'timer_start': 0, 'pause_spans': []}, {'deadline': 3, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 3, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 4, 'max_wait': 5, 'timer_start': 1, 'pause_spans': [[0, 2]]}, {'deadline': 0, 'pending': 'old', 'token': 3, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': None, 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[0, 2]]}, {'deadline': 3, 'pending': None, 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 0, 'token': 1, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 1, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 3, 'delay': 0, 'due': 3, 'token': 0, 'fired': 3, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 2, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 3, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 3, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 8, 'delay': 2, 'due': 8, 'token': 3, 'fired': 3, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 4, 'max_wait': 5, 'timer_start': 4, 'pause_spans': [[1, 2], [4, 8]]}, {'deadline': 10, 'pending': 'new', 'token': 4, 'current_timer': True, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False})], 2: [({'now': 6, 'delay': 4, 'due': 0, 'token': 6, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 1, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 5, 'schedule': False}), ({'now': 16, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 4]]}, {'deadline': 6, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 0, 'due': 0, 'token': 1, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 6, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 6, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 4]]}, {'deadline': 20, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 6, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 8, 'max_wait': 10, 'timer_start': 0, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 6, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 6, 'delay': 4, 'due': 6, 'token': 6, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 4, 'timer_start': 0, 'pause_spans': []}, {'deadline': 10, 'pending': 'new', 'token': 7, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 5, 'schedule': True}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 16, 'delay': 4, 'due': 16, 'token': 6, 'fired': 6, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 8, 'max_wait': 10, 'timer_start': 8, 'pause_spans': [[1, 4], [8, 16]]}, {'deadline': 20, 'pending': 'new', 'token': 7, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 18, 'schedule': False})], 3: [({'now': 9, 'delay': 6, 'due': 9, 'token': 9, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 15, 'pending': 'new', 'token': 10, 'current_timer': False, 'due': 2, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 0, 'token': 9, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 0, 'pending': 'old', 'token': 9, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 7, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 0, 'max_wait': 15, 'timer_start': 1, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 24, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 6, 'timer_start': 1, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 9, 'delay': 0, 'due': 24, 'token': 0, 'fired': 0, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 6, 'timer_start': 12, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'old', 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 9, 'schedule': False}), ({'now': 24, 'delay': 0, 'due': 9, 'token': 0, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 6]]}, {'deadline': 24, 'pending': 'new', 'token': 1, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 24, 'delay': 6, 'due': 24, 'token': 9, 'fired': 9, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 12, 'max_wait': 15, 'timer_start': 12, 'pause_spans': [[1, 6], [12, 24]]}, {'deadline': 30, 'pending': 'new', 'token': 10, 'current_timer': True, 'due': 6, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 27, 'schedule': False})], 4: [({'now': 12, 'delay': 8, 'due': 0, 'token': 12, 'fired': 0, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 1, 'pause_spans': [[0, 8]]}, {'deadline': 20, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 0, 'due': 0, 'token': 12, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': True, 'burst_start': 16, 'max_wait': 8, 'timer_start': 0, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 0, 'pending': 'old', 'token': 12, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 24, 'schedule': False}), ({'now': 0, 'delay': 8, 'due': 12, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 0, 'max_wait': 20, 'timer_start': 1, 'pause_spans': []}, {'deadline': 8, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 8, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 32, 'token': 1, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 16, 'max_wait': 20, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 12, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': True, 'cancel_timer': True, 'cancel_payload': 12, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 12, 'fired': 1, 'incoming': 'new', 'pending': None, 'complete': False, 'flush': False, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 16, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'new', 'token': 13, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 12, 'delay': 0, 'due': 0, 'token': 0, 'fired': 12, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': False, 'cancel': True, 'paused': False, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[0, 8]]}, {'deadline': 0, 'pending': 'old', 'token': 0, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 32, 'delay': 8, 'due': 32, 'token': 12, 'fired': 12, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 16, 'max_wait': 20, 'timer_start': 16, 'pause_spans': [[1, 8], [16, 32]]}, {'deadline': 40, 'pending': 'new', 'token': 13, 'current_timer': True, 'due': 8, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 36, 'schedule': False})], 5: [({'now': 15, 'delay': 10, 'due': 0, 'token': 1, 'fired': 1, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': False, 'cancel': False, 'paused': True, 'burst_start': 1, 'max_wait': 0, 'timer_start': 0, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 25, 'pending': 'new', 'token': 2, 'current_timer': True, 'due': 4, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 1, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 0, 'token': 15, 'fired': 1, 'incoming': None, 'pending': 'old', 'complete': False, 'flush': True, 'cancel': True, 'paused': False, 'burst_start': 20, 'max_wait': 0, 'timer_start': 20, 'pause_spans': [[0, 10]]}, {'deadline': 0, 'pending': 'old', 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 0, 'due': 40, 'token': 15, 'fired': 15, 'incoming': None, 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 0, 'pause_spans': []}, {'deadline': 40, 'pending': 'old', 'token': 15, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 15, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 15, 'token': 15, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 25, 'timer_start': 1, 'pause_spans': []}, {'deadline': 15, 'pending': None, 'token': 15, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 25, 'schedule': False}), ({'now': 15, 'delay': 10, 'due': 40, 'token': 1, 'fired': 0, 'incoming': None, 'pending': None, 'complete': True, 'flush': True, 'cancel': False, 'paused': False, 'burst_start': 1, 'max_wait': 10, 'timer_start': 1, 'pause_spans': [[0, 10]]}, {'deadline': 40, 'pending': None, 'token': 1, 'current_timer': False, 'due': 5, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 11, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 15, 'token': 1, 'fired': 0, 'incoming': 'new', 'pending': None, 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 1, 'max_wait': 25, 'timer_start': 20, 'pause_spans': []}, {'deadline': 0, 'pending': 'new', 'token': 2, 'current_timer': False, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 0, 'schedule': False}), ({'now': 0, 'delay': 0, 'due': 0, 'token': 0, 'fired': 0, 'incoming': None, 'pending': None, 'complete': False, 'flush': False, 'cancel': False, 'paused': False, 'burst_start': 0, 'max_wait': 0, 'timer_start': 0, 'pause_spans': []}, {'deadline': 0, 'pending': None, 'token': 0, 'current_timer': True, 'due': 0, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': False, 'cancel_payload': 0, 'schedule': False}), ({'now': 40, 'delay': 10, 'due': 40, 'token': 15, 'fired': 15, 'incoming': 'new', 'pending': 'old', 'complete': True, 'flush': True, 'cancel': True, 'paused': True, 'burst_start': 20, 'max_wait': 25, 'timer_start': 20, 'pause_spans': [[1, 10], [20, 40]]}, {'deadline': 50, 'pending': 'new', 'token': 16, 'current_timer': True, 'due': 10, 'timer_flush': False, 'complete_flush': False, 'cancel_timer': True, 'cancel_payload': 45, 'schedule': 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:
Debounce completion fails to invalidate its outstanding timer; the returned lifecycle plan violates the stated transition contract.

Plan a trailing debounce listener. Every accepted event replaces pending payload and restarts a timer at now+delay. A stale timer token cannot flush a newer payload. Completion flushes pending data only under flush policy; cancellation never flushes. At equality a current timer is due. Pause preserves payload while withholding timer delivery. For the maximum-wait projection, use the earlier of the quiet deadline now+delay and the fixed burst deadline burst_start+max_wait. Pause spans are disjoint half-open suspension intervals. Remaining debounce delay counts elapsed active time only, clipping spans to [timer_start,now]. 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: deadline = s['now']+s['delay'] if s['incoming'] is not None else s['due']; pending = s['incoming'] if s['incoming'] is not None else s['pending']; token = s['token']+int(s['incoming'] is not None); current_timer = s['fired']==s['token']; due = max(0,s['delay']-max(0,s['now']-s['timer_start']-sum(max(0,min(b,s['now'])-max(a,s['timer_start'])) for a,b in s['pause_spans']))); timer_flush = s['pending'] is not None and s['fired']==s['token'] and s['now']>=s['due'] and not s['cancel'] and not s['paused']; complete_flush = s['complete'] and s['flush'] and s['pending'] is not None and not s['cancel']; cancel_timer = s['cancel'] or s['complete']; cancel_payload = min(s['now']+s['delay'],s['burst_start']+s['max_wait']); schedule = s['incoming'] is not None and not s['cancel'] and not s['complete']

split: open-access