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'])
            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:
                continue
            if m['next_try'] <= now + 1:
                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:
A retry scheduled for exactly now waits an extra tick.

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:
                break
            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)

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(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 and m['order'] == 1:
                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:
An acknowledged message still counts as the queue head and stalls the conversation.

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: str(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)

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['nonce']):
            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:
After nine queued messages the tenth is dispatched before the ninth.

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(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq != best.get(conv):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > sent_markers.get(c, -1)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, 0):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > sent_markers.get(c, -1)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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 last scroll event wins, so a lower receipt is sent after a higher one was generated.

pending_reads are [conv, seq] events produced while scrolling, in any order. Per conversation only the highest seq is sent, and only if it is above the marker already sent (missing marker means nothing sent, -1). In the background nothing is sent: the eligible conversations are deferred. Result {send: [[conv, seq]...] sorted by conv, defer: [conv...]}.

split: open-access


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

N = 1
observations = []
def solve(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s != sent_markers.get(c, -1)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s >= sent_markers.get(c, -1)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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:
Receipts at or below the marker already sent are transmitted again.

pending_reads are [conv, seq] events produced while scrolling, in any order. Per conversation only the highest seq is sent, and only if it is above the marker already sent (missing marker means nothing sent, -1). In the background nothing is sent: the eligible conversations are deferred. Result {send: [[conv, seq]...] sorted by conv, defer: [conv...]}.

split: open-access


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

N = 1
observations = []
def solve(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > sent_markers.get(c, 0)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > (sent_markers.get(c) or 0)]
    if not foreground:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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 conversation that never sent a receipt suppresses the receipt for its seq-zero message.

pending_reads are [conv, seq] events produced while scrolling, in any order. Per conversation only the highest seq is sent, and only if it is above the marker already sent (missing marker means nothing sent, -1). In the background nothing is sent: the eligible conversations are deferred. Result {send: [[conv, seq]...] sorted by conv, defer: [conv...]}.

split: open-access


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

N = 1
observations = []
def solve(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > sent_markers.get(c, -1)]
    if not foreground and not rows:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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(pending_reads, sent_markers, foreground):
    best = {}
    for conv, seq in pending_reads:
        if seq > best.get(conv, -1):
            best[conv] = seq
    rows = [[c, s] for c, s in sorted(best.items()) if s > sent_markers.get(c, -1)]
    if not foreground and len(rows) > 1:
        return {'send': [], 'defer': [c for c, _ in rows]}
    return {'send': rows, 'defer': []}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('scroll events out of order', ([['a', 10], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 10], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 8]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 8]]}), ('lower than sent', ([['a', 2]], {'a': 7}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 2]], {'b': 2}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 2: [('scroll events out of order', ([['a', 11], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 11], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 9]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 9]]}), ('lower than sent', ([['a', 2]], {'a': 8}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 3]], {'b': 3}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 3: [('scroll events out of order', ([['a', 12], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 12], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 10]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 10]]}), ('lower than sent', ([['a', 2]], {'a': 9}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 4]], {'b': 4}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 4: [('scroll events out of order', ([['a', 13], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 13], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 11]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 11]]}), ('lower than sent', ([['a', 2]], {'a': 10}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 5]], {'b': 5}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})], 5: [('scroll events out of order', ([['a', 14], ['a', 4], ['b', 2]], {}, True), {'defer': [], 'send': [['a', 14], ['b', 2]]}), ('first message has seq zero', ([['n', 0]], {}, True), {'defer': [], 'send': [['n', 0]]}), ('not advancing', ([['a', 5], ['b', 12]], {'a': 5, 'b': 3}, True), {'defer': [], 'send': [['b', 12]]}), ('lower than sent', ([['a', 2]], {'a': 11}, True), {'defer': [], 'send': []}), ('background defers', ([['a', 3], ['b', 6]], {'b': 6}, False), {'defer': ['a'], 'send': []}), ('empty', ([], {'a': 1}, True), {'defer': [], 'send': []})]}
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:
Receipts are sent while the app is in the background, exposing activity the user has not seen.

pending_reads are [conv, seq] events produced while scrolling, in any order. Per conversation only the highest seq is sent, and only if it is above the marker already sent (missing marker means nothing sent, -1). In the background nothing is sent: the eligible conversations are deferred. Result {send: [[conv, seq]...] sorted by conv, defer: [conv...]}.

split: open-access


prompt:
A reader whose marker sits exactly on a message is shown under the previous message.

messages are ascending [seq, author] of the visible window. reads maps user -> [read_seq, read_at]. Each user other than me gets an avatar under the latest visible message with seq <= read_seq; users whose read_seq is before the first visible message get none. Avatars under one message are ordered by read_at descending, then user id. Result: [[seq, [users...]]...] by seq.

split: open-access


prompt:
A reader who has not reached the loaded window is shown under the newest message.

