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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpinned', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'pinned', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 unpin-failure event leaves a notification in unpinned instead of unpin-error.

Inbox notification pin persistence is a bounded visual-notification workflow with mutable policy state {'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True}. Its default transition relation is {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}; 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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'pinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'pin-pending', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 cancel-pin-intent event leaves a notification in pinned instead of unpinned.

Inbox notification pin persistence is a bounded visual-notification workflow with mutable policy state {'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True}. Its default transition relation is {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}; 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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'unpinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'unpin-pending', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 cancel-unpin-intent event leaves a notification in unpinned instead of pinned.

Inbox notification pin persistence is a bounded visual-notification workflow with mutable policy state {'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True}. Its default transition relation is {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}; 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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'unpinned', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'gone', ('expired-pinned', 'unpin-expired'): 'gone'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 notification-expires event leaves a notification in unpinned instead of expired-pinned.

Inbox notification pin persistence is a bounded visual-notification workflow with mutable policy state {'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True}. Its default transition relation is {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}; 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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'pinned'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 = {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'unpinned'}
    data = json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})) if payload is None else {**json.loads(json.dumps({'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True})), **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 == 'pin-click' and data['item'] not in data['pinned'] and len(data['pinned']) >= data['capacity']: event = 'unknown-event'
            if event == 'notification-expires': data['expired'] = True
            state = table.get((state, event), state)
            if state in ('pinned','expired-pinned') and data['item'] not in data['pinned']: data['pinned'].append(data['item'])
            if state in ('unpinned','gone'): data['pinned'] = [x for x in data['pinned'] if x != data['item']]
            if state == 'gone': data['retained'] = False
    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('unpinned / pin-click', solve('unpinned', [('pin-click', N)], N), 'pin-pending')
check('pin-pending / pin-success', solve('pin-pending', [('pin-success', N)], N), 'pinned')
check('pin-pending / pin-failure', solve('pin-pending', [('pin-failure', N)], N), 'pin-error')
check('pinned / unpin-click', solve('pinned', [('unpin-click', N)], N), 'unpin-pending')
check('unpin-pending / unpin-success', solve('unpin-pending', [('unpin-success', N)], N), 'unpinned')
check('unpin-pending / unpin-failure', solve('unpin-pending', [('unpin-failure', N)], N), 'unpin-error')
check('pin-error / cancel-pin-intent', solve('pin-error', [('cancel-pin-intent', N)], N), 'unpinned')
check('unpin-error / cancel-unpin-intent', solve('unpin-error', [('cancel-unpin-intent', N)], N), 'pinned')
check('pinned / notification-expires', solve('pinned', [('notification-expires', N)], N), 'expired-pinned')
check('expired-pinned / unpin-expired', solve('expired-pinned', [('unpin-expired', N)], N), 'gone')
check('older notification incarnation', solve('unpinned', [('pin-click', N - 1)], N), 'unpinned')
check('future notification incarnation', solve('unpinned', [('pin-click', N + 1)], N), 'unpinned')
check('unknown event is inert', solve('unpinned', [('unknown-event', N)], N), 'unpinned')
check('empty delivery batch', solve('unpinned', [], N), 'unpinned')
check('N stale deliveries before current delivery', solve('unpinned', [('pin-click', N - 1)] * N + [('pin-click', N)], N), 'pin-pending')
check('trace pin-click then pin-success', solve('unpinned', [('pin-click', N), ('pin-success', N)], N), 'pinned')
check('trace pin-click then pin-failure', solve('unpinned', [('pin-click', N), ('pin-failure', N)], N), 'pin-error')
check('trace pin-success then unpin-click', solve('pin-pending', [('pin-success', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace pin-success then notification-expires', solve('pin-pending', [('pin-success', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace pin-failure then cancel-pin-intent', solve('pin-pending', [('pin-failure', N), ('cancel-pin-intent', N)], N), 'unpinned')
check('trace unpin-click then unpin-success', solve('pinned', [('unpin-click', N), ('unpin-success', N)], N), 'unpinned')
check('trace unpin-click then unpin-failure', solve('pinned', [('unpin-click', N), ('unpin-failure', N)], N), 'unpin-error')
check('trace unpin-success then pin-click', solve('unpin-pending', [('unpin-success', N), ('pin-click', N)], N), 'pin-pending')
check('trace unpin-failure then cancel-unpin-intent', solve('unpin-pending', [('unpin-failure', N), ('cancel-unpin-intent', N)], N), 'pinned')
check('trace cancel-pin-intent then pin-click', solve('pin-error', [('cancel-pin-intent', N), ('pin-click', N)], N), 'pin-pending')
check('trace cancel-unpin-intent then unpin-click', solve('unpin-error', [('cancel-unpin-intent', N), ('unpin-click', N)], N), 'unpin-pending')
check('trace cancel-unpin-intent then notification-expires', solve('unpin-error', [('cancel-unpin-intent', N), ('notification-expires', N)], N), 'expired-pinned')
check('trace notification-expires then unpin-expired', solve('pinned', [('notification-expires', N), ('unpin-expired', N)], N), 'gone')
check('domain state regression 1: pinned', solve('unpinned', [('pin-click', N, {})], N, {'capacity': 1}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 2: pinned', solve('pin-pending', [('pin-success', N, {})], N, {}, 'pinned'), {'phase': 'pinned', 'value': ['other', 'n']})
check('domain state regression 3: pinned', solve('unpin-pending', [('unpin-success', N, {})], N, {'pinned': ['n', 'other']}, 'pinned'), {'phase': 'unpinned', 'value': ['other']})
check('domain state regression 4: retained', solve('pinned', [('notification-expires', N, {})], N, {'pinned': ['n']}, 'retained'), {'phase': 'expired-pinned', 'value': True})
check('domain state regression 5: pinned', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n', 'other'], 'expired': True}, 'pinned'), {'phase': 'gone', 'value': ['other']})
check('domain state regression 6: retained', solve('expired-pinned', [('unpin-expired', N, {})], N, {'pinned': ['n'], 'expired': True}, 'retained'), {'phase': 'gone', 'value': False})
check('domain state regression 7: pinned', solve('unpinned', [('pin-click', N, {}), ('pin-success', N, {}), ('notification-expires', N, {}), ('unpin-expired', N, {})], N, {}, 'pinned'), {'phase': 'gone', 'value': ['other']})
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 unpin-expired event leaves a notification in pinned instead of gone.

Inbox notification pin persistence is a bounded visual-notification workflow with mutable policy state {'pinned': ['other'], 'item': 'n', 'capacity': 3, 'expired': False, 'retained': True}. Its default transition relation is {('unpinned', 'pin-click'): 'pin-pending', ('pin-pending', 'pin-success'): 'pinned', ('pin-pending', 'pin-failure'): 'pin-error', ('pinned', 'unpin-click'): 'unpin-pending', ('unpin-pending', 'unpin-success'): 'unpinned', ('unpin-pending', 'unpin-failure'): 'unpin-error', ('pin-error', 'cancel-pin-intent'): 'unpinned', ('unpin-error', 'cancel-unpin-intent'): 'pinned', ('pinned', 'notification-expires'): 'expired-pinned', ('expired-pinned', 'unpin-expired'): 'gone'}; 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 = {('first-page', 'load-older'): 'end-of-history', ('loading-older', 'nonempty-page'): 'older-appended', ('loading-older', 'empty-page'): 'end-of-history', ('loading-older', 'page-failure'): 'older-error', ('older-error', 'retry-older'): 'loading-older', ('older-appended', 'new-head-arrives'): 'head-update-pending', ('head-update-pending', 'show-new-head'): 'head-restoring', ('head-restoring', 'head-anchor-ready'): 'first-page', ('loading-older', 'filter-changed'): 'new-filter-loading', ('new-filter-loading', 'old-page-arrives'): 'new-filter-loading'}
    data = json.loads(json.dumps({'rows': ['head'], 'filter': 2, 'anchor': 'head', 'has_more': True})) if payload is None else {**json.loads(json.dumps({'rows': ['head'], 'filter': 2, 'anchor': 'head', 'has_more': True})), **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 in ('nonempty-page','empty-page','old-page-arrives') and arg.get('filter',data['filter']) != data['filter']: event = 'unknown-event'
            if event == 'nonempty-page': data['rows'] += [x for x in arg.get('rows',['older']) if x not in data['rows']]
            if event == 'filter-changed': data['filter'] += 1
            state = table.get((state, event), state)
            if state == 'end-of-history': data['has_more'] = False
            if state == 'first-page': data['anchor'] = data['rows'][0] if data['rows'] else None
            if state == 'new-filter-loading': data['rows'] = []
    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('first-page / load-older', solve('first-page', [('load-older', N)], N), 'loading-older')
check('loading-older / nonempty-page', solve('loading-older', [('nonempty-page', N)], N), 'older-appended')
check('loading-older / empty-page', solve('loading-older', [('empty-page', N)], N), 'end-of-history')
check('loading-older / page-failure', solve('loading-older', [('page-failure', N)], N), 'older-error')
check('older-error / retry-older', solve('older-error', [('retry-older', N)], N), 'loading-older')
check('older-appended / new-head-arrives', solve('older-appended', [('new-head-arrives', N)], N), 'head-update-pending')
check('head-update-pending / show-new-head', solve('head-update-pending', [('show-new-head', N)], N), 'head-restoring')
check('head-restoring / head-anchor-ready', solve('head-restoring', [('head-anchor-ready', N)], N), 'first-page')
check('loading-older / filter-changed', solve('loading-older', [('filter-changed', N)], N), 'new-filter-loading')
check('new-filter-loading / old-page-arrives', solve('new-filter-loading', [('old-page-arrives', N)], N), 'new-filter-loading')
check('older notification incarnation', solve('first-page', [('load-older', N - 1)], N), 'first-page')
check('future notification incarnation', solve('first-page', [('load-older', N + 1)], N), 'first-page')
check('unknown event is inert', solve('first-page', [('unknown-event', N)], N), 'first-page')
check('empty delivery batch', solve('first-page', [], N), 'first-page')
check('N stale deliveries before current delivery', solve('first-page', [('load-older', N - 1)] * N + [('load-older', N)], N), 'loading-older')
check('trace load-older then nonempty-page', solve('first-page', [('load-older', N), ('nonempty-page', N)], N), 'older-appended')
check('trace load-older then empty-page', solve('first-page', [('load-older', N), ('empty-page', N)], N), 'end-of-history')
check('trace load-older then page-failure', solve('first-page', [('load-older', N), ('page-failure', N)], N), 'older-error')
check('trace load-older then filter-changed', solve('first-page', [('load-older', N), ('filter-changed', N)], N), 'new-filter-loading')
check('trace nonempty-page then new-head-arrives', solve('loading-older', [('nonempty-page', N), ('new-head-arrives', N)], N), 'head-update-pending')
check('trace page-failure then retry-older', solve('loading-older', [('page-failure', N), ('retry-older', N)], N), 'loading-older')
check('trace retry-older then nonempty-page', solve('older-error', [('retry-older', N), ('nonempty-page', N)], N), 'older-appended')
check('trace retry-older then empty-page', solve('older-error', [('retry-older', N), ('empty-page', N)], N), 'end-of-history')
check('trace retry-older then page-failure', solve('older-error', [('retry-older', N), ('page-failure', N)], N), 'older-error')
check('trace retry-older then filter-changed', solve('older-error', [('retry-older', N), ('filter-changed', N)], N), 'new-filter-loading')
check('trace new-head-arrives then show-new-head', solve('older-appended', [('new-head-arrives', N), ('show-new-head', N)], N), 'head-restoring')
check('trace show-new-head then head-anchor-ready', solve('head-update-pending', [('show-new-head', N), ('head-anchor-ready', N)], N), 'first-page')
check('trace head-anchor-ready then load-older', solve('head-restoring', [('head-anchor-ready', N), ('load-older', N)], N), 'loading-older')
check('trace filter-changed then old-page-arrives', solve('loading-older', [('filter-changed', N), ('old-page-arrives', N)], N), 'new-filter-loading')
check('trace old-page-arrives then old-page-arrives', solve('new-filter-loading', [('old-page-arrives', N), ('old-page-arrives', N)], N), 'new-filter-loading')
check('domain state regression 1: rows', solve('loading-older', [('nonempty-page', N, {'filter': 1, 'rows': ['stale']})], N, {}, 'rows'), {'phase': 'loading-older', 'value': ['head']})
check('domain state regression 2: rows', solve('loading-older', [('nonempty-page', N, {'rows': ['head', 'old']})], N, {}, 'rows'), {'phase': 'older-appended', 'value': ['head', 'old']})
check('domain state regression 3: has_more', solve('loading-older', [('empty-page', N, {})], N, {}, 'has_more'), {'phase': 'end-of-history', 'value': False})
check('domain state regression 4: rows', solve('loading-older', [('filter-changed', N, {})], N, {}, 'rows'), {'phase': 'new-filter-loading', 'value': []})
check('domain state regression 5: filter', solve('loading-older', [('filter-changed', N, {})], N, {}, 'filter'), {'phase': 'new-filter-loading', 'value': 3})
check('domain state regression 6: anchor', solve('older-appended', [('new-head-arrives', N, {})], N, {'anchor': 'old'}, 'anchor'), {'phase': 'head-update-pending', 'value': 'old'})
check('domain state regression 7: rows', solve('first-page', [('load-older', N, {}), ('filter-changed', N, {}), ('old-page-arrives', N, {'filter': 2, 'rows': ['old']})], N, {}, 'rows'), {'phase': 'new-filter-loading', 'value': []})
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 = {('first-page', 'load-older'): 'older-appended', ('loading-older', 'nonempty-page'): 'older-appended', ('loading-older', 'empty-page'): 'end-of-history', ('loading-older', 'page-failure'): 'older-error', ('older-error', 'retry-older'): 'loading-older', ('older-appended', 'new-head-arrives'): 'head-update-pending', ('head-update-pending', 'show-new-head'): 'head-restoring', ('head-restoring', 'head-anchor-ready'): 'first-page', ('loading-older', 'filter-changed'): 'new-filter-loading', ('new-filter-loading', 'old-page-arrives'): 'new-filter-loading'}
    data = json.loads(json.dumps({'rows': ['head'], 'filter': 2, 'anchor': 'head', 'has_more': True})) if payload is None else {**json.loads(json.dumps({'rows': ['head'], 'filter': 2, 'anchor': 'head', 'has_more': True})), **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 in ('nonempty-page','empty-page','old-page-arrives') and arg.get('filter',data['filter']) != data['filter']: event = 'unknown-event'
            if event == 'nonempty-page': data['rows'] += [x for x in arg.get('rows',['older']) if x not in data['rows']]
            if event == 'filter-changed': data['filter'] += 1
            state = table.get((state, event), state)
            if state == 'end-of-history': data['has_more'] = False
            if state == 'first-page': data['anchor'] = data['rows'][0] if data['rows'] else None
            if state == 'new-filter-loading': data['rows'] = []
    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('first-page / load-older', solve('first-page', [('load-older', N)], N), 'loading-older')
check('loading-older / nonempty-page', solve('loading-older', [('nonempty-page', N)], N), 'older-appended')
check('loading-older / empty-page', solve('loading-older', [('empty-page', N)], N), 'end-of-history')
check('loading-older / page-failure', solve('loading-older', [('page-failure', N)], N), 'older-error')
check('older-error / retry-older', solve('older-error', [('retry-older', N)], N), 'loading-older')
check('older-appended / new-head-arrives', solve('older-appended', [('new-head-arrives', N)], N), 'head-update-pending')
check('head-update-pending / show-new-head', solve('head-update-pending', [('show-new-head', N)], N), 'head-restoring')
check('head-restoring / head-anchor-ready', solve('head-restoring', [('head-anchor-ready', N)], N), 'first-page')
check('loading-older / filter-changed', solve('loading-older', [('filter-changed', N)], N), 'new-filter-loading')
check('new-filter-loading / old-page-arrives', solve('new-filter-loading', [('old-page-arrives', N)], N), 'new-filter-loading')
check('older notification incarnation', solve('first-page', [('load-older', N - 1)], N), 'first-page')
check('future notification incarnation', solve('first-page', [('load-older', N + 1)], N), 'first-page')
check('unknown event is inert', solve('first-page', [('unknown-event', N)], N), 'first-page')
check('empty delivery batch', solve('first-page', [], N), 'first-page')
check('N stale deliveries before current delivery', solve('first-page', [('load-older', N - 1)] * N + [('load-older', N)], N), 'loading-older')
check('trace load-older then nonempty-page', solve('first-page', [('load-older', N), ('nonempty-page', N)], N), 'older-appended')
check('trace load-older then empty-page', solve('first-page', [('load-older', N), ('empty-page', N)], N), 'end-of-history')
check('trace load-older then page-failure', solve('first-page', [('load-older', N), ('page-failure', N)], N), 'older-error')
check('trace load-older then filter-changed', solve('first-page', [('load-older', N), ('filter-changed', N)], N), 'new-filter-loading')
check('trace nonempty-page then new-head-arrives', solve('loading-older', [('nonempty-page', N), ('new-head-arrives', N)], N), 'head-update-pending')
check('trace page-failure then retry-older', solve('loading-older', [('page-failure', N), ('retry-older', N)], N), 'loading-older')
check('trace retry-older then nonempty-page', solve('older-error', [('retry-older', N), ('nonempty-page', N)], N), 'older-appended')
check('trace retry-older then empty-page', solve('older-error', [('retry-older', N), ('empty-page', N)], N), 'end-of-history')
check('trace retry-older then page-failure', solve('older-error', [('retry-older', N), ('page-failure', N)], N), 'older-error')
check('trace retry-older then filter-changed', solve('older-error', [('retry-older', N), ('filter-changed', N)], N), 'new-filter-loading')
check('trace new-head-arrives then show-new-head', solve('older-appended', [('new-head-arrives', N), ('show-new-head', N)], N), 'head-restoring')
check('trace show-new-head then head-anchor-ready', solve('head-update-pending', [('show-new-head', N), ('head-anchor-ready', N)], N), 'first-page')
check('trace head-anchor-ready then load-older', solve('head-restoring', [('head-anchor-ready', N), ('load-older', N)], N), 'loading-older')
check('trace filter-changed then old-page-arrives', solve('loading-older', [('filter-changed', N), ('old-page-arrives', N)], N), 'new-filter-loading')
check('trace old-page-arrives then old-page-arrives', solve('new-filter-loading', [('old-page-arrives', N), ('old-page-arrives', N)], N), 'new-filter-loading')
check('domain state regression 1: rows', solve('loading-older', [('nonempty-page', N, {'filter': 1, 'rows': ['stale']})], N, {}, 'rows'), {'phase': 'loading-older', 'value': ['head']})
check('domain state regression 2: rows', solve('loading-older', [('nonempty-page', N, {'rows': ['head', 'old']})], N, {}, 'rows'), {'phase': 'older-appended', 'value': ['head', 'old']})
check('domain state regression 3: has_more', solve('loading-older', [('empty-page', N, {})], N, {}, 'has_more'), {'phase': 'end-of-history', 'value': False})
check('domain state regression 4: rows', solve('loading-older', [('filter-changed', N, {})], N, {}, 'rows'), {'phase': 'new-filter-loading', 'value': []})
check('domain state regression 5: filter', solve('loading-older', [('filter-changed', N, {})], N, {}, 'filter'), {'phase': 'new-filter-loading', 'value': 3})
check('domain state regression 6: anchor', solve('older-appended', [('new-head-arrives', N, {})], N, {'anchor': 'old'}, 'anchor'), {'phase': 'head-update-pending', 'value': 'old'})
check('domain state regression 7: rows', solve('first-page', [('load-older', N, {}), ('filter-changed', N, {}), ('old-page-arrives', N, {'filter': 2, 'rows': ['old']})], N, {}, 'rows'), {'phase': 'new-filter-loading', 'value': []})
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 load-older event leaves a notification in end-of-history instead of loading-older.

Inbox history pagination presentation is a bounded visual-notification workflow with mutable policy state {'rows': ['head'], 'filter': 2, 'anchor': 'head', 'has_more': True}. Its default transition relation is {('first-page', 'load-older'): 'loading-older', ('loading-older', 'nonempty-page'): 'older-appended', ('loading-older', 'empty-page'): 'end-of-history', ('loading-older', 'page-failure'): 'older-error', ('older-error', 'retry-older'): 'loading-older', ('older-appended', 'new-head-arrives'): 'head-update-pending', ('head-update-pending', 'show-new-head'): 'head-restoring', ('head-restoring', 'head-anchor-ready'): 'first-page', ('loading-older', 'filter-changed'): 'new-filter-loading', ('new-filter-loading', 'old-page-arrives'): 'new-filter-loading'}; 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