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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'expired', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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:
The pointer-leave event leaves a notification in expired instead of visible.

Toast exposure timeout is a bounded visual-notification workflow with mutable policy state {'remaining': 10, 'pause_owners': [], 'spent': 0}. Its default transition relation is {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}; domain inputs can suppress or redirect transitions and update policy fields, as specified in solve. Different-generation events are inert. Batches apply in order. Optional observe returns the selected policy field alongside the phase.

split: open-access


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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'visible', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'expired', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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:
The page-hidden event leaves a notification in visible instead of hidden-paused.

Toast exposure timeout is a bounded visual-notification workflow with mutable policy state {'remaining': 10, 'pause_owners': [], 'spent': 0}. Its default transition relation is {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}; domain inputs can suppress or redirect transitions and update policy fields, as specified in solve. Different-generation events are inert. Batches apply in order. Optional observe returns the selected policy field alongside the phase.

split: open-access


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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'expired', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'hover-paused', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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:
The page-visible event leaves a notification in expired instead of visible.

Toast exposure timeout is a bounded visual-notification workflow with mutable policy state {'remaining': 10, 'pause_owners': [], 'spent': 0}. Its default transition relation is {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}; domain inputs can suppress or redirect transitions and update policy fields, as specified in solve. Different-generation events are inert. Batches apply in order. Optional observe returns the selected policy field alongside the phase.

split: open-access


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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'hidden-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'visible', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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:
The page-hidden event leaves a notification in hidden-paused instead of both-paused.

Toast exposure timeout is a bounded visual-notification workflow with mutable policy state {'remaining': 10, 'pause_owners': [], 'spent': 0}. Its default transition relation is {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}; domain inputs can suppress or redirect transitions and update policy fields, as specified in solve. Different-generation events are inert. Batches apply in order. Optional observe returns the selected policy field alongside the phase.

