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

N = 1
observations = []
def solve(events, me, now, names):
    last = {}
    for ts, user, kind in events:
        if kind == 'start':
            last[user] = ts
        else:
            last.pop(user, None)
    active = sorted((ts, user) for user, ts in last.items() if user != me and now - ts < 6000)
    who = [names.get(u, u) for _, u in active]
    if not who:
        return ''
    if len(who) == 1:
        return who[0] + ' is typing'
    if len(who) == 2:
        return who[0] + ' and ' + who[1] + ' are typing'
    return 'Several people are typing'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('exact expiry', ([[1000, 'bo', 'start']], 'me', 7000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50001, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [301, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [701, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 11, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2501, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 21, {}), '')], 2: [('exact expiry', ([[2000, 'bo', 'start']], 'me', 8000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50002, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [302, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [702, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 12, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2502, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 22, {}), '')], 3: [('exact expiry', ([[3000, 'bo', 'start']], 'me', 9000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50003, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [303, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [703, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 13, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2503, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 23, {}), '')], 4: [('exact expiry', ([[4000, 'bo', 'start']], 'me', 10000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50004, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [304, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [704, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 14, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2504, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 24, {}), '')], 5: [('exact expiry', ([[5000, 'bo', 'start']], 'me', 11000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50005, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [305, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [705, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 15, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2505, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 25, {}), '')]}
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, me, now, names):
    last = {}
    for ts, user, kind in sorted(events, key=lambda e: e[0] // 1000):
        if kind == 'start':
            last[user] = ts
        else:
            last.pop(user, None)
    active = sorted((ts, user) for user, ts in last.items() if user != me and now - ts < 6000)
    who = [names.get(u, u) for _, u in active]
    if not who:
        return ''
    if len(who) == 1:
        return who[0] + ' is typing'
    if len(who) == 2:
        return who[0] + ' and ' + who[1] + ' are typing'
    return 'Several people are typing'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('exact expiry', ([[1000, 'bo', 'start']], 'me', 7000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50001, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [301, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [701, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 11, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2501, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 21, {}), '')], 2: [('exact expiry', ([[2000, 'bo', 'start']], 'me', 8000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50002, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [302, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [702, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 12, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2502, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 22, {}), '')], 3: [('exact expiry', ([[3000, 'bo', 'start']], 'me', 9000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50003, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [303, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [703, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 13, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2503, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 23, {}), '')], 4: [('exact expiry', ([[4000, 'bo', 'start']], 'me', 10000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50004, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [304, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [704, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 14, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2504, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 24, {}), '')], 5: [('exact expiry', ([[5000, 'bo', 'start']], 'me', 11000, {'bo': 'Bo'}), ''), ('future stamped start', ([[50005, 'bo', 'start']], 'me', 40000, {}), 'bo is typing'), ('message clears typing', ([[100, 'bo', 'start'], [305, 'bo', 'message']], 'me', 1000, {'bo': 'Bo'}), ''), ('start order', ([[500, 'zed', 'start'], [705, 'amy', 'start']], 'me', 2000, {'zed': 'Zed', 'amy': 'Amy'}), 'Zed and Amy are typing'), ('three typers', ([[1, 'a', 'start'], [2, 'b', 'start'], [3, 'c', 'start']], 'me', 15, {'a': 'A', 'b': 'B', 'c': 'C'}), 'Several people are typing'), ('stop overtaken in transit', ([[2505, 'bo', 'stop'], [2100, 'bo', 'start'], [2600, 'cy', 'start']], 'me', 3000, {'cy': 'Cy'}), 'Cy is typing'), ('self typing hidden', ([[10, 'me', 'start']], 'me', 25, {}), '')]}
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 stop that overtook its start in transit leaves the indicator stuck on.

events [ts_ms, user, kind] with kind start, stop or message are applied in (ts, user, kind) order. A user is typing when their latest start has no later stop or message and now - start < 6000 ms (a start stamped in the future by a skewed clock stays active). The viewer is excluded. Typers are listed by start time: one -> "A is typing", two -> "A and B are typing", more -> "Several people are typing", none -> "". names maps ids to display names.

split: open-access


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

N = 1
observations = []
def solve(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] >= 300:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300000:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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:
Messages exactly five minutes apart are split, or long pauses are not split at all.

messages are ascending {author, ts, kind}. A message shows a header (starts a group) when it is the first message, when it or the previous message is a system message, when the author changes, when more than 300 seconds passed since the previous message, or when the UTC day changes. Result: one boolean per message.

split: open-access


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

N = 1
observations = []
def solve(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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:
The first user message after a system notice is glued to the group before the notice.

messages are ascending {author, ts, kind}. A message shows a header (starts a group) when it is the first message, when it or the previous message is a system message, when the author changes, when more than 300 seconds passed since the previous message, or when the UTC day changes. Result: one boolean per message.

split: open-access


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

N = 1
observations = []
def solve(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = False
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = m['ts'] - prev['ts'] >= 86400
        out.append(head)
        prev = m
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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:
Messages sent seconds apart across midnight are grouped under the previous day's header.

messages are ascending {author, ts, kind}. A message shows a header (starts a group) when it is the first message, when it or the previous message is a system message, when the author changes, when more than 300 seconds passed since the previous message, or when the UTC day changes. Result: one boolean per message.

split: open-access


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

N = 1
observations = []
def solve(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m if m['kind'] != 'system' else prev
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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(messages):
    out = []
    prev = None
    for m in messages:
        if prev is None or m['kind'] == 'system' or prev['kind'] == 'system':
            head = True
        elif m['author'] != prev['author']:
            head = True
        elif m['ts'] - prev['ts'] > 300:
            head = True
        else:
            head = m['ts'] // 86400 != prev['ts'] // 86400
        out.append(head)
        prev = m if m['kind'] == 'user' else prev
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1401, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 13, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259211, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}],), [True, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 2: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1402, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 2000, 'kind': 'user'}, {'author': 'bo', 'ts': 2300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 14, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259212, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}],), [True, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 3: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1403, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 3000, 'kind': 'user'}, {'author': 'bo', 'ts': 3300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 15, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259213, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}],), [True, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 4: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1404, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 4000, 'kind': 'user'}, {'author': 'bo', 'ts': 4300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 16, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259214, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}],), [True, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])], 5: [('long pause', ([{'author': 'bo', 'ts': 1000, 'kind': 'user'}, {'author': 'bo', 'ts': 1405, 'kind': 'user'}],), [True, True]), ('exact five minutes', ([{'author': 'bo', 'ts': 5000, 'kind': 'user'}, {'author': 'bo', 'ts': 5300, 'kind': 'user'}],), [True, False]), ('after a system message', ([{'author': 'bo', 'ts': 10, 'kind': 'user'}, {'author': 'bo', 'ts': 11, 'kind': 'system'}, {'author': 'bo', 'ts': 17, 'kind': 'user'}],), [True, True, True]), ('midnight crossing', ([{'author': 'bo', 'ts': 259170, 'kind': 'user'}, {'author': 'bo', 'ts': 259215, 'kind': 'user'}],), [True, True]), ('burst', ([{'author': 'bo', 'ts': 100, 'kind': 'user'}, {'author': 'bo', 'ts': 160, 'kind': 'user'}, {'author': 'bo', 'ts': 220, 'kind': 'user'}, {'author': 'bo', 'ts': 280, 'kind': 'user'}, {'author': 'bo', 'ts': 340, 'kind': 'user'}, {'author': 'bo', 'ts': 400, 'kind': 'user'}, {'author': 'bo', 'ts': 460, 'kind': 'user'}, {'author': 'bo', 'ts': 520, 'kind': 'user'}],), [True, False, False, False, False, False, False, False]), ('author change', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'cy', 'ts': 6, 'kind': 'user'}],), [True, True]), ('bot notice between', ([{'author': 'bo', 'ts': 5, 'kind': 'user'}, {'author': 'bot', 'ts': 6, 'kind': 'notice'}, {'author': 'bo', 'ts': 7, 'kind': 'user'}],), [True, True, True])]}
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:
System notices are skipped when tracking the previous message, so the next user message is grouped across the notice.

messages are ascending {author, ts, kind}. A message shows a header (starts a group) when it is the first message, when it or the previous message is a system message, when the author changes, when more than 300 seconds passed since the previous message, or when the UTC day changes. Result: one boolean per message.

split: open-access


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

N = 1
observations = []
def solve(outbox, acked, failed, now):
    done = set(acked)
    out = []
    by_conv = {}
    for m in outbox:
        by_conv.setdefault(m['conv'], []).append(m)
    for conv in sorted(by_conv):
        for m in sorted(by_conv[conv], key=lambda m: m['order']):
            if m['nonce'] in done:
                continue
            if failed.get(m['nonce'], 0) >= 5:
                continue
            if m['next_try'] <= now:
                out.append(m['nonce'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 101}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 41}], [], {}, 41), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 1), ['p', 'q'])], 2: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 102}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 42}], [], {}, 42), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 2), ['p', 'q'])], 3: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 103}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 43}], [], {}, 43), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 3), ['p', 'q'])], 4: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 104}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 44}], [], {}, 44), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 4), ['p', 'q'])], 5: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 105}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 45}], [], {}, 45), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 5), ['p', 'q'])]}
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(outbox, acked, failed, now):
    done = set(acked)
    out = []
    by_conv = {}
    for m in outbox:
        by_conv.setdefault(m['conv'], []).append(m)
    for conv in sorted(by_conv):
        for m in sorted(by_conv[conv], key=lambda m: m['order']):
            if m['nonce'] in done:
                continue
            if failed.get(m['nonce'], 0) >= 5:
                continue
            if m['next_try'] <= now:
                out.append(m['nonce'])
                break
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 101}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 41}], [], {}, 41), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 1), ['p', 'q'])], 2: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 102}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 42}], [], {}, 42), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 2), ['p', 'q'])], 3: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 103}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 43}], [], {}, 43), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 3), ['p', 'q'])], 4: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 104}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 44}], [], {}, 44), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 4), ['p', 'q'])], 5: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 105}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 45}], [], {}, 45), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 5), ['p', 'q'])]}
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:
Later messages are dispatched while an earlier one is still pending, so they arrive out of order.

