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

N = 1
observations = []
def solve(s):
    return {
        'payload': list(s['payload']),
        'headers': dict(s['headers']),
        'origin': next((r[0] for r in s['hops'] if not r[1]),None),
        'correlation': next((r[1] for r in reversed(s['correlation_scopes']) if r[0]),None),
        'sequence': [s['epoch']+(s['counter']+1)//s['modulus'],(s['counter']+1)%s['modulus']],
        'index': [[r[0],i] for i,r in enumerate(r for r in s['slots'] if r[1])],
        'timestamp': s['timestamp'],
        'secret': None if s['redact'] else s['secret'],
        'cancelled': s['frame_flags'].get(s['frame'],False),
        'public_count': sum(not k.startswith('_') for k in s['headers']),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 4, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 2, 'counter': 7, 'modulus': 3, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [4, 2], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 0, 'modulus': 3, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [0, 1], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 0, 'index': 2, 'timestamp': 5, 'now': 2, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 7, 'modulus': 5, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 3], 'index': [['a', 0], ['c', 1]], 'timestamp': 5, 'secret': None, 'cancelled': True, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': 'trace', 'sequence': 4, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [], 'epoch': 2, 'counter': 2, 'modulus': 3, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [3, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 4, 'index': 0, 'timestamp': 5, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 7, 'modulus': 3, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [2, 2], 'index': [], 'timestamp': 5, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 5, 'now': 2, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 0], 'index': [], 'timestamp': 5, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 2, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 4, 'index': 2, 'timestamp': 5, 'now': 9, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 2, 'counter': 7, 'modulus': 5, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [3, 3], 'index': [['a', 0], ['c', 1]], 'timestamp': 5, 'secret': None, 'cancelled': False, 'public_count': 0})], 2: [({'payload': [0, 1, 4], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 8, 'index': 4, 'timestamp': 0, 'now': 4, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 4, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [5, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 4], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 4, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [5, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 8, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 4, 'counter': 14, 'modulus': 6, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [6, 3], 'index': [], 'timestamp': 10, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 10, 'now': 4, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 4, 'counter': 14, 'modulus': 10, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [5, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 0, 'index': 4, 'timestamp': 0, 'now': 18, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [], 'epoch': 4, 'counter': 4, 'modulus': 10, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [4, 5], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': 'trace', 'sequence': 8, 'index': 0, 'timestamp': 0, 'now': 18, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 14, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [15, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 4, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 8, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 4, 'counter': 14, 'modulus': 10, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [5, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': None, 'cancelled': False, 'public_count': 0})], 3: [({'payload': [0, 1, 6], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 6, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 21, 'modulus': 9, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 6], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [2, 4], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 6, 'timestamp': 0, 'now': 27, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'inner', 'sequence': [1, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 6], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 15, 'now': 6, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 6, 'modulus': 15, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 6], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [6, 7], 'index': [['b', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 12, 'index': 0, 'timestamp': 15, 'now': 6, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [], 'epoch': 0, 'counter': 21, 'modulus': 9, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [2, 4], 'index': [['b', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 6], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 12, 'index': 6, 'timestamp': 15, 'now': 27, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 6, 'counter': 21, 'modulus': 9, 'slots': [], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 6], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': [8, 4], 'index': [], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 12, 'index': 0, 'timestamp': 15, 'now': 27, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 6, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [13, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 6, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 6], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 12, 'index': 6, 'timestamp': 15, 'now': 27, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 21, 'modulus': 15, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 6], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [7, 7], 'index': [['a', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 0})], 4: [({'payload': [0, 1, 8], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 16, 'index': 8, 'timestamp': 0, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 8, 'counter': 28, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [37, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': True, 'public_count': 2}), ({'payload': [0, 1, 8], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 16, 'index': 0, 'timestamp': 0, 'now': 8, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 8, 'modulus': 20, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [8, 9], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 16, 'index': 0, 'timestamp': 0, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 8, 'counter': 0, 'modulus': 12, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [8, 1], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 36, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 28, 'modulus': 12, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [10, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 8, 'timestamp': 20, 'now': 36, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 8, 'modulus': 20, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [8, 9], 'index': [['b', 0], ['c', 1]], 'timestamp': 20, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 8, 'timestamp': 0, 'now': 8, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 8, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [9, 0], 'index': [], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 8, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 16, 'index': 8, 'timestamp': 20, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 28, 'modulus': 20, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [9, 9], 'index': [['a', 0], ['c', 1]], 'timestamp': 20, 'secret': None, 'cancelled': False, 'public_count': 0})], 5: [({'payload': [0, 1, 10], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 10, 'timestamp': 0, 'now': 10, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 10, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [11, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 20, 'index': 0, 'timestamp': 25, 'now': 10, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 35, 'modulus': 25, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 11], 'index': [], 'timestamp': 25, 'secret': 'hidden', 'cancelled': True, 'public_count': 2}), ({'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 45, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 10, 'counter': 35, 'modulus': 15, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [12, 6], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 20, 'index': 10, 'timestamp': 25, 'now': 10, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 10, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [11, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 25, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 10, 'timestamp': 0, 'now': 10, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 20, 'index': 10, 'timestamp': 0, 'now': 45, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [], 'epoch': 0, 'counter': 35, 'modulus': 25, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 11], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 10, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 20, 'index': 10, 'timestamp': 25, 'now': 45, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 10, 'counter': 35, 'modulus': 25, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [11, 11], 'index': [['a', 0], ['c', 1]], 'timestamp': 25, 'secret': None, 'cancelled': False, 'public_count': 0})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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(s):
    return {
        'payload': list(s['payload']),
        'headers': {k:v for k,v in s['headers'].items() if '_' not in k},
        'origin': next((r[0] for r in s['hops'] if not r[1]),None),
        'correlation': next((r[1] for r in reversed(s['correlation_scopes']) if r[0]),None),
        'sequence': [s['epoch']+(s['counter']+1)//s['modulus'],(s['counter']+1)%s['modulus']],
        'index': [[r[0],i] for i,r in enumerate(r for r in s['slots'] if r[1])],
        'timestamp': s['timestamp'],
        'secret': None if s['redact'] else s['secret'],
        'cancelled': s['frame_flags'].get(s['frame'],False),
        'public_count': sum(not k.startswith('_') for k in s['headers']),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 4, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 2, 'counter': 7, 'modulus': 3, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [4, 2], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 0, 'modulus': 3, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [0, 1], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 0, 'index': 2, 'timestamp': 5, 'now': 2, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 7, 'modulus': 5, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 3], 'index': [['a', 0], ['c', 1]], 'timestamp': 5, 'secret': None, 'cancelled': True, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': 'trace', 'sequence': 4, 'index': 0, 'timestamp': 0, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [], 'epoch': 2, 'counter': 2, 'modulus': 3, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [3, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 4, 'index': 0, 'timestamp': 5, 'now': 9, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 7, 'modulus': 3, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [2, 2], 'index': [], 'timestamp': 5, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 5, 'now': 2, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 2], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 0], 'index': [], 'timestamp': 5, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 2, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 2], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 4, 'index': 2, 'timestamp': 5, 'now': 9, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 2, 'counter': 7, 'modulus': 5, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 2], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [3, 3], 'index': [['a', 0], ['c', 1]], 'timestamp': 5, 'secret': None, 'cancelled': False, 'public_count': 0})], 2: [({'payload': [0, 1, 4], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 8, 'index': 4, 'timestamp': 0, 'now': 4, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 4, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [5, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 4], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 4, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [5, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 8, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 4, 'counter': 14, 'modulus': 6, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [6, 3], 'index': [], 'timestamp': 10, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 10, 'now': 4, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 4, 'counter': 14, 'modulus': 10, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [5, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 0, 'index': 4, 'timestamp': 0, 'now': 18, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [], 'epoch': 4, 'counter': 4, 'modulus': 10, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [4, 5], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': 'trace', 'sequence': 8, 'index': 0, 'timestamp': 0, 'now': 18, 'secret': 'hidden', 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 14, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [], 'headers': {}, 'origin': 'source', 'correlation': None, 'sequence': [15, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 4, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 4], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 8, 'index': 4, 'timestamp': 10, 'now': 18, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 4, 'counter': 14, 'modulus': 10, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 4], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [5, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 10, 'secret': None, 'cancelled': False, 'public_count': 0})], 3: [({'payload': [0, 1, 6], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 6, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 21, 'modulus': 9, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 6], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [2, 4], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 6, 'timestamp': 0, 'now': 27, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'inner', 'sequence': [1, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 6], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 15, 'now': 6, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 6, 'modulus': 15, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 6], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [6, 7], 'index': [['b', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 12, 'index': 0, 'timestamp': 15, 'now': 6, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [], 'epoch': 0, 'counter': 21, 'modulus': 9, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [2, 4], 'index': [['b', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 6], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 12, 'index': 6, 'timestamp': 15, 'now': 27, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 6, 'counter': 21, 'modulus': 9, 'slots': [], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 6], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': [8, 4], 'index': [], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 12, 'index': 0, 'timestamp': 15, 'now': 27, 'secret': None, 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 6, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': True, 'inner': False}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [13, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 6, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 6], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 12, 'index': 6, 'timestamp': 15, 'now': 27, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 6, 'counter': 21, 'modulus': 15, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 6], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [7, 7], 'index': [['a', 0], ['c', 1]], 'timestamp': 15, 'secret': None, 'cancelled': False, 'public_count': 0})], 4: [({'payload': [0, 1, 8], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': 16, 'index': 8, 'timestamp': 0, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 8, 'counter': 28, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [37, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': True, 'public_count': 2}), ({'payload': [0, 1, 8], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 16, 'index': 0, 'timestamp': 0, 'now': 8, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 8, 'modulus': 20, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [8, 9], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 2}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 16, 'index': 0, 'timestamp': 0, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 8, 'counter': 0, 'modulus': 12, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [8, 1], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 36, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 28, 'modulus': 12, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [10, 5], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 8, 'timestamp': 20, 'now': 36, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 8, 'modulus': 20, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [8, 9], 'index': [['b', 0], ['c', 1]], 'timestamp': 20, 'secret': None, 'cancelled': True, 'public_count': 0}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 8, 'timestamp': 0, 'now': 8, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 8, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [9, 0], 'index': [], 'timestamp': 0, 'secret': 'hidden', 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 8, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 8], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 16, 'index': 8, 'timestamp': 20, 'now': 36, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 8, 'counter': 28, 'modulus': 20, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 8], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [9, 9], 'index': [['a', 0], ['c', 1]], 'timestamp': 20, 'secret': None, 'cancelled': False, 'public_count': 0})], 5: [({'payload': [0, 1, 10], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 0, 'index': 10, 'timestamp': 0, 'now': 10, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 0, 'counter': 10, 'modulus': 1, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': [11, 0], 'index': [['a', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': None, 'sequence': 20, 'index': 0, 'timestamp': 25, 'now': 10, 'secret': 'hidden', 'redact': False, 'cancelled': True, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 0, 'counter': 35, 'modulus': 25, 'slots': [], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': 'inner', 'sequence': [1, 11], 'index': [], 'timestamp': 25, 'secret': 'hidden', 'cancelled': True, 'public_count': 2}), ({'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 45, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['proxy', True], ['source', False], ['relay', False]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 10, 'counter': 35, 'modulus': 15, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'missing'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': 'source', 'correlation': 'inner', 'sequence': [12, 6], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 20, 'index': 10, 'timestamp': 25, 'now': 10, 'secret': None, 'redact': True, 'cancelled': False, 'outer_cancel': False, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [True, None]], 'epoch': 10, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [11, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 25, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {'public': 'x', '_internal': 'y', 'mid_key': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 0, 'index': 10, 'timestamp': 0, 'now': 10, 'secret': 'hidden', 'redact': True, 'cancelled': False, 'outer_cancel': True, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [0, 1, 10], 'headers': {'public': 'x', 'mid_key': 'z'}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 2}), ({'payload': [], 'headers': {'_only': 'z'}, 'origin': None, 'correlation': 'trace', 'sequence': 20, 'index': 10, 'timestamp': 0, 'now': 45, 'secret': None, 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [], 'epoch': 0, 'counter': 35, 'modulus': 25, 'slots': [['a', False], ['b', True], ['c', True]], 'frame_flags': {}, 'frame': 'missing', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 11], 'index': [['b', 0], ['c', 1]], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': 0, 'index': 0, 'timestamp': 0, 'now': 10, 'secret': None, 'redact': False, 'cancelled': False, 'outer_cancel': False, 'hops': [], 'correlation_scopes': [], 'epoch': 0, 'counter': 0, 'modulus': 1, 'slots': [], 'frame_flags': {}, 'frame': 'inner', 'parent_frame': 'outer'}, {'payload': [], 'headers': {}, 'origin': None, 'correlation': None, 'sequence': [1, 0], 'index': [], 'timestamp': 0, 'secret': None, 'cancelled': False, 'public_count': 0}), ({'payload': [0, 1, 10], 'headers': {'_only': 'z'}, 'origin': 'source', 'correlation': 'trace', 'sequence': 20, 'index': 10, 'timestamp': 25, 'now': 45, 'secret': 'hidden', 'redact': True, 'cancelled': True, 'outer_cancel': True, 'hops': [['only', True]], 'correlation_scopes': [[True, 'outer'], [False, 'stale'], [True, 'inner']], 'epoch': 10, 'counter': 35, 'modulus': 25, 'slots': [['a', True], ['b', False], ['c', True]], 'frame_flags': {'outer': False, 'inner': True}, 'frame': 'missing', 'parent_frame': 'missing'}, {'payload': [0, 1, 10], 'headers': {}, 'origin': None, 'correlation': 'inner', 'sequence': [11, 11], 'index': [['a', 0], ['c', 1]], 'timestamp': 25, 'secret': None, 'cancelled': False, 'public_count': 0})]}