split: open-access


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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'visible', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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(initial, events, generation, payload=None, observe=None):
    table = {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'expired', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}
    data = json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})) if payload is None else {**json.loads(json.dumps({'remaining': 10, 'pause_owners': [], 'spent': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event == 'pointer-enter': data['pause_owners'] = sorted(set(data['pause_owners']) | {'pointer'})
            if event == 'page-hidden': data['pause_owners'] = sorted(set(data['pause_owners']) | {'page'})
            if event == 'pointer-leave': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'pointer']
            if event == 'page-visible': data['pause_owners'] = [x for x in data['pause_owners'] if x != 'page']
            if event in ('budget-consumed', 'budget-callback'):
                elapsed = max(0, arg.get('elapsed', data['remaining']))
                charge = 0 if data['pause_owners'] else min(elapsed, data['remaining'])
                data['remaining'] -= charge
                data['spent'] += charge
                if data['remaining'] > 0 and event == 'budget-consumed': event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'expired': data['remaining'] = 0
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('visible / pointer-enter', solve('visible', [('pointer-enter', N)], N), 'hover-paused')
check('hover-paused / pointer-leave', solve('hover-paused', [('pointer-leave', N)], N), 'visible')
check('visible / page-hidden', solve('visible', [('page-hidden', N)], N), 'hidden-paused')
check('hidden-paused / page-visible', solve('hidden-paused', [('page-visible', N)], N), 'visible')
check('hover-paused / page-hidden', solve('hover-paused', [('page-hidden', N)], N), 'both-paused')
check('both-paused / page-visible', solve('both-paused', [('page-visible', N)], N), 'hover-paused')
check('both-paused / pointer-leave', solve('both-paused', [('pointer-leave', N)], N), 'hidden-paused')
check('visible / budget-consumed', solve('visible', [('budget-consumed', N)], N), 'expired')
check('expired / late-pointer-enter', solve('expired', [('late-pointer-enter', N)], N), 'expired')
check('hidden-paused / budget-callback', solve('hidden-paused', [('budget-callback', N)], N), 'hidden-paused')
check('older notification incarnation', solve('visible', [('pointer-enter', N - 1)], N), 'visible')
check('future notification incarnation', solve('visible', [('pointer-enter', N + 1)], N), 'visible')
check('unknown event is inert', solve('visible', [('unknown-event', N)], N), 'visible')
check('empty delivery batch', solve('visible', [], N), 'visible')
check('N stale deliveries before current delivery', solve('visible', [('pointer-enter', N - 1)] * N + [('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-enter then pointer-leave', solve('visible', [('pointer-enter', N), ('pointer-leave', N)], N), 'visible')
check('trace pointer-enter then page-hidden', solve('visible', [('pointer-enter', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then pointer-enter', solve('hover-paused', [('pointer-leave', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace pointer-leave then page-hidden', solve('hover-paused', [('pointer-leave', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace pointer-leave then budget-consumed', solve('hover-paused', [('pointer-leave', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('visible', [('page-hidden', N), ('page-visible', N)], N), 'visible')
check('trace page-hidden then budget-callback', solve('visible', [('page-hidden', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace page-visible then pointer-enter', solve('hidden-paused', [('page-visible', N), ('pointer-enter', N)], N), 'hover-paused')
check('trace page-visible then page-hidden', solve('hidden-paused', [('page-visible', N), ('page-hidden', N)], N), 'hidden-paused')
check('trace page-visible then budget-consumed', solve('hidden-paused', [('page-visible', N), ('budget-consumed', N)], N), 'expired')
check('trace page-hidden then page-visible', solve('hover-paused', [('page-hidden', N), ('page-visible', N)], N), 'hover-paused')
check('trace page-hidden then pointer-leave', solve('hover-paused', [('page-hidden', N), ('pointer-leave', N)], N), 'hidden-paused')
check('trace page-visible then pointer-leave', solve('both-paused', [('page-visible', N), ('pointer-leave', N)], N), 'visible')
check('trace page-visible then page-hidden', solve('both-paused', [('page-visible', N), ('page-hidden', N)], N), 'both-paused')
check('trace pointer-leave then page-visible', solve('both-paused', [('pointer-leave', N), ('page-visible', N)], N), 'visible')
check('trace pointer-leave then budget-callback', solve('both-paused', [('pointer-leave', N), ('budget-callback', N)], N), 'hidden-paused')
check('trace budget-consumed then late-pointer-enter', solve('visible', [('budget-consumed', N), ('late-pointer-enter', N)], N), 'expired')
check('trace late-pointer-enter then late-pointer-enter', solve('expired', [('late-pointer-enter', N), ('late-pointer-enter', N)], N), 'expired')
check('trace budget-callback then page-visible', solve('hidden-paused', [('budget-callback', N), ('page-visible', N)], N), 'visible')
check('trace budget-callback then budget-callback', solve('hidden-paused', [('budget-callback', N), ('budget-callback', N)], N), 'hidden-paused')
check('domain state regression 1: remaining', solve('visible', [('budget-consumed', N, {'elapsed': 3})], N, {}, 'remaining'), {'phase': 'visible', 'value': 7})
check('domain state regression 2: spent', solve('visible', [('budget-consumed', N, {'elapsed': 20})], N, {}, 'spent'), {'phase': 'expired', 'value': 10})
check('domain state regression 3: remaining', solve('visible', [('pointer-enter', N, {}), ('budget-callback', N, {'elapsed': 20})], N, {}, 'remaining'), {'phase': 'hover-paused', 'value': 10})
check('domain state regression 4: pause_owners', solve('both-paused', [('pointer-leave', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hidden-paused', 'value': ['page']})
check('domain state regression 5: pause_owners', solve('both-paused', [('page-visible', N, {})], N, {'pause_owners': ['page', 'pointer']}, 'pause_owners'), {'phase': 'hover-paused', 'value': ['pointer']})
check('domain state regression 6: spent', solve('visible', [('budget-consumed', N, {'elapsed': -2})], N, {}, 'spent'), {'phase': 'visible', 'value': 0})
check('domain state regression 7: remaining', solve('visible', [('pointer-enter', N, {}), ('page-hidden', N, {}), ('pointer-leave', N, {}), ('budget-callback', N, {'elapsed': 99})], N, {}, 'remaining'), {'phase': 'hidden-paused', 'value': 10})
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:
The page-visible event leaves a notification in visible instead of hover-paused.

Toast exposure timeout is a bounded visual-notification workflow with mutable policy state {'remaining': 10, 'pause_owners': [], 'spent': 0}. Its default transition relation is {('visible', 'pointer-enter'): 'hover-paused', ('hover-paused', 'pointer-leave'): 'visible', ('visible', 'page-hidden'): 'hidden-paused', ('hidden-paused', 'page-visible'): 'visible', ('hover-paused', 'page-hidden'): 'both-paused', ('both-paused', 'page-visible'): 'hover-paused', ('both-paused', 'pointer-leave'): 'hidden-paused', ('visible', 'budget-consumed'): 'expired', ('expired', 'late-pointer-enter'): 'expired', ('hidden-paused', 'budget-callback'): 'hidden-paused'}; domain inputs can suppress or redirect transitions and update policy fields, as specified in solve. Different-generation events are inert. Batches apply in order. Optional observe returns the selected policy field alongside the phase.

split: open-access