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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'offline-cached', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'empty', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 snapshot-current event leaves a notification in offline-cached instead of live.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'live', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'empty', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 snapshot-failed event leaves a notification in live instead of offline-error.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'live', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'offline-cached', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 retry-refresh event leaves a notification in live instead of reconciling.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'live', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'empty', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 connection-lost event leaves a notification in live instead of offline-cached.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'live', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'loading', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 open-cached-item event leaves a notification in live instead of offline-preview.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'live', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 = {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'empty', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}
    data = json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})) if payload is None else {**json.loads(json.dumps({'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False})), **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 == 'snapshot-current':
                if arg.get('cursor',data['cursor']) < data['cursor']: event = 'unknown-event'
                else:
                    data['cursor'] = arg.get('cursor',data['cursor'])
                    data['cached'] = arg.get('items',data['cached'])[:]
            if event == 'connection-lost': data['fresh'] = False
            state = table.get((state, event), state)
            if state in ('live','live-preview'): data['fresh'] = True
            if state == 'live-preview' and data['preview'] not in data['cached']: data['preview'] = None
            if state == 'empty': data['cached'] = []
    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('live / connection-lost', solve('live', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / connection-restored', solve('offline-cached', [('connection-restored', N)], N), 'reconciling')
check('reconciling / snapshot-current', solve('reconciling', [('snapshot-current', N)], N), 'live')
check('reconciling / snapshot-failed', solve('reconciling', [('snapshot-failed', N)], N), 'offline-error')
check('offline-error / retry-refresh', solve('offline-error', [('retry-refresh', N)], N), 'reconciling')
check('reconciling / connection-lost', solve('reconciling', [('connection-lost', N)], N), 'offline-cached')
check('offline-cached / open-cached-item', solve('offline-cached', [('open-cached-item', N)], N), 'offline-preview')
check('offline-preview / close-preview', solve('offline-preview', [('close-preview', N)], N), 'offline-cached')
check('offline-preview / connection-restored', solve('offline-preview', [('connection-restored', N)], N), 'reconciling-preview')
check('reconciling-preview / snapshot-current', solve('reconciling-preview', [('snapshot-current', N)], N), 'live-preview')
check('older notification incarnation', solve('live', [('connection-lost', N - 1)], N), 'live')
check('future notification incarnation', solve('live', [('connection-lost', N + 1)], N), 'live')
check('unknown event is inert', solve('live', [('unknown-event', N)], N), 'live')
check('empty delivery batch', solve('live', [], N), 'live')
check('N stale deliveries before current delivery', solve('live', [('connection-lost', N - 1)] * N + [('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('live', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('live', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-cached', [('connection-restored', N), ('snapshot-current', N)], N), 'live')
check('trace connection-restored then snapshot-failed', solve('offline-cached', [('connection-restored', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace connection-restored then connection-lost', solve('offline-cached', [('connection-restored', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-current then connection-lost', solve('reconciling', [('snapshot-current', N), ('connection-lost', N)], N), 'offline-cached')
check('trace snapshot-failed then retry-refresh', solve('reconciling', [('snapshot-failed', N), ('retry-refresh', N)], N), 'reconciling')
check('trace retry-refresh then snapshot-current', solve('offline-error', [('retry-refresh', N), ('snapshot-current', N)], N), 'live')
check('trace retry-refresh then snapshot-failed', solve('offline-error', [('retry-refresh', N), ('snapshot-failed', N)], N), 'offline-error')
check('trace retry-refresh then connection-lost', solve('offline-error', [('retry-refresh', N), ('connection-lost', N)], N), 'offline-cached')
check('trace connection-lost then connection-restored', solve('reconciling', [('connection-lost', N), ('connection-restored', N)], N), 'reconciling')
check('trace connection-lost then open-cached-item', solve('reconciling', [('connection-lost', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace open-cached-item then close-preview', solve('offline-cached', [('open-cached-item', N), ('close-preview', N)], N), 'offline-cached')
check('trace open-cached-item then connection-restored', solve('offline-cached', [('open-cached-item', N), ('connection-restored', N)], N), 'reconciling-preview')
check('trace close-preview then connection-restored', solve('offline-preview', [('close-preview', N), ('connection-restored', N)], N), 'reconciling')
check('trace close-preview then open-cached-item', solve('offline-preview', [('close-preview', N), ('open-cached-item', N)], N), 'offline-preview')
check('trace connection-restored then snapshot-current', solve('offline-preview', [('connection-restored', N), ('snapshot-current', N)], N), 'live-preview')
check('domain state regression 1: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 7, 'items': ['stale']})], N, {}, 'cached'), {'phase': 'reconciling', 'value': ['old']})
check('domain state regression 2: cached', solve('reconciling', [('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'cached'), {'phase': 'live', 'value': ['new']})
check('domain state regression 3: cached', solve('live', [('connection-lost', N, {})], N, {'fresh': True}, 'cached'), {'phase': 'offline-cached', 'value': ['old']})
check('domain state regression 4: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
check('domain state regression 5: preview', solve('reconciling-preview', [('snapshot-current', N, {'items': ['old', 'new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': 'old'})
check('domain state regression 6: fresh', solve('reconciling', [('snapshot-failed', N, {})], N, {}, 'fresh'), {'phase': 'offline-error', 'value': False})
check('domain state regression 7: preview', solve('offline-preview', [('connection-restored', N, {}), ('snapshot-current', N, {'cursor': 9, 'items': ['new']})], N, {}, 'preview'), {'phase': 'live-preview', 'value': None})
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 close-preview event leaves a notification in live instead of offline-cached.

Notification inbox reconnect recovery is a bounded visual-notification workflow with mutable policy state {'cached': ['old'], 'cursor': 8, 'preview': 'old', 'fresh': False}. Its default transition relation is {('live', 'connection-lost'): 'offline-cached', ('offline-cached', 'connection-restored'): 'reconciling', ('reconciling', 'snapshot-current'): 'live', ('reconciling', 'snapshot-failed'): 'offline-error', ('offline-error', 'retry-refresh'): 'reconciling', ('reconciling', 'connection-lost'): 'offline-cached', ('offline-cached', 'open-cached-item'): 'offline-preview', ('offline-preview', 'close-preview'): 'offline-cached', ('offline-preview', 'connection-restored'): 'reconciling-preview', ('reconciling-preview', 'snapshot-current'): 'live-preview'}; 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