for i,(state,expected) in enumerate(fixtures[N]):
    check("transition "+str(i), solve(state), 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:
Private observer envelope headers escape to callbacks; the returned lifecycle plan violates the stated transition contract.

Copy an observer event envelope according to this finite contract: payload list is copied, headers are copied with private keys removed, origin and correlation are preserved independently, callback index does not replace event sequence, cancellation flags are frame-local, and a redacted event drops only its secret field. Event timestamp zero is valid. These are value-copy semantics, not object identity tests. Origin resolution scans [identity,is_proxy] hops and takes the first nonproxy identity; proxy-only paths have no origin. Correlation scopes are outer-to-inner [explicitly_bound,value]. The innermost explicit binding wins, including None. Increment the epoch/counter sequence and normalize arbitrary recovered counter overflow using the positive modulus. Public invocation positions are zero-based among enabled [callback_id,enabled] slots, not physical registry indices. Read cancellation by exact current frame identity; missing frame flags default false. Inputs are finite state snapshots, including transitional and stale states; output fields are the exact independent actions/metadata defined by the corrected expression table. Numeric fixture capacities and counts vary with N.
Field definitions, each independently computed from the input snapshot: payload = list(s['payload']); headers = {k:v for k,v in s['headers'].items() if not k.startswith('_')}; origin = next((r[0] for r in s['hops'] if not r[1]),None); correlation = next((r[1] for r in reversed(s['correlation_scopes']) if r[0]),None); sequence = [s['epoch']+(s['counter']+1)//s['modulus'],(s['counter']+1)%s['modulus']]; index = [[r[0],i] for i,r in enumerate(r for r in s['slots'] if r[1])]; timestamp = s['timestamp']; secret = None if s['redact'] else s['secret']; cancelled = s['frame_flags'].get(s['frame'],False); public_count = sum(not k.startswith('_') for k in s['headers'])

split: open-access