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', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'offered', ('retry-offered', 'dismiss-error'): 'committed'}
    data = json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})) if payload is None else {**json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            data['now'] = max(data['now'], arg.get('now', data['now']))
            if event in ('undo-click', 'retry-click'):
                if data['now'] >= data['deadline']: event = 'window-end'
                else: data['requests'] += 1
            if event == 'window-end' and data['now'] < data['deadline'] and 'now' in arg: event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'restored': data['applied'] = False
            if state == 'committed': data['applied'] = True
    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 / undo-click', solve('offered', [('undo-click', N)], N), 'undo-pending')
check('undo-pending / undo-success', solve('undo-pending', [('undo-success', N)], N), 'restored')
check('undo-pending / undo-failure', solve('undo-pending', [('undo-failure', N)], N), 'retry-offered')
check('offered / window-end', solve('offered', [('window-end', N)], N), 'committed')
check('undo-pending / window-end', solve('undo-pending', [('window-end', N)], N), 'undo-pending')
check('retry-offered / retry-click', solve('retry-offered', [('retry-click', N)], N), 'undo-pending')
check('restored / late-window-end', solve('restored', [('late-window-end', N)], N), 'restored')
check('committed / late-undo-click', solve('committed', [('late-undo-click', N)], N), 'too-late')
check('too-late / acknowledge', solve('too-late', [('acknowledge', N)], N), 'closed')
check('retry-offered / dismiss-error', solve('retry-offered', [('dismiss-error', N)], N), 'committed')
check('older notification incarnation', solve('offered', [('undo-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('undo-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', [('undo-click', N - 1)] * N + [('undo-click', N)], N), 'undo-pending')
check('trace undo-click then undo-success', solve('offered', [('undo-click', N), ('undo-success', N)], N), 'restored')
check('trace undo-click then undo-failure', solve('offered', [('undo-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace undo-click then window-end', solve('offered', [('undo-click', N), ('window-end', N)], N), 'undo-pending')
check('trace undo-success then late-window-end', solve('undo-pending', [('undo-success', N), ('late-window-end', N)], N), 'restored')
check('trace undo-failure then retry-click', solve('undo-pending', [('undo-failure', N), ('retry-click', N)], N), 'undo-pending')
check('trace undo-failure then dismiss-error', solve('undo-pending', [('undo-failure', N), ('dismiss-error', N)], N), 'committed')
check('trace window-end then late-undo-click', solve('offered', [('window-end', N), ('late-undo-click', N)], N), 'too-late')
check('trace window-end then undo-success', solve('undo-pending', [('window-end', N), ('undo-success', N)], N), 'restored')
check('trace window-end then undo-failure', solve('undo-pending', [('window-end', N), ('undo-failure', N)], N), 'retry-offered')
check('trace window-end then window-end', solve('undo-pending', [('window-end', N), ('window-end', N)], N), 'undo-pending')
check('trace retry-click then undo-success', solve('retry-offered', [('retry-click', N), ('undo-success', N)], N), 'restored')
check('trace retry-click then undo-failure', solve('retry-offered', [('retry-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace retry-click then window-end', solve('retry-offered', [('retry-click', N), ('window-end', N)], N), 'undo-pending')
check('trace late-window-end then late-window-end', solve('restored', [('late-window-end', N), ('late-window-end', N)], N), 'restored')
check('trace late-undo-click then acknowledge', solve('committed', [('late-undo-click', N), ('acknowledge', N)], N), 'closed')
check('trace dismiss-error then late-undo-click', solve('retry-offered', [('dismiss-error', N), ('late-undo-click', N)], N), 'too-late')
check('domain state regression 1: requests', solve('offered', [('undo-click', N, {'now': 19})], N, {}, 'requests'), {'phase': 'undo-pending', 'value': 1})
check('domain state regression 2: requests', solve('offered', [('undo-click', N, {'now': 20})], N, {}, 'requests'), {'phase': 'committed', 'value': 0})
check('domain state regression 3: applied', solve('offered', [('window-end', N, {'now': 19})], N, {}, 'applied'), {'phase': 'offered', 'value': True})
check('domain state regression 4: applied', solve('undo-pending', [('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', 'value': False})
check('domain state regression 5: requests', solve('retry-offered', [('retry-click', N, {'now': 8})], N, {'requests': 1}, 'requests'), {'phase': 'undo-pending', 'value': 2})
check('domain state regression 6: now', solve('offered', [('undo-click', N, {'now': 2})], N, {}, 'now'), {'phase': 'undo-pending', 'value': 5})
check('domain state regression 7: applied', solve('offered', [('undo-click', N, {'now': 19}), ('window-end', N, {'now': 20}), ('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', '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 = {('offered', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'undo-pending', ('retry-offered', 'dismiss-error'): 'committed'}
    data = json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})) if payload is None else {**json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            data['now'] = max(data['now'], arg.get('now', data['now']))
            if event in ('undo-click', 'retry-click'):
                if data['now'] >= data['deadline']: event = 'window-end'
                else: data['requests'] += 1
            if event == 'window-end' and data['now'] < data['deadline'] and 'now' in arg: event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'restored': data['applied'] = False
            if state == 'committed': data['applied'] = True
    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 / undo-click', solve('offered', [('undo-click', N)], N), 'undo-pending')
check('undo-pending / undo-success', solve('undo-pending', [('undo-success', N)], N), 'restored')
check('undo-pending / undo-failure', solve('undo-pending', [('undo-failure', N)], N), 'retry-offered')
check('offered / window-end', solve('offered', [('window-end', N)], N), 'committed')
check('undo-pending / window-end', solve('undo-pending', [('window-end', N)], N), 'undo-pending')
check('retry-offered / retry-click', solve('retry-offered', [('retry-click', N)], N), 'undo-pending')
check('restored / late-window-end', solve('restored', [('late-window-end', N)], N), 'restored')
check('committed / late-undo-click', solve('committed', [('late-undo-click', N)], N), 'too-late')
check('too-late / acknowledge', solve('too-late', [('acknowledge', N)], N), 'closed')
check('retry-offered / dismiss-error', solve('retry-offered', [('dismiss-error', N)], N), 'committed')
check('older notification incarnation', solve('offered', [('undo-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('undo-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', [('undo-click', N - 1)] * N + [('undo-click', N)], N), 'undo-pending')
check('trace undo-click then undo-success', solve('offered', [('undo-click', N), ('undo-success', N)], N), 'restored')
check('trace undo-click then undo-failure', solve('offered', [('undo-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace undo-click then window-end', solve('offered', [('undo-click', N), ('window-end', N)], N), 'undo-pending')
check('trace undo-success then late-window-end', solve('undo-pending', [('undo-success', N), ('late-window-end', N)], N), 'restored')
check('trace undo-failure then retry-click', solve('undo-pending', [('undo-failure', N), ('retry-click', N)], N), 'undo-pending')
check('trace undo-failure then dismiss-error', solve('undo-pending', [('undo-failure', N), ('dismiss-error', N)], N), 'committed')
check('trace window-end then late-undo-click', solve('offered', [('window-end', N), ('late-undo-click', N)], N), 'too-late')
check('trace window-end then undo-success', solve('undo-pending', [('window-end', N), ('undo-success', N)], N), 'restored')
check('trace window-end then undo-failure', solve('undo-pending', [('window-end', N), ('undo-failure', N)], N), 'retry-offered')
check('trace window-end then window-end', solve('undo-pending', [('window-end', N), ('window-end', N)], N), 'undo-pending')
check('trace retry-click then undo-success', solve('retry-offered', [('retry-click', N), ('undo-success', N)], N), 'restored')
check('trace retry-click then undo-failure', solve('retry-offered', [('retry-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace retry-click then window-end', solve('retry-offered', [('retry-click', N), ('window-end', N)], N), 'undo-pending')
check('trace late-window-end then late-window-end', solve('restored', [('late-window-end', N), ('late-window-end', N)], N), 'restored')
check('trace late-undo-click then acknowledge', solve('committed', [('late-undo-click', N), ('acknowledge', N)], N), 'closed')
check('trace dismiss-error then late-undo-click', solve('retry-offered', [('dismiss-error', N), ('late-undo-click', N)], N), 'too-late')
check('domain state regression 1: requests', solve('offered', [('undo-click', N, {'now': 19})], N, {}, 'requests'), {'phase': 'undo-pending', 'value': 1})
check('domain state regression 2: requests', solve('offered', [('undo-click', N, {'now': 20})], N, {}, 'requests'), {'phase': 'committed', 'value': 0})
check('domain state regression 3: applied', solve('offered', [('window-end', N, {'now': 19})], N, {}, 'applied'), {'phase': 'offered', 'value': True})
check('domain state regression 4: applied', solve('undo-pending', [('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', 'value': False})
check('domain state regression 5: requests', solve('retry-offered', [('retry-click', N, {'now': 8})], N, {'requests': 1}, 'requests'), {'phase': 'undo-pending', 'value': 2})
check('domain state regression 6: now', solve('offered', [('undo-click', N, {'now': 2})], N, {}, 'now'), {'phase': 'undo-pending', 'value': 5})
check('domain state regression 7: applied', solve('offered', [('undo-click', N, {'now': 19}), ('window-end', N, {'now': 20}), ('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', '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 acknowledge event leaves a notification in offered instead of closed.

Notification undo affordance is a bounded visual-notification workflow with mutable policy state {'deadline': 20, 'now': 5, 'applied': True, 'requests': 0}. Its default transition relation is {('offered', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'closed', ('retry-offered', 'dismiss-error'): 'committed'}; 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 = {('offered', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'closed', ('retry-offered', 'dismiss-error'): 'restored'}
    data = json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})) if payload is None else {**json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            data['now'] = max(data['now'], arg.get('now', data['now']))
            if event in ('undo-click', 'retry-click'):
                if data['now'] >= data['deadline']: event = 'window-end'
                else: data['requests'] += 1
            if event == 'window-end' and data['now'] < data['deadline'] and 'now' in arg: event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'restored': data['applied'] = False
            if state == 'committed': data['applied'] = True
    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 / undo-click', solve('offered', [('undo-click', N)], N), 'undo-pending')
check('undo-pending / undo-success', solve('undo-pending', [('undo-success', N)], N), 'restored')
check('undo-pending / undo-failure', solve('undo-pending', [('undo-failure', N)], N), 'retry-offered')
check('offered / window-end', solve('offered', [('window-end', N)], N), 'committed')
check('undo-pending / window-end', solve('undo-pending', [('window-end', N)], N), 'undo-pending')
check('retry-offered / retry-click', solve('retry-offered', [('retry-click', N)], N), 'undo-pending')
check('restored / late-window-end', solve('restored', [('late-window-end', N)], N), 'restored')
check('committed / late-undo-click', solve('committed', [('late-undo-click', N)], N), 'too-late')
check('too-late / acknowledge', solve('too-late', [('acknowledge', N)], N), 'closed')
check('retry-offered / dismiss-error', solve('retry-offered', [('dismiss-error', N)], N), 'committed')
check('older notification incarnation', solve('offered', [('undo-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('undo-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', [('undo-click', N - 1)] * N + [('undo-click', N)], N), 'undo-pending')
check('trace undo-click then undo-success', solve('offered', [('undo-click', N), ('undo-success', N)], N), 'restored')
check('trace undo-click then undo-failure', solve('offered', [('undo-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace undo-click then window-end', solve('offered', [('undo-click', N), ('window-end', N)], N), 'undo-pending')
check('trace undo-success then late-window-end', solve('undo-pending', [('undo-success', N), ('late-window-end', N)], N), 'restored')
check('trace undo-failure then retry-click', solve('undo-pending', [('undo-failure', N), ('retry-click', N)], N), 'undo-pending')
check('trace undo-failure then dismiss-error', solve('undo-pending', [('undo-failure', N), ('dismiss-error', N)], N), 'committed')
check('trace window-end then late-undo-click', solve('offered', [('window-end', N), ('late-undo-click', N)], N), 'too-late')
check('trace window-end then undo-success', solve('undo-pending', [('window-end', N), ('undo-success', N)], N), 'restored')
check('trace window-end then undo-failure', solve('undo-pending', [('window-end', N), ('undo-failure', N)], N), 'retry-offered')
check('trace window-end then window-end', solve('undo-pending', [('window-end', N), ('window-end', N)], N), 'undo-pending')
check('trace retry-click then undo-success', solve('retry-offered', [('retry-click', N), ('undo-success', N)], N), 'restored')
check('trace retry-click then undo-failure', solve('retry-offered', [('retry-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace retry-click then window-end', solve('retry-offered', [('retry-click', N), ('window-end', N)], N), 'undo-pending')
check('trace late-window-end then late-window-end', solve('restored', [('late-window-end', N), ('late-window-end', N)], N), 'restored')
check('trace late-undo-click then acknowledge', solve('committed', [('late-undo-click', N), ('acknowledge', N)], N), 'closed')
check('trace dismiss-error then late-undo-click', solve('retry-offered', [('dismiss-error', N), ('late-undo-click', N)], N), 'too-late')
check('domain state regression 1: requests', solve('offered', [('undo-click', N, {'now': 19})], N, {}, 'requests'), {'phase': 'undo-pending', 'value': 1})
check('domain state regression 2: requests', solve('offered', [('undo-click', N, {'now': 20})], N, {}, 'requests'), {'phase': 'committed', 'value': 0})
check('domain state regression 3: applied', solve('offered', [('window-end', N, {'now': 19})], N, {}, 'applied'), {'phase': 'offered', 'value': True})
check('domain state regression 4: applied', solve('undo-pending', [('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', 'value': False})
check('domain state regression 5: requests', solve('retry-offered', [('retry-click', N, {'now': 8})], N, {'requests': 1}, 'requests'), {'phase': 'undo-pending', 'value': 2})
check('domain state regression 6: now', solve('offered', [('undo-click', N, {'now': 2})], N, {}, 'now'), {'phase': 'undo-pending', 'value': 5})
check('domain state regression 7: applied', solve('offered', [('undo-click', N, {'now': 19}), ('window-end', N, {'now': 20}), ('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', '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 = {('offered', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'closed', ('retry-offered', 'dismiss-error'): 'undo-pending'}
    data = json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})) if payload is None else {**json.loads(json.dumps({'deadline': 20, 'now': 5, 'applied': True, 'requests': 0})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            data['now'] = max(data['now'], arg.get('now', data['now']))
            if event in ('undo-click', 'retry-click'):
                if data['now'] >= data['deadline']: event = 'window-end'
                else: data['requests'] += 1
            if event == 'window-end' and data['now'] < data['deadline'] and 'now' in arg: event = 'unknown-event'
            state = table.get((state, event), state)
            if state == 'restored': data['applied'] = False
            if state == 'committed': data['applied'] = True
    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 / undo-click', solve('offered', [('undo-click', N)], N), 'undo-pending')
check('undo-pending / undo-success', solve('undo-pending', [('undo-success', N)], N), 'restored')
check('undo-pending / undo-failure', solve('undo-pending', [('undo-failure', N)], N), 'retry-offered')
check('offered / window-end', solve('offered', [('window-end', N)], N), 'committed')
check('undo-pending / window-end', solve('undo-pending', [('window-end', N)], N), 'undo-pending')
check('retry-offered / retry-click', solve('retry-offered', [('retry-click', N)], N), 'undo-pending')
check('restored / late-window-end', solve('restored', [('late-window-end', N)], N), 'restored')
check('committed / late-undo-click', solve('committed', [('late-undo-click', N)], N), 'too-late')
check('too-late / acknowledge', solve('too-late', [('acknowledge', N)], N), 'closed')
check('retry-offered / dismiss-error', solve('retry-offered', [('dismiss-error', N)], N), 'committed')
check('older notification incarnation', solve('offered', [('undo-click', N - 1)], N), 'offered')
check('future notification incarnation', solve('offered', [('undo-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', [('undo-click', N - 1)] * N + [('undo-click', N)], N), 'undo-pending')
check('trace undo-click then undo-success', solve('offered', [('undo-click', N), ('undo-success', N)], N), 'restored')
check('trace undo-click then undo-failure', solve('offered', [('undo-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace undo-click then window-end', solve('offered', [('undo-click', N), ('window-end', N)], N), 'undo-pending')
check('trace undo-success then late-window-end', solve('undo-pending', [('undo-success', N), ('late-window-end', N)], N), 'restored')
check('trace undo-failure then retry-click', solve('undo-pending', [('undo-failure', N), ('retry-click', N)], N), 'undo-pending')
check('trace undo-failure then dismiss-error', solve('undo-pending', [('undo-failure', N), ('dismiss-error', N)], N), 'committed')
check('trace window-end then late-undo-click', solve('offered', [('window-end', N), ('late-undo-click', N)], N), 'too-late')
check('trace window-end then undo-success', solve('undo-pending', [('window-end', N), ('undo-success', N)], N), 'restored')
check('trace window-end then undo-failure', solve('undo-pending', [('window-end', N), ('undo-failure', N)], N), 'retry-offered')
check('trace window-end then window-end', solve('undo-pending', [('window-end', N), ('window-end', N)], N), 'undo-pending')
check('trace retry-click then undo-success', solve('retry-offered', [('retry-click', N), ('undo-success', N)], N), 'restored')
check('trace retry-click then undo-failure', solve('retry-offered', [('retry-click', N), ('undo-failure', N)], N), 'retry-offered')
check('trace retry-click then window-end', solve('retry-offered', [('retry-click', N), ('window-end', N)], N), 'undo-pending')
check('trace late-window-end then late-window-end', solve('restored', [('late-window-end', N), ('late-window-end', N)], N), 'restored')
check('trace late-undo-click then acknowledge', solve('committed', [('late-undo-click', N), ('acknowledge', N)], N), 'closed')
check('trace dismiss-error then late-undo-click', solve('retry-offered', [('dismiss-error', N), ('late-undo-click', N)], N), 'too-late')
check('domain state regression 1: requests', solve('offered', [('undo-click', N, {'now': 19})], N, {}, 'requests'), {'phase': 'undo-pending', 'value': 1})
check('domain state regression 2: requests', solve('offered', [('undo-click', N, {'now': 20})], N, {}, 'requests'), {'phase': 'committed', 'value': 0})
check('domain state regression 3: applied', solve('offered', [('window-end', N, {'now': 19})], N, {}, 'applied'), {'phase': 'offered', 'value': True})
check('domain state regression 4: applied', solve('undo-pending', [('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', 'value': False})
check('domain state regression 5: requests', solve('retry-offered', [('retry-click', N, {'now': 8})], N, {'requests': 1}, 'requests'), {'phase': 'undo-pending', 'value': 2})
check('domain state regression 6: now', solve('offered', [('undo-click', N, {'now': 2})], N, {}, 'now'), {'phase': 'undo-pending', 'value': 5})
check('domain state regression 7: applied', solve('offered', [('undo-click', N, {'now': 19}), ('window-end', N, {'now': 20}), ('undo-success', N, {})], N, {}, 'applied'), {'phase': 'restored', '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 dismiss-error event leaves a notification in restored instead of committed.

Notification undo affordance is a bounded visual-notification workflow with mutable policy state {'deadline': 20, 'now': 5, 'applied': True, 'requests': 0}. Its default transition relation is {('offered', 'undo-click'): 'undo-pending', ('undo-pending', 'undo-success'): 'restored', ('undo-pending', 'undo-failure'): 'retry-offered', ('offered', 'window-end'): 'committed', ('undo-pending', 'window-end'): 'undo-pending', ('retry-offered', 'retry-click'): 'undo-pending', ('restored', 'late-window-end'): 'restored', ('committed', 'late-undo-click'): 'too-late', ('too-late', 'acknowledge'): 'closed', ('retry-offered', 'dismiss-error'): 'committed'}; 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 = {('ready', 'action-click'): 'succeeded', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 = {('ready', 'action-click'): 'failed', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 action-click event leaves a notification in succeeded instead of submitting.

Toast action request feedback is a bounded visual-notification workflow with mutable policy state {'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True}. Its default transition relation is {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}; 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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'ready', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'succeeded', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 second-click event leaves a notification in ready instead of submitting.

Toast action request feedback is a bounded visual-notification workflow with mutable policy state {'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True}. Its default transition relation is {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}; 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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'succeeded', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'ready', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 accepted event leaves a notification in succeeded instead of running.

Toast action request feedback is a bounded visual-notification workflow with mutable policy state {'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True}. Its default transition relation is {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}; 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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'ready', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 = {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'failed', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}
    data = json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})) if payload is None else {**json.loads(json.dumps({'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            command = arg.get('command', data['command'])
            if event in ('accepted', 'completion', 'rejection') and command != data['command']: event = 'unknown-event'
            if event in ('action-click','retry-click') and data['command'] not in data['pending']: data['pending'].append(data['command'])
            if event == 'transport-unknown': data['transport_known'] = False
            if event.startswith('status-confirmed-'): data['transport_known'] = True
            state = table.get((state, event), state)
            if state == 'succeeded':
                data['pending'] = [x for x in data['pending'] if x != data['command']]
                if data['command'] not in data['completed']: data['completed'].append(data['command'])
            if state == 'ready': data['pending'] = [x for x in data['pending'] if x != data['command']]
    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('ready / action-click', solve('ready', [('action-click', N)], N), 'submitting')
check('submitting / second-click', solve('submitting', [('second-click', N)], N), 'submitting')
check('submitting / accepted', solve('submitting', [('accepted', N)], N), 'running')
check('running / completion', solve('running', [('completion', N)], N), 'succeeded')
check('running / rejection', solve('running', [('rejection', N)], N), 'failed')
check('failed / retry-click', solve('failed', [('retry-click', N)], N), 'submitting')
check('submitting / transport-unknown', solve('submitting', [('transport-unknown', N)], N), 'uncertain')
check('uncertain / status-confirmed-running', solve('uncertain', [('status-confirmed-running', N)], N), 'running')
check('uncertain / status-confirmed-absent', solve('uncertain', [('status-confirmed-absent', N)], N), 'ready')
check('succeeded / stale-rejection', solve('succeeded', [('stale-rejection', N)], N), 'succeeded')
check('older notification incarnation', solve('ready', [('action-click', N - 1)], N), 'ready')
check('future notification incarnation', solve('ready', [('action-click', N + 1)], N), 'ready')
check('unknown event is inert', solve('ready', [('unknown-event', N)], N), 'ready')
check('empty delivery batch', solve('ready', [], N), 'ready')
check('N stale deliveries before current delivery', solve('ready', [('action-click', N - 1)] * N + [('action-click', N)], N), 'submitting')
check('trace action-click then second-click', solve('ready', [('action-click', N), ('second-click', N)], N), 'submitting')
check('trace action-click then accepted', solve('ready', [('action-click', N), ('accepted', N)], N), 'running')
check('trace action-click then transport-unknown', solve('ready', [('action-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace second-click then second-click', solve('submitting', [('second-click', N), ('second-click', N)], N), 'submitting')
check('trace second-click then accepted', solve('submitting', [('second-click', N), ('accepted', N)], N), 'running')
check('trace second-click then transport-unknown', solve('submitting', [('second-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace accepted then completion', solve('submitting', [('accepted', N), ('completion', N)], N), 'succeeded')
check('trace accepted then rejection', solve('submitting', [('accepted', N), ('rejection', N)], N), 'failed')
check('trace completion then stale-rejection', solve('running', [('completion', N), ('stale-rejection', N)], N), 'succeeded')
check('trace rejection then retry-click', solve('running', [('rejection', N), ('retry-click', N)], N), 'submitting')
check('trace retry-click then second-click', solve('failed', [('retry-click', N), ('second-click', N)], N), 'submitting')
check('trace retry-click then accepted', solve('failed', [('retry-click', N), ('accepted', N)], N), 'running')
check('trace retry-click then transport-unknown', solve('failed', [('retry-click', N), ('transport-unknown', N)], N), 'uncertain')
check('trace transport-unknown then status-confirmed-running', solve('submitting', [('transport-unknown', N), ('status-confirmed-running', N)], N), 'running')
check('trace transport-unknown then status-confirmed-absent', solve('submitting', [('transport-unknown', N), ('status-confirmed-absent', N)], N), 'ready')
check('trace status-confirmed-running then completion', solve('uncertain', [('status-confirmed-running', N), ('completion', N)], N), 'succeeded')
check('trace status-confirmed-running then rejection', solve('uncertain', [('status-confirmed-running', N), ('rejection', N)], N), 'failed')
check('trace status-confirmed-absent then action-click', solve('uncertain', [('status-confirmed-absent', N), ('action-click', N)], N), 'submitting')
check('trace stale-rejection then stale-rejection', solve('succeeded', [('stale-rejection', N), ('stale-rejection', N)], N), 'succeeded')
check('domain state regression 1: completed', solve('running', [('completion', N, {'command': 'old'})], N, {}, 'completed'), {'phase': 'running', 'value': []})
check('domain state regression 2: pending', solve('running', [('completion', N, {'command': 'c1'})], N, {'pending': ['c1']}, 'pending'), {'phase': 'succeeded', 'value': []})
check('domain state regression 3: completed', solve('running', [('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
check('domain state regression 4: transport_known', solve('submitting', [('transport-unknown', N, {})], N, {}, 'transport_known'), {'phase': 'uncertain', 'value': False})
check('domain state regression 5: transport_known', solve('uncertain', [('status-confirmed-running', N, {})], N, {'transport_known': False}, 'transport_known'), {'phase': 'running', 'value': True})
check('domain state regression 6: pending', solve('ready', [('action-click', N, {})], N, {'pending': ['other']}, 'pending'), {'phase': 'submitting', 'value': ['other', 'c1']})
check('domain state regression 7: completed', solve('ready', [('action-click', N, {}), ('accepted', N, {}), ('completion', N, {})], N, {}, 'completed'), {'phase': 'succeeded', 'value': ['c1']})
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 completion event leaves a notification in ready instead of succeeded.

Toast action request feedback is a bounded visual-notification workflow with mutable policy state {'command': 'c1', 'pending': [], 'completed': [], 'transport_known': True}. Its default transition relation is {('ready', 'action-click'): 'submitting', ('submitting', 'second-click'): 'submitting', ('submitting', 'accepted'): 'running', ('running', 'completion'): 'succeeded', ('running', 'rejection'): 'failed', ('failed', 'retry-click'): 'submitting', ('submitting', 'transport-unknown'): 'uncertain', ('uncertain', 'status-confirmed-running'): 'running', ('uncertain', 'status-confirmed-absent'): 'ready', ('succeeded', 'stale-rejection'): 'succeeded'}; 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