messages are ascending [seq, author] of the visible window. reads maps user -> [read_seq, read_at]. Each user other than me gets an avatar under the latest visible message with seq <= read_seq; users whose read_seq is before the first visible message get none. Avatars under one message are ordered by read_at descending, then user id. Result: [[seq, [users...]]...] by seq.

split: open-access


prompt:
Avatars under a message are sorted by user id instead of most recent reader first.

messages are ascending [seq, author] of the visible window. reads maps user -> [read_seq, read_at]. Each user other than me gets an avatar under the latest visible message with seq <= read_seq; users whose read_seq is before the first visible message get none. Avatars under one message are ordered by read_at descending, then user id. Result: [[seq, [users...]]...] by seq.

split: open-access


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

N = 1
observations = []
def solve(messages, root):
    replies = sorted((m for m in messages if (m['root'] == root or m['seq'] == root) and not m['deleted']), key=lambda m: m['seq'])
    seen = []
    for m in replies:
        if m['author'] not in seen:
            seen.append(m['author'])
    return {'count': len(replies), 'faces': seen[:3], 'more': max(0, len(seen) - 3),
            'last': replies[-1]['seq'] if replies else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 10, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 10, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u4', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u0', 'u1'], 'last': 19, 'more': 2}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 2: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 11, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 11, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u0'], 'last': 19, 'more': 3}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 3: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 12, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 12, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 6, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u5', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 4}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 4: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 13, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 13, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 7, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u3', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 5}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 5: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 14, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 14, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 8, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 6}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})]}
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, root):
    replies = sorted((m for m in messages if m['root'] in (root, None) and not m['deleted']), key=lambda m: m['seq'])
    seen = []
    for m in replies:
        if m['author'] not in seen:
            seen.append(m['author'])
    return {'count': len(replies), 'faces': seen[:3], 'more': max(0, len(seen) - 3),
            'last': replies[-1]['seq'] if replies else None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 10, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 10, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u4', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u0', 'u1'], 'last': 19, 'more': 2}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 2: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 11, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 11, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u0'], 'last': 19, 'more': 3}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 3: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 12, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 12, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 6, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u5', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 4}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 4: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 13, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 13, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 7, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u3', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 5}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})], 5: [('root is not a reply', ([{'seq': 5, 'root': None, 'author': 'al', 'deleted': False}, {'seq': 6, 'root': 5, 'author': 'bo', 'deleted': False}, {'seq': 7, 'root': None, 'author': 'cy', 'deleted': False}], 5), {'count': 1, 'faces': ['bo'], 'last': 6, 'more': 0}), ('reply order by seq', ([{'seq': 14, 'root': 1, 'author': 'zed', 'deleted': False}, {'seq': 3, 'root': 1, 'author': 'amy', 'deleted': False}, {'seq': 4, 'root': 1, 'author': 'kim', 'deleted': False}], 1), {'count': 3, 'faces': ['amy', 'kim', 'zed'], 'last': 14, 'more': 0}), ('few authors', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('newest reply deleted', ([{'seq': 2, 'root': 1, 'author': 'a', 'deleted': False}, {'seq': 8, 'root': 1, 'author': 'b', 'deleted': True}], 1), {'count': 1, 'faces': ['a'], 'last': 2, 'more': 0}), ('alternating authors', ([{'seq': 1, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 2, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 3, 'root': 0, 'author': 'b', 'deleted': False}, {'seq': 4, 'root': 0, 'author': 'a', 'deleted': False}, {'seq': 5, 'root': 0, 'author': 'b', 'deleted': False}], 0), {'count': 5, 'faces': ['b', 'a'], 'last': 5, 'more': 0}), ('many authors', ([{'seq': 4, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 5, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 6, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 7, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 8, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 9, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 10, 'root': 3, 'author': 'u1', 'deleted': False}, {'seq': 11, 'root': 3, 'author': 'u2', 'deleted': False}, {'seq': 12, 'root': 3, 'author': 'u3', 'deleted': False}, {'seq': 13, 'root': 3, 'author': 'u4', 'deleted': False}, {'seq': 14, 'root': 3, 'author': 'u5', 'deleted': False}, {'seq': 15, 'root': 3, 'author': 'u6', 'deleted': False}, {'seq': 16, 'root': 3, 'author': 'u7', 'deleted': False}, {'seq': 17, 'root': 3, 'author': 'u8', 'deleted': False}, {'seq': 18, 'root': 3, 'author': 'u0', 'deleted': False}, {'seq': 19, 'root': 3, 'author': 'u1', 'deleted': False}], 3), {'count': 16, 'faces': ['u4', 'u5', 'u6'], 'last': 19, 'more': 6}), ('no replies', ([{'seq': 1, 'root': None, 'author': 'a', 'deleted': False}], 1), {'count': 0, 'faces': [], 'last': None, 'more': 0})]}
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 root message is counted as one of its own replies.

messages {seq, root, author, deleted}; replies of a thread have root equal to the root seq (the root itself has root None). Deleted replies are ignored. Result {count, faces: first three distinct reply authors in order of their first reply, more: number of further distinct authors, last: seq of the newest reply or None}.

split: open-access