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

N = 1
observations = []
def solve(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status != 'read' else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status == 'sent' else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
A transport failure reported after delivery marks a delivered message as failed.

events are [seq, kind] with kind in queued, sent, delivered, read, failed, retry, processed in (seq, kind) order. Ranks queued<sent<delivered<read and status never regresses. failed only applies while queued or sent; retry moves failed back to queued; after a failure only delivered or read evidence (not a stale sent) replaces it. Result {status, history} where history lists every status change starting at queued.

split: open-access


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

N = 1
observations = []
def solve(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued'
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued' if status != 'read' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
A retry signal resets a delivered message back to queued.

events are [seq, kind] with kind in queued, sent, delivered, read, failed, retry, processed in (seq, kind) order. Ranks queued<sent<delivered<read and status never regresses. failed only applies while queued or sent; retry moves failed back to queued; after a failure only delivered or read evidence (not a stale sent) replaces it. Result {status, history} where history lists every status change starting at queued.

split: open-access


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

N = 1
observations = []
def solve(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] > rank['delivered'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['sent'] else status
        else:
            nxt = kind if rank[kind] > rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
Delivery evidence arriving after a spurious failure is ignored, or a stale sent revives the message.

events are [seq, kind] with kind in queued, sent, delivered, read, failed, retry, processed in (seq, kind) order. Ranks queued<sent<delivered<read and status never regresses. failed only applies while queued or sent; retry moves failed back to queued; after a failure only delivered or read evidence (not a stale sent) replaces it. Result {status, history} where history lists every status change starting at queued.

split: open-access


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

N = 1
observations = []
def solve(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] != rank[status] else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(events):
    rank = {'queued': 0, 'sent': 1, 'delivered': 2, 'read': 3}
    status = 'queued'
    history = ['queued']
    for _, kind in sorted(events):
        if kind == 'failed':
            nxt = 'failed' if status in ('queued', 'sent') else status
        elif kind == 'retry':
            nxt = 'queued' if status == 'failed' else status
        elif status == 'failed':
            nxt = kind if rank[kind] >= rank['delivered'] else status
        else:
            nxt = kind if rank[kind] >= rank[status] - 1 else status
        if nxt != status:
            status = nxt
            history.append(status)
    return {'status': status, 'history': history}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('arrival order differs', ([[4, 'read'], [2, 'sent'], [3, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[1, 'failed'], [2, 'retry'], [3, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [3, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [4, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [5, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 2: [('arrival order differs', ([[5, 'read'], [3, 'sent'], [4, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[2, 'failed'], [3, 'retry'], [4, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [4, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [5, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [6, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 3: [('arrival order differs', ([[6, 'read'], [4, 'sent'], [5, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[3, 'failed'], [4, 'retry'], [5, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [5, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [6, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [7, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 4: [('arrival order differs', ([[7, 'read'], [5, 'sent'], [6, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[4, 'failed'], [5, 'retry'], [6, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [6, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [7, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [8, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})], 5: [('arrival order differs', ([[8, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'sent', 'delivered', 'read'], 'status': 'read'}), ('failure after delivery', ([[1, 'sent'], [2, 'delivered'], [3, 'failed']],), {'history': ['queued', 'sent', 'delivered'], 'status': 'delivered'}), ('failure while queued', ([[5, 'failed'], [6, 'retry'], [7, 'sent']],), {'history': ['queued', 'failed', 'queued', 'sent'], 'status': 'sent'}), ('retry after read', ([[1, 'read'], [2, 'retry']],), {'history': ['queued', 'read'], 'status': 'read'}), ('retry after delivery', ([[1, 'delivered'], [7, 'retry']],), {'history': ['queued', 'delivered'], 'status': 'delivered'}), ('late delivery after failure', ([[1, 'sent'], [2, 'failed'], [3, 'delivered']],), {'history': ['queued', 'sent', 'failed', 'delivered'], 'status': 'delivered'}), ('stale sent after failure', ([[1, 'sent'], [2, 'failed'], [8, 'sent']],), {'history': ['queued', 'sent', 'failed'], 'status': 'failed'}), ('late sent after read', ([[5, 'read'], [6, 'sent'], [7, 'delivered']],), {'history': ['queued', 'read'], 'status': 'read'}), ('failed then retried delivery', ([[2, 'failed'], [3, 'retry'], [4, 'delivered'], [9, 'failed']],), {'history': ['queued', 'failed', 'queued', 'delivered'], 'status': 'delivered'})]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
A late "sent" event downgrades a message that was already read.

events are [seq, kind] with kind in queued, sent, delivered, read, failed, retry, processed in (seq, kind) order. Ranks queued<sent<delivered<read and status never regresses. failed only applies while queued or sent; retry moves failed back to queued; after a failure only delivered or read evidence (not a stale sent) replaces it. Result {status, history} where history lists every status change starting at queued.

split: open-access


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

N = 1
observations = []
def solve(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, False)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, chat_kind != 'direct')
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
Users who never touched the privacy setting are treated as having disabled read receipts.

settings[u] is a user's "send read receipts" flag (default True). In direct chats a reader is shown only when both the reader and the viewer have receipts enabled (reciprocity). In group chats only the reader's flag matters. In channels only admins see receipts and they see every reader regardless of settings. The viewer never sees their own receipt. Result: sorted visible readers.

split: open-access


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

N = 1
observations = []
def solve(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u) or enabled(viewer)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
A viewer who disabled their own receipts can still see other people's receipts in direct chats.

settings[u] is a user's "send read receipts" flag (default True). In direct chats a reader is shown only when both the reader and the viewer have receipts enabled (reciprocity). In group chats only the reader's flag matters. In channels only admins see receipts and they see every reader regardless of settings. The viewer never sees their own receipt. Result: sorted visible readers.

split: open-access


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

N = 1
observations = []
def solve(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(u) and enabled(viewer)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(viewer)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
Group receipts vanish for viewers who disabled their own receipts although reciprocity only applies to direct chats.

settings[u] is a user's "send read receipts" flag (default True). In direct chats a reader is shown only when both the reader and the viewer have receipts enabled (reciprocity). In group chats only the reader's flag matters. In channels only admins see receipts and they see every reader regardless of settings. The viewer never sees their own receipt. Result: sorted visible readers.

split: open-access


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

N = 1
observations = []
def solve(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = viewer in admins and enabled(u)
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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(viewer, readers, settings, chat_kind, admins):
    enabled = lambda u: settings.get(u, True)
    out = []
    for u in readers:
        if u == viewer:
            continue
        if chat_kind == 'channel':
            ok = enabled(u)
        elif chat_kind == 'direct':
            ok = enabled(u) and enabled(viewer)
        else:
            ok = enabled(u)
        if ok:
            out.append(u)
    return sorted(out)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('missing settings default on', ('v', ['r1'], {}, 'direct', []), ['r1']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r1'], {}, 'group', []), ['r1']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 2: [('missing settings default on', ('v', ['r2'], {}, 'direct', []), ['r2']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r2'], {}, 'group', []), ['r2']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 3: [('missing settings default on', ('v', ['r3'], {}, 'direct', []), ['r3']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r3'], {}, 'group', []), ['r3']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 4: [('missing settings default on', ('v', ['r4'], {}, 'direct', []), ['r4']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r4'], {}, 'group', []), ['r4']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])], 5: [('missing settings default on', ('v', ['r5'], {}, 'direct', []), ['r5']), ('viewer disabled in direct chat', ('v', ['r'], {'v': False}, 'direct', []), []), ('viewer disabled in group', ('v', ['r', 'q'], {'v': False, 'q': False}, 'group', []), ['r']), ('reader disabled in direct chat', ('v', ['r'], {'r': False, 'v': True}, 'direct', []), []), ('channel admin', ('v', ['r', 'q', 'p'], {'r': False}, 'channel', ['v']), ['p', 'q', 'r']), ('channel non-admin', ('v', ['r'], {}, 'channel', ['a']), []), ('own receipt in group', ('v', ['v', 'r5'], {}, 'group', []), ['r5']), ('own receipt in channel as admin', ('v', ['v'], {}, 'channel', ['v']), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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:
Channel admins lose receipts of members who disabled them, or non-admins see channel receipts.

settings[u] is a user's "send read receipts" flag (default True). In direct chats a reader is shown only when both the reader and the viewer have receipts enabled (reciprocity). In group chats only the reader's flag matters. In channels only admins see receipts and they see every reader regardless of settings. The viewer never sees their own receipt. Result: sorted visible readers.

split: open-access