outbox items {nonce, conv, order, next_try}. Per conversation, messages are sent strictly in numeric `order`: the head is the lowest-order message that is neither acknowledged nor dead (failed attempts >= 5). Dead messages are skipped without blocking. The head is dispatched when next_try <= now; later messages always wait for it. Result: nonces to dispatch, by conversation id then order.

split: open-access


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

N = 1
observations = []
def solve(outbox, acked, failed, now):
    done = set(acked)
    out = []
    by_conv = {}
    for m in outbox:
        by_conv.setdefault(m['conv'], []).append(m)
    for conv in sorted(by_conv):
        for m in sorted(by_conv[conv], key=lambda m: m['order']):
            if m['nonce'] in done:
                continue
            if failed.get(m['conv'], 0) >= 5:
                continue
            if m['next_try'] <= now:
                out.append(m['nonce'])
            break
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 101}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 41}], [], {}, 41), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 1), ['p', 'q'])], 2: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 102}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 42}], [], {}, 42), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 2), ['p', 'q'])], 3: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 103}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 43}], [], {}, 43), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 3), ['p', 'q'])], 4: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 104}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 44}], [], {}, 44), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 4), ['p', 'q'])], 5: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 105}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 45}], [], {}, 45), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 5), ['p', 'q'])]}
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(outbox, acked, failed, now):
    done = set(acked)
    out = []
    by_conv = {}
    for m in outbox:
        by_conv.setdefault(m['conv'], []).append(m)
    for conv in sorted(by_conv):
        for m in sorted(by_conv[conv], key=lambda m: m['order']):
            if m['nonce'] in done:
                continue
            if failed.get(m['nonce'], 0) >= 5 and m['next_try'] <= now:
                continue
            if m['next_try'] <= now:
                out.append(m['nonce'])
            break
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 101}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 41}], [], {}, 41), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 1), ['p', 'q'])], 2: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 102}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 42}], [], {}, 42), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 2), ['p', 'q'])], 3: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 103}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 43}], [], {}, 43), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 3), ['p', 'q'])], 4: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 104}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 5}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 44}], [], {}, 44), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 4), ['p', 'q'])], 5: [('head not yet due', ([{'nonce': 'a1', 'conv': 'c', 'order': 1, 'next_try': 105}, {'nonce': 'a2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {}, 50), []), ('dead head skipped', ([{'nonce': 'd1', 'conv': 'c', 'order': 1, 'next_try': 999}, {'nonce': 'd2', 'conv': 'c', 'order': 2, 'next_try': 0}], [], {'d1': 6}, 10), ['d2']), ('due exactly now', ([{'nonce': 'e1', 'conv': 'k', 'order': 3, 'next_try': 45}], [], {}, 45), ['e1']), ('one tick early', ([{'nonce': 'f1', 'conv': 'k', 'order': 1, 'next_try': 41}], [], {}, 40), []), ('acked head', ([{'nonce': 'g1', 'conv': 'c', 'order': 2, 'next_try': 0}, {'nonce': 'g2', 'conv': 'c', 'order': 3, 'next_try': 0}], ['g1'], {}, 5), ['g2']), ('numeric order beyond nine', ([{'nonce': 'h10', 'conv': 'z', 'order': 10, 'next_try': 0}, {'nonce': 'h9', 'conv': 'z', 'order': 9, 'next_try': 0}], [], {}, 1), ['h9']), ('two conversations', ([{'nonce': 'q', 'conv': 'b', 'order': 1, 'next_try': 0}, {'nonce': 'p', 'conv': 'a', 'order': 1, 'next_try': 0}, {'nonce': 'r', 'conv': 'a', 'order': 2, 'next_try': 0}], [], {}, 5), ['p', 'q'])]}
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:
Retry counts are looked up per conversation instead of per message, so a dead message is never recognised and blocks the queue forever.

outbox items {nonce, conv, order, next_try}. Per conversation, messages are sent strictly in numeric `order`: the head is the lowest-order message that is neither acknowledged nor dead (failed attempts >= 5). Dead messages are skipped without blocking. The head is dispatched when next_try <= now; later messages always wait for it. Result: nonces to dispatch, by conversation id then order.

split: open-access