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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'displaying', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'releasing', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 unmounted event leaves a notification in displaying instead of standby.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'standby', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'displaying', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The close-surface event leaves a notification in standby instead of releasing.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'displaying', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'claiming', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 release-confirmed event leaves a notification in displaying instead of standby.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'standby', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'displaying', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The cancel-display event leaves a notification in standby instead of claim-canceled.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'displaying', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'standby', ('standby', 'foreign-release'): 'standby'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 late-lease-granted event leaves a notification in displaying instead of releasing.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'displaying'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 = {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'releasing'}
    data = json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})) if payload is None else {**json.loads(json.dumps({'token': 5, 'owner': 'local', 'mounted': False, 'released': []})), **json.loads(json.dumps(payload))}
    state = initial
    for delivery in events:
        event, event_generation = delivery[:2]
        arg = delivery[2] if len(delivery) > 2 else {}
        if event_generation == generation:
            previous = state
            if event in ('lease-granted','lease-revoked','release-confirmed','late-lease-granted') and arg.get('token',data['token']) != data['token']: event = 'unknown-event'
            if event == 'foreign-release' and arg.get('owner','foreign') == data['owner']: event = 'release-confirmed'
            state = table.get((state, event), state)
            if state == 'displaying': data['mounted'] = True
            if state in ('standby','withdrawing'): data['mounted'] = False
            if state == 'releasing' and data['token'] not in data['released']: data['released'].append(data['token'])
    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('standby / request-display', solve('standby', [('request-display', N)], N), 'claiming')
check('claiming / lease-granted', solve('claiming', [('lease-granted', N)], N), 'displaying')
check('claiming / lease-denied', solve('claiming', [('lease-denied', N)], N), 'standby')
check('displaying / lease-revoked', solve('displaying', [('lease-revoked', N)], N), 'withdrawing')
check('withdrawing / unmounted', solve('withdrawing', [('unmounted', N)], N), 'standby')
check('displaying / close-surface', solve('displaying', [('close-surface', N)], N), 'releasing')
check('releasing / release-confirmed', solve('releasing', [('release-confirmed', N)], N), 'standby')
check('claiming / cancel-display', solve('claiming', [('cancel-display', N)], N), 'claim-canceled')
check('claim-canceled / late-lease-granted', solve('claim-canceled', [('late-lease-granted', N)], N), 'releasing')
check('standby / foreign-release', solve('standby', [('foreign-release', N)], N), 'standby')
check('older notification incarnation', solve('standby', [('request-display', N - 1)], N), 'standby')
check('future notification incarnation', solve('standby', [('request-display', N + 1)], N), 'standby')
check('unknown event is inert', solve('standby', [('unknown-event', N)], N), 'standby')
check('empty delivery batch', solve('standby', [], N), 'standby')
check('N stale deliveries before current delivery', solve('standby', [('request-display', N - 1)] * N + [('request-display', N)], N), 'claiming')
check('trace request-display then lease-granted', solve('standby', [('request-display', N), ('lease-granted', N)], N), 'displaying')
check('trace request-display then lease-denied', solve('standby', [('request-display', N), ('lease-denied', N)], N), 'standby')
check('trace request-display then cancel-display', solve('standby', [('request-display', N), ('cancel-display', N)], N), 'claim-canceled')
check('trace lease-granted then lease-revoked', solve('claiming', [('lease-granted', N), ('lease-revoked', N)], N), 'withdrawing')
check('trace lease-granted then close-surface', solve('claiming', [('lease-granted', N), ('close-surface', N)], N), 'releasing')
check('trace lease-denied then request-display', solve('claiming', [('lease-denied', N), ('request-display', N)], N), 'claiming')
check('trace lease-denied then foreign-release', solve('claiming', [('lease-denied', N), ('foreign-release', N)], N), 'standby')
check('trace lease-revoked then unmounted', solve('displaying', [('lease-revoked', N), ('unmounted', N)], N), 'standby')
check('trace unmounted then request-display', solve('withdrawing', [('unmounted', N), ('request-display', N)], N), 'claiming')
check('trace unmounted then foreign-release', solve('withdrawing', [('unmounted', N), ('foreign-release', N)], N), 'standby')
check('trace close-surface then release-confirmed', solve('displaying', [('close-surface', N), ('release-confirmed', N)], N), 'standby')
check('trace release-confirmed then request-display', solve('releasing', [('release-confirmed', N), ('request-display', N)], N), 'claiming')
check('trace release-confirmed then foreign-release', solve('releasing', [('release-confirmed', N), ('foreign-release', N)], N), 'standby')
check('trace cancel-display then late-lease-granted', solve('claiming', [('cancel-display', N), ('late-lease-granted', N)], N), 'releasing')
check('trace late-lease-granted then release-confirmed', solve('claim-canceled', [('late-lease-granted', N), ('release-confirmed', N)], N), 'standby')
check('trace foreign-release then request-display', solve('standby', [('foreign-release', N), ('request-display', N)], N), 'claiming')
check('trace foreign-release then foreign-release', solve('standby', [('foreign-release', N), ('foreign-release', N)], N), 'standby')
check('domain state regression 1: mounted', solve('claiming', [('lease-granted', N, {'token': 4})], N, {}, 'mounted'), {'phase': 'claiming', 'value': False})
check('domain state regression 2: mounted', solve('claiming', [('lease-granted', N, {'token': 5})], N, {}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 3: mounted', solve('displaying', [('lease-revoked', N, {'token': 4})], N, {'mounted': True}, 'mounted'), {'phase': 'displaying', 'value': True})
check('domain state regression 4: mounted', solve('displaying', [('lease-revoked', N, {'token': 5})], N, {'mounted': True}, 'mounted'), {'phase': 'withdrawing', 'value': False})
check('domain state regression 5: released', solve('claim-canceled', [('late-lease-granted', N, {})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
check('domain state regression 6: released', solve('standby', [('foreign-release', N, {'owner': 'foreign'})], N, {}, 'released'), {'phase': 'standby', 'value': []})
check('domain state regression 7: released', solve('standby', [('request-display', N, {}), ('cancel-display', N, {}), ('late-lease-granted', N, {'token': 5})], N, {}, 'released'), {'phase': 'releasing', 'value': [5]})
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 foreign-release event leaves a notification in displaying instead of standby.

Single-surface notification display ownership is a bounded visual-notification workflow with mutable policy state {'token': 5, 'owner': 'local', 'mounted': False, 'released': []}. Its default transition relation is {('standby', 'request-display'): 'claiming', ('claiming', 'lease-granted'): 'displaying', ('claiming', 'lease-denied'): 'standby', ('displaying', 'lease-revoked'): 'withdrawing', ('withdrawing', 'unmounted'): 'standby', ('displaying', 'close-surface'): 'releasing', ('releasing', 'release-confirmed'): 'standby', ('claiming', 'cancel-display'): 'claim-canceled', ('claim-canceled', 'late-lease-granted'): 'releasing', ('standby', 'foreign-release'): 'standby'}; 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