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

N = 1
observations = []
def solve(s):
    return {
        'ready': len(s['values'])>s['threshold'],
        'publish': s['depth']==0 and bool(s['values']) and (len(s['values'])>=s['threshold'] or s['flush'] or (s['final'] and s['partial'])),
        'head': s['values'][:s['threshold']],
        'tail': s['values'][s['threshold']:],
        'rollback': s['values'][:s['checkpoint']] if s['error'] else list(s['values']),
        'depth': max(0,s['depth']+int(s['begin'])-int(s['end'])),
        'partial_drop': s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold'],
        'new_checkpoint': len(s['values']) if s['begin'] else s['checkpoint'],
        'unmatched_end': s['end'] and s['depth']==0,
        'empty_flush': list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged'])),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 4, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': True, 'checkpoint': 3, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': True, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a'], 'threshold': 2, 'flush': True, 'depth': 3, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 4, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 2: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': False, 'publish': True, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': True, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': False, 'final': True, 'error': False, 'checkpoint': 6, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 5, 'partial_drop': False, 'new_checkpoint': 6, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 6, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': True, 'final': True, 'error': True, 'checkpoint': 6, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 3: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 6, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 6, 'flush': False, 'depth': 9, 'partial': True, 'final': False, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 6, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': True, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 12, 'flush': True, 'depth': 9, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 4: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 12, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': ['a'], 'threshold': 8, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 16, 'flush': True, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 16, 'flush': True, 'depth': 12, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 5: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 10, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 15, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 20, 'flush': True, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 15, 'partial_drop': True, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 16, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})]}
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 {
        'ready': bool(s['values']),
        'publish': s['depth']==0 and bool(s['values']) and (len(s['values'])>=s['threshold'] or s['flush'] or (s['final'] and s['partial'])),
        'head': s['values'][:s['threshold']],
        'tail': s['values'][s['threshold']:],
        'rollback': s['values'][:s['checkpoint']] if s['error'] else list(s['values']),
        'depth': max(0,s['depth']+int(s['begin'])-int(s['end'])),
        'partial_drop': s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold'],
        'new_checkpoint': len(s['values']) if s['begin'] else s['checkpoint'],
        'unmatched_end': s['end'] and s['depth']==0,
        'empty_flush': list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged'])),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 4, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': True, 'checkpoint': 3, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': True, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a'], 'threshold': 2, 'flush': True, 'depth': 3, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 4, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 2: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': False, 'publish': True, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': True, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': False, 'final': True, 'error': False, 'checkpoint': 6, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 5, 'partial_drop': False, 'new_checkpoint': 6, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 6, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': True, 'final': True, 'error': True, 'checkpoint': 6, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 3: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 6, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 6, 'flush': False, 'depth': 9, 'partial': True, 'final': False, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 6, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': True, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 12, 'flush': True, 'depth': 9, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 4: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 12, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': ['a'], 'threshold': 8, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 16, 'flush': True, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 16, 'flush': True, 'depth': 12, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 5: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 10, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 15, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 20, 'flush': True, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 15, 'partial_drop': True, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 16, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})]}
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:
Observer batches publish before their threshold is reached; the returned lifecycle plan violates the stated transition contract.

Plan batched observer publication. A batch holds until threshold or explicit flush, publishes at most threshold values, and preserves the unconsumed suffix. Nested batch scopes publish only at depth zero. An exception rolls back only the current batch checkpoint. Empty batches do not notify; a final partial batch publishes only when partial delivery is allowed. Acknowledgement notifications deduplicate pending batch IDs in first-occurrence order and exclude IDs already acknowledged. 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: ready = len(s['values'])>=s['threshold']; publish = s['depth']==0 and bool(s['values']) and (len(s['values'])>=s['threshold'] or s['flush'] or (s['final'] and s['partial'])); head = s['values'][:s['threshold']]; tail = s['values'][s['threshold']:]; rollback = s['values'][:s['checkpoint']] if s['error'] else list(s['values']); depth = max(0,s['depth']+int(s['begin'])-int(s['end'])); partial_drop = s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold']; new_checkpoint = len(s['values']) if s['begin'] else s['checkpoint']; unmatched_end = s['end'] and s['depth']==0; empty_flush = list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged']))

