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 = {('offered', 'destructive-click'): 'confirming', ('confirming', 'confirm-accept'): 'executing', ('confirming', 'confirm-cancel'): 'offered', ('executing', 'command-success'): 'succeeded', ('executing', 'command-failure'): 'failed', ('failed', 'retry-click'): 'confirming-retry', ('confirming-retry', 'retry-confirm-accept'): 'executing', ('confirming', 'notification-withdrawn'): 'confirmation-invalidated', ('confirmation-invalidated', 'late-confirm-accept'): 'withdrawn', ('executing', 'notification-withdrawn'): 'withdrawn'}
    data = json.loads(json.dumps({'revision': 2, 'consented': None, 'submitted': [], 'withdrawn': False})) if payload is None else {**json.loads(json.dumps({'revision': 2, 'consented': None, 'submitted': [], 'withdrawn': 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 in ('confirm-accept','retry-confirm-accept'):
                if data['withdrawn'] or arg.get('revision',data['revision']) != data['revision']: event = 'confirm-cancel'
                else: data['consented'] = data['revision']
            if event == 'notification-withdrawn': data['withdrawn'] = True
            state = table.get((state, event), state)
            if state == 'executing' and previous != 'executing': data['submitted'].append(data['revision'])
            if state == 'offered': data['consented'] = None
    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('offered / destructive-click', solve('offered', [('destructive-click', N)], N), 'confirming')
check('confirming / confirm-accept', solve('confirming', [('confirm-accept', N)], N), 'executing')
check('confirming / confirm-cancel', solve('confirming', [('confirm-cancel', N)], N), 'offered')
check('executing / command-success', solve('executing', [('command-success', N)], N), 'succeeded')
check('executing / command-failure', solve('executing', [('command-failure', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'confirming-retry')
check('confirming-retry / retry-confirm-accept', solve('confirming-retry', [('retry-confirm-accept', N)], N), 'executing')
check('confirming / notification-withdrawn', solve('confirming', [('notification-withdrawn', N)], N), 'confirmation-invalidated')
check('confirmation-invalidated / late-confirm-accept', solve('confirmation-invalidated', [('late-confirm-accept', N)], N), 'withdrawn')
check('executing / notification-withdrawn', solve('executing', [('notification-withdrawn', N)], N), 'executing-withdrawn')
check('older notification incarnation', solve('offered', [('destructive-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('destructive-click', N + 1)], N), 'offered')
check('unknown event is inert', solve('offered', [('unknown-event', N)], N), 'offered')
check('empty delivery batch', solve('offered', [], N), 'offered')
check('N stale deliveries before current delivery', solve('offered', [('destructive-click', N - 1)] * N + [('destructive-click', N)], N), 'confirming')
check('trace destructive-click then confirm-accept', solve('offered', [('destructive-click', N), ('confirm-accept', N)], N), 'executing')
check('trace destructive-click then confirm-cancel', solve('offered', [('destructive-click', N), ('confirm-cancel', N)], N), 'offered')
check('trace destructive-click then notification-withdrawn', solve('offered', [('destructive-click', N), ('notification-withdrawn', N)], N), 'confirmation-invalidated')
check('trace confirm-accept then command-success', solve('confirming', [('confirm-accept', N), ('command-success', N)], N), 'succeeded')
check('trace confirm-accept then command-failure', solve('confirming', [('confirm-accept', N), ('command-failure', N)], N), 'failed')
check('trace confirm-accept then notification-withdrawn', solve('confirming', [('confirm-accept', N), ('notification-withdrawn', N)], N), 'executing-withdrawn')
check('trace confirm-cancel then destructive-click', solve('confirming', [('confirm-cancel', N), ('destructive-click', N)], N), 'confirming')
check('trace command-failure then retry-click', solve('executing', [('command-failure', N), ('retry-click', N)], N), 'confirming-retry')
check('trace retry-click then retry-confirm-accept', solve('failed', [('retry-click', N), ('retry-confirm-accept', N)], N), 'executing')
check('trace retry-confirm-accept then command-success', solve('confirming-retry', [('retry-confirm-accept', N), ('command-success', N)], N), 'succeeded')
check('trace retry-confirm-accept then command-failure', solve('confirming-retry', [('retry-confirm-accept', N), ('command-failure', N)], N), 'failed')
check('trace retry-confirm-accept then notification-withdrawn', solve('confirming-retry', [('retry-confirm-accept', N), ('notification-withdrawn', N)], N), 'executing-withdrawn')
check('trace notification-withdrawn then late-confirm-accept', solve('confirming', [('notification-withdrawn', N), ('late-confirm-accept', N)], N), 'withdrawn')
check('domain state regression 1: submitted', solve('confirming', [('confirm-accept', N, {'revision': 1})], N, {}, 'submitted'), {'phase': 'offered', 'value': []})
check('domain state regression 2: submitted', solve('confirming', [('confirm-accept', N, {'revision': 2})], N, {}, 'submitted'), {'phase': 'executing', 'value': [2]})
check('domain state regression 3: submitted', solve('confirming', [('confirm-accept', N, {})], N, {'withdrawn': True}, 'submitted'), {'phase': 'offered', 'value': []})
check('domain state regression 4: consented', solve('confirming', [('confirm-cancel', N, {})], N, {'consented': 2}, 'consented'), {'phase': 'offered', 'value': None})
check('domain state regression 5: submitted', solve('executing', [('notification-withdrawn', N, {})], N, {'submitted': [2]}, 'submitted'), {'phase': 'executing-withdrawn', 'value': [2]})
check('domain state regression 6: submitted', solve('confirmation-invalidated', [('late-confirm-accept', N, {})], N, {'withdrawn': True}, 'submitted'), {'phase': 'withdrawn', 'value': []})
check('domain state regression 7: submitted', solve('offered', [('destructive-click', N, {}), ('notification-withdrawn', N, {}), ('late-confirm-accept', N, {})], N, {}, 'submitted'), {'phase': 'withdrawn', 'value': []})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(initial, events, generation, payload=None, observe=None):
    table = {('offered', 'destructive-click'): 'confirming', ('confirming', 'confirm-accept'): 'executing', ('confirming', 'confirm-cancel'): 'offered', ('executing', 'command-success'): 'succeeded', ('executing', 'command-failure'): 'failed', ('failed', 'retry-click'): 'confirming-retry', ('confirming-retry', 'retry-confirm-accept'): 'executing', ('confirming', 'notification-withdrawn'): 'confirmation-invalidated', ('confirmation-invalidated', 'late-confirm-accept'): 'withdrawn', ('executing', 'notification-withdrawn'): 'succeeded'}
    data = json.loads(json.dumps({'revision': 2, 'consented': None, 'submitted': [], 'withdrawn': False})) if payload is None else {**json.loads(json.dumps({'revision': 2, 'consented': None, 'submitted': [], 'withdrawn': 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 in ('confirm-accept','retry-confirm-accept'):
                if data['withdrawn'] or arg.get('revision',data['revision']) != data['revision']: event = 'confirm-cancel'
                else: data['consented'] = data['revision']
            if event == 'notification-withdrawn': data['withdrawn'] = True
            state = table.get((state, event), state)
            if state == 'executing' and previous != 'executing': data['submitted'].append(data['revision'])
            if state == 'offered': data['consented'] = None
    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('offered / destructive-click', solve('offered', [('destructive-click', N)], N), 'confirming')
check('confirming / confirm-accept', solve('confirming', [('confirm-accept', N)], N), 'executing')
check('confirming / confirm-cancel', solve('confirming', [('confirm-cancel', N)], N), 'offered')
check('executing / command-success', solve('executing', [('command-success', N)], N), 'succeeded')
check('executing / command-failure', solve('executing', [('command-failure', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'confirming-retry')
check('confirming-retry / retry-confirm-accept', solve('confirming-retry', [('retry-confirm-accept', N)], N), 'executing')
check('confirming / notification-withdrawn', solve('confirming', [('notification-withdrawn', N)], N), 'confirmation-invalidated')
check('confirmation-invalidated / late-confirm-accept', solve('confirmation-invalidated', [('late-confirm-accept', N)], N), 'withdrawn')
check('executing / notification-withdrawn', solve('executing', [('notification-withdrawn', N)], N), 'executing-withdrawn')
check('older notification incarnation', solve('offered', [('destructive-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('destructive-click', N + 1)], N), 'offered')
check('unknown event is inert', solve('offered', [('unknown-event', N)], N), 'offered')
check('empty delivery batch', solve('offered', [], N), 'offered')
check('N stale deliveries before current delivery', solve('offered', [('destructive-click', N - 1)] * N + [('destructive-click', N)], N), 'confirming')
check('trace destructive-click then confirm-accept', solve('offered', [('destructive-click', N), ('confirm-accept', N)], N), 'executing')
check('trace destructive-click then confirm-cancel', solve('offered', [('destructive-click', N), ('confirm-cancel', N)], N), 'offered')
check('trace destructive-click then notification-withdrawn', solve('offered', [('destructive-click', N), ('notification-withdrawn', N)], N), 'confirmation-invalidated')
check('trace confirm-accept then command-success', solve('confirming', [('confirm-accept', N), ('command-success', N)], N), 'succeeded')
check('trace confirm-accept then command-failure', solve('confirming', [('confirm-accept', N), ('command-failure', N)], N), 'failed')
check('trace confirm-accept then notification-withdrawn', solve('confirming', [('confirm-accept', N), ('notification-withdrawn', N)], N), 'executing-withdrawn')
check('trace confirm-cancel then destructive-click', solve('confirming', [('confirm-cancel', N), ('destructive-click', N)], N), 'confirming')
check('trace command-failure then retry-click', solve('executing', [('command-failure', N), ('retry-click', N)], N), 'confirming-retry')
check('trace retry-click then retry-confirm-accept', solve('failed', [('retry-click', N), ('retry-confirm-accept', N)], N), 'executing')
check('trace retry-confirm-accept then command-success', solve('confirming-retry', [('retry-confirm-accept', N), ('command-success', N)], N), 'succeeded')
check('trace retry-confirm-accept then command-failure', solve('confirming-retry', [('retry-confirm-accept', N), ('command-failure', N)], N), 'failed')
check('trace retry-confirm-accept then notification-withdrawn', solve('confirming-retry', [('retry-confirm-accept', N), ('notification-withdrawn', N)], N), 'executing-withdrawn')
check('trace notification-withdrawn then late-confirm-accept', solve('confirming', [('notification-withdrawn', N), ('late-confirm-accept', N)], N), 'withdrawn')
check('domain state regression 1: submitted', solve('confirming', [('confirm-accept', N, {'revision': 1})], N, {}, 'submitted'), {'phase': 'offered', 'value': []})
check('domain state regression 2: submitted', solve('confirming', [('confirm-accept', N, {'revision': 2})], N, {}, 'submitted'), {'phase': 'executing', 'value': [2]})
check('domain state regression 3: submitted', solve('confirming', [('confirm-accept', N, {})], N, {'withdrawn': True}, 'submitted'), {'phase': 'offered', 'value': []})
check('domain state regression 4: consented', solve('confirming', [('confirm-cancel', N, {})], N, {'consented': 2}, 'consented'), {'phase': 'offered', 'value': None})
check('domain state regression 5: submitted', solve('executing', [('notification-withdrawn', N, {})], N, {'submitted': [2]}, 'submitted'), {'phase': 'executing-withdrawn', 'value': [2]})
check('domain state regression 6: submitted', solve('confirmation-invalidated', [('late-confirm-accept', N, {})], N, {'withdrawn': True}, 'submitted'), {'phase': 'withdrawn', 'value': []})
check('domain state regression 7: submitted', solve('offered', [('destructive-click', N, {}), ('notification-withdrawn', N, {}), ('late-confirm-accept', N, {})], N, {}, 'submitted'), {'phase': 'withdrawn', 'value': []})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The notification-withdrawn event leaves a notification in withdrawn instead of executing-withdrawn.

Notification destructive-action confirmation is a bounded visual-notification workflow with mutable policy state {'revision': 2, 'consented': None, 'submitted': [], 'withdrawn': False}. Its default transition relation is {('offered', 'destructive-click'): 'confirming', ('confirming', 'confirm-accept'): 'executing', ('confirming', 'confirm-cancel'): 'offered', ('executing', 'command-success'): 'succeeded', ('executing', 'command-failure'): 'failed', ('failed', 'retry-click'): 'confirming-retry', ('confirming-retry', 'retry-confirm-accept'): 'executing', ('confirming', 'notification-withdrawn'): 'confirmation-invalidated', ('confirmation-invalidated', 'late-confirm-accept'): 'withdrawn', ('executing', 'notification-withdrawn'): 'executing-withdrawn'}; 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 = {('local-visible', 'send-to-other-surface'): 'remote-visible', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 = {('local-visible', 'send-to-other-surface'): 'local-hidden', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 send-to-other-surface event leaves a notification in remote-visible instead of handoff-pending.

Notification handoff to another surface is a bounded visual-notification workflow with mutable policy state {'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'}. Its default transition relation is {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}; 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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-visible', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'local-hidden', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 remote-accepted event leaves a notification in remote-visible instead of remote-mounting.

Notification handoff to another surface is a bounded visual-notification workflow with mutable policy state {'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'}. Its default transition relation is {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}; 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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'local-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'handoff-error', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 remote-painted event leaves a notification in local-visible instead of remote-visible.

Notification handoff to another surface is a bounded visual-notification workflow with mutable policy state {'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'}. Its default transition relation is {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}; 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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'remote-visible', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'local-hidden', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 remote-paint-failed event leaves a notification in remote-visible instead of handoff-error.

Notification handoff to another surface is a bounded visual-notification workflow with mutable policy state {'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'}. Its default transition relation is {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}; 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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'remote-visible', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 = {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'local-hidden', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}
    data = json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})) if payload is None else {**json.loads(json.dumps({'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('remote-accepted','remote-painted','remote-released','remote-rejected','remote-paint-failed'):
                if arg.get('transfer',data['transfer']) != data['transfer'] or arg.get('owner',data['remote_owner']) != data['remote_owner']: event = 'unknown-event'
            if event == 'remote-painted': data['remote'] = True
            if event == 'remote-released': data['remote'] = False
            state = table.get((state, event), state)
            if state == 'remote-visible': data['local'] = False
            if state in ('local-visible','handoff-error'): data['local'] = True
            if state == 'local-hidden': data['local'] = False
    return {'phase': state, 'value': data[observe]} if observe else state
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('local-visible / send-to-other-surface', solve('local-visible', [('send-to-other-surface', N)], N), 'handoff-pending')
check('handoff-pending / remote-accepted', solve('handoff-pending', [('remote-accepted', N)], N), 'remote-mounting')
check('remote-mounting / remote-painted', solve('remote-mounting', [('remote-painted', N)], N), 'remote-visible')
check('remote-mounting / remote-paint-failed', solve('remote-mounting', [('remote-paint-failed', N)], N), 'handoff-error')
check('handoff-pending / remote-rejected', solve('handoff-pending', [('remote-rejected', N)], N), 'handoff-error')
check('handoff-error / retry-handoff', solve('handoff-error', [('retry-handoff', N)], N), 'handoff-pending')
check('remote-visible / bring-back', solve('remote-visible', [('bring-back', N)], N), 'recall-pending')
check('recall-pending / remote-released', solve('recall-pending', [('remote-released', N)], N), 'local-remounting')
check('local-remounting / local-painted', solve('local-remounting', [('local-painted', N)], N), 'local-visible')
check('handoff-pending / cancel-handoff', solve('handoff-pending', [('cancel-handoff', N)], N), 'cancel-pending')
check('older notification incarnation', solve('local-visible', [('send-to-other-surface', N - 1)], N), 'local-visible')
check('future notification incarnation', solve('local-visible', [('send-to-other-surface', N + 1)], N), 'local-visible')
check('unknown event is inert', solve('local-visible', [('unknown-event', N)], N), 'local-visible')
check('empty delivery batch', solve('local-visible', [], N), 'local-visible')
check('N stale deliveries before current delivery', solve('local-visible', [('send-to-other-surface', N - 1)] * N + [('send-to-other-surface', N)], N), 'handoff-pending')
check('trace send-to-other-surface then remote-accepted', solve('local-visible', [('send-to-other-surface', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace send-to-other-surface then remote-rejected', solve('local-visible', [('send-to-other-surface', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace send-to-other-surface then cancel-handoff', solve('local-visible', [('send-to-other-surface', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace remote-accepted then remote-painted', solve('handoff-pending', [('remote-accepted', N), ('remote-painted', N)], N), 'remote-visible')
check('trace remote-accepted then remote-paint-failed', solve('handoff-pending', [('remote-accepted', N), ('remote-paint-failed', N)], N), 'handoff-error')
check('trace remote-painted then bring-back', solve('remote-mounting', [('remote-painted', N), ('bring-back', N)], N), 'recall-pending')
check('trace remote-paint-failed then retry-handoff', solve('remote-mounting', [('remote-paint-failed', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace remote-rejected then retry-handoff', solve('handoff-pending', [('remote-rejected', N), ('retry-handoff', N)], N), 'handoff-pending')
check('trace retry-handoff then remote-accepted', solve('handoff-error', [('retry-handoff', N), ('remote-accepted', N)], N), 'remote-mounting')
check('trace retry-handoff then remote-rejected', solve('handoff-error', [('retry-handoff', N), ('remote-rejected', N)], N), 'handoff-error')
check('trace retry-handoff then cancel-handoff', solve('handoff-error', [('retry-handoff', N), ('cancel-handoff', N)], N), 'cancel-pending')
check('trace bring-back then remote-released', solve('remote-visible', [('bring-back', N), ('remote-released', N)], N), 'local-remounting')
check('trace remote-released then local-painted', solve('recall-pending', [('remote-released', N), ('local-painted', N)], N), 'local-visible')
check('trace local-painted then send-to-other-surface', solve('local-remounting', [('local-painted', N), ('send-to-other-surface', N)], N), 'handoff-pending')
check('domain state regression 1: local', solve('handoff-pending', [('remote-accepted', N, {'transfer': 3})], N, {}, 'local'), {'phase': 'handoff-pending', 'value': True})
check('domain state regression 2: remote', solve('remote-mounting', [('remote-painted', N, {'owner': 'phone'})], N, {}, 'remote'), {'phase': 'remote-mounting', 'value': False})
check('domain state regression 3: local', solve('remote-mounting', [('remote-painted', N, {})], N, {}, 'local'), {'phase': 'remote-visible', 'value': False})
check('domain state regression 4: local', solve('remote-mounting', [('remote-paint-failed', N, {})], N, {}, 'local'), {'phase': 'handoff-error', 'value': True})
check('domain state regression 5: remote', solve('recall-pending', [('remote-released', N, {})], N, {'local': False, 'remote': True}, 'remote'), {'phase': 'local-remounting', 'value': False})
check('domain state regression 6: local', solve('local-remounting', [('local-painted', N, {})], N, {'local': False, 'remote': False}, 'local'), {'phase': 'local-visible', 'value': True})
check('domain state regression 7: remote', solve('local-visible', [('send-to-other-surface', N, {}), ('remote-accepted', N, {}), ('remote-painted', N, {}), ('bring-back', N, {}), ('remote-released', N, {}), ('local-painted', N, {})], N, {}, 'remote'), {'phase': 'local-visible', 'value': False})
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 remote-rejected event leaves a notification in remote-visible instead of handoff-error.

Notification handoff to another surface is a bounded visual-notification workflow with mutable policy state {'transfer': 4, 'local': True, 'remote': False, 'remote_owner': 'tablet'}. Its default transition relation is {('local-visible', 'send-to-other-surface'): 'handoff-pending', ('handoff-pending', 'remote-accepted'): 'remote-mounting', ('remote-mounting', 'remote-painted'): 'remote-visible', ('remote-mounting', 'remote-paint-failed'): 'handoff-error', ('handoff-pending', 'remote-rejected'): 'handoff-error', ('handoff-error', 'retry-handoff'): 'handoff-pending', ('remote-visible', 'bring-back'): 'recall-pending', ('recall-pending', 'remote-released'): 'local-remounting', ('local-remounting', 'local-painted'): 'local-visible', ('handoff-pending', 'cancel-handoff'): 'cancel-pending'}; 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