split: open-access


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

N = 1
observations = []
def solve(s):
    return {
        'ready': len(s['values'])>=s['threshold'],
        'publish': bool(s['values']) and (len(s['values'])>=s['threshold'] or s['flush']),
        'head': s['values'][:s['threshold']],
        'tail': s['values'][s['threshold']:],
        'rollback': s['values'][:s['checkpoint']] if s['error'] else list(s['values']),
        'depth': max(0,s['depth']+int(s['begin'])-int(s['end'])),
        'partial_drop': s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold'],
        'new_checkpoint': len(s['values']) if s['begin'] else s['checkpoint'],
        'unmatched_end': s['end'] and s['depth']==0,
        'empty_flush': list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged'])),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 4, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': True, 'checkpoint': 3, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': True, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a'], 'threshold': 2, 'flush': True, 'depth': 3, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 4, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 2: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': False, 'publish': True, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': True, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': False, 'final': True, 'error': False, 'checkpoint': 6, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 5, 'partial_drop': False, 'new_checkpoint': 6, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 6, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': True, 'final': True, 'error': True, 'checkpoint': 6, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 3: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 6, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 6, 'flush': False, 'depth': 9, 'partial': True, 'final': False, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 6, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': True, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 12, 'flush': True, 'depth': 9, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 4: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 12, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': ['a'], 'threshold': 8, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 16, 'flush': True, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 16, 'flush': True, 'depth': 12, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 5: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 10, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 15, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 20, 'flush': True, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 15, 'partial_drop': True, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 16, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})]}
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)

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(s):
    return {
        'ready': len(s['values'])>=s['threshold'],
        'publish': s['depth']==0 and (len(s['values'])>=s['threshold'] or s['flush']),
        'head': s['values'][:s['threshold']],
        'tail': s['values'][s['threshold']:],
        'rollback': s['values'][:s['checkpoint']] if s['error'] else list(s['values']),
        'depth': max(0,s['depth']+int(s['begin'])-int(s['end'])),
        'partial_drop': s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold'],
        'new_checkpoint': len(s['values']) if s['begin'] else s['checkpoint'],
        'unmatched_end': s['end'] and s['depth']==0,
        'empty_flush': list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged'])),
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 4, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': True, 'checkpoint': 3, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': True, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a'], 'threshold': 2, 'flush': True, 'depth': 3, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': True, 'depth': 3, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 4, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': True, 'depth': 3, 'partial': True, 'final': True, 'error': True, 'checkpoint': 3, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 3, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 2: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a', 'b', 'c'], 'threshold': 4, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': False, 'publish': True, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': True, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': False, 'final': True, 'error': False, 'checkpoint': 6, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 5, 'partial_drop': False, 'new_checkpoint': 6, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 6, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 6, 'partial': True, 'final': True, 'error': True, 'checkpoint': 6, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 6, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 3: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': True, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 6, 'flush': True, 'depth': 1, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': True, 'depth': 0, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 6, 'flush': False, 'depth': 9, 'partial': True, 'final': False, 'error': True, 'checkpoint': 9, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 9, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 6, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': True, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 12, 'flush': True, 'depth': 9, 'partial': True, 'final': True, 'error': True, 'checkpoint': 9, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 9, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 4: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 12, 'partial': False, 'final': True, 'error': True, 'checkpoint': 1, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b']}), ({'values': ['a'], 'threshold': 8, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 1, 'begin': False, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': [], 'threshold': 16, 'flush': True, 'depth': 1, 'partial': False, 'final': True, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': False, 'checkpoint': 0, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': ['a', 'b', 'c'], 'depth': 2, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a', 'b', 'c'], 'threshold': 8, 'flush': True, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 12, 'begin': False, 'end': True, 'batch_ids': [], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 12, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 16, 'flush': True, 'depth': 12, 'partial': True, 'final': True, 'error': True, 'checkpoint': 12, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 12, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})], 5: [({'values': ['a', 'b', 'c'], 'threshold': 1, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': []}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': ['b', 'c'], 'rollback': [], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['b', 'a']}), ({'values': ['a'], 'threshold': 10, 'flush': False, 'depth': 0, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': False, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['a']}, {'ready': False, 'publish': True, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 15, 'unmatched_end': True, 'empty_flush': []}), ({'values': ['a'], 'threshold': 1, 'flush': False, 'depth': 1, 'partial': True, 'final': False, 'error': True, 'checkpoint': 0, 'begin': True, 'end': True, 'batch_ids': [], 'acknowledged': ['a']}, {'ready': True, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': []}), ({'values': [], 'threshold': 20, 'flush': True, 'depth': 1, 'partial': False, 'final': False, 'error': False, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 1, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': False, 'depth': 15, 'partial': False, 'final': True, 'error': False, 'checkpoint': 1, 'begin': False, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 15, 'partial_drop': True, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': ['a'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': False, 'batch_ids': ['a'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a'], 'tail': [], 'rollback': ['a'], 'depth': 16, 'partial_drop': False, 'new_checkpoint': 1, 'unmatched_end': False, 'empty_flush': ['a']}), ({'values': [], 'threshold': 1, 'flush': False, 'depth': 0, 'partial': False, 'final': False, 'error': False, 'checkpoint': 0, 'begin': False, 'end': False, 'batch_ids': [], 'acknowledged': []}, {'ready': False, 'publish': False, 'head': [], 'tail': [], 'rollback': [], 'depth': 0, 'partial_drop': False, 'new_checkpoint': 0, 'unmatched_end': False, 'empty_flush': []}), ({'values': ['a', 'b', 'c'], 'threshold': 20, 'flush': True, 'depth': 15, 'partial': True, 'final': True, 'error': True, 'checkpoint': 15, 'begin': True, 'end': True, 'batch_ids': ['b', 'a', 'b'], 'acknowledged': ['b']}, {'ready': False, 'publish': False, 'head': ['a', 'b', 'c'], 'tail': [], 'rollback': ['a', 'b', 'c'], 'depth': 15, 'partial_drop': False, 'new_checkpoint': 3, 'unmatched_end': False, 'empty_flush': ['a']})]}
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:
Nested batching publishes an inner batch immediately; the returned lifecycle plan violates the stated transition contract.

Plan batched observer publication. A batch holds until threshold or explicit flush, publishes at most threshold values, and preserves the unconsumed suffix. Nested batch scopes publish only at depth zero. An exception rolls back only the current batch checkpoint. Empty batches do not notify; a final partial batch publishes only when partial delivery is allowed. Acknowledgement notifications deduplicate pending batch IDs in first-occurrence order and exclude IDs already acknowledged. 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: ready = len(s['values'])>=s['threshold']; publish = s['depth']==0 and bool(s['values']) and (len(s['values'])>=s['threshold'] or s['flush'] or (s['final'] and s['partial'])); head = s['values'][:s['threshold']]; tail = s['values'][s['threshold']:]; rollback = s['values'][:s['checkpoint']] if s['error'] else list(s['values']); depth = max(0,s['depth']+int(s['begin'])-int(s['end'])); partial_drop = s['final'] and not s['partial'] and 0<len(s['values'])<s['threshold']; new_checkpoint = len(s['values']) if s['begin'] else s['checkpoint']; unmatched_end = s['end'] and s['depth']==0; empty_flush = list(dict.fromkeys(x for x in s['batch_ids'] if x not in s['acknowledged']))

split: open-access