FAILURE MAP
← Case archive

FA-41931 / Listener lifecycle / Open access

A terminated replay source acquires a live subscription · case 01

A terminated replay source acquires a live subscription; the returned lifecycle plan violates the stated transition contract.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The attach_live decision in the replay-subscribe listener model is computed as not s['subscribed'], losing a required lifecycle condition.

VERIFIED REPAIR

Compute the attach_live decision from the complete contract: not s['subscribed'] and s['terminal'] is None and not s['cancel'].

Unsuccessful approach: The partial repair uses not s['subscribed'] and not s['cancel']; a retained regression distinguishes it from the full transition.

Case contract

Plan a subscription to a bounded replay observer. History entries are [sequence,value]; deliver entries strictly after cursor, in stored order, capped by demand. Subscriber replay is suppressed after cancellation. A terminal marker follows replay only when requested. A gap exists if the cursor precedes the oldest retained predecessor. Live events stay deferred until replay completes. 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: eligible = [r for r in s['history'] if r[0]>s['cursor']]; values = [r[1] for r in s['history'] if r[0]>s['cursor']][:s['demand']] if not s['cancel'] else []; gap = bool(s['history']) and s['cursor']<s['history'][0][0]-1; terminal = s['terminal'] if s['want_terminal'] and not s['cancel'] and not s['replaying'] else None; live = list(s['live']) if not s['replaying'] and not s['cancel'] else []; deferred = list(s['live']) if s['replaying'] and not s['cancel'] else []; cursor = max([s['cursor']]+[r[0] for r in s['history'] if r[0]>s['cursor']][:s['demand']]); remaining = max(0,s['demand']-len([r for r in s['history'] if r[0]>s['cursor']])); attach_live = not s['subscribed'] and s['terminal'] is None and not s['cancel']; history_order = [r[0] for r in s['history']]

Why this case matters

Observer implementations need to preserve this state while subscriptions enter, execute, and leave their lifecycle.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    return {
        'eligible': [r for r in s['history'] if r[0]>s['cursor']],
        'values': [r[1] for r in s['history'] if r[0]>s['cursor']][:s['demand']] if not s['cancel'] else [],
        'gap': bool(s['history']) and s['cursor']<s['history'][0][0]-1,
        'terminal': s['terminal'] if s['want_terminal'] and not s['cancel'] and not s['replaying'] else None,
        'live': list(s['live']) if not s['replaying'] and not s['cancel'] else [],
        'deferred': list(s['live']) if s['replaying'] and not s['cancel'] else [],
        'cursor': max([s['cursor']]+[r[0] for r in s['history'] if r[0]>s['cursor']][:s['demand']]),
        'remaining': max(0,s['demand']-len([r for r in s['history'] if r[0]>s['cursor']])),
        'attach_live': not s['subscribed'],
        'history_order': [r[0] for r in s['history']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 1, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 2, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': [], 'last': 4, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 3, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 1, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a']], 'cursor': 3, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 3, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 3, 'attach_live': False, 'history_order': [1, 3, 4]})], 2: [({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': False}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 6, 'demand': 8, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 8, 'remaining': 7, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': [], 'last': 8, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 6, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 6, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []})], 3: [({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': False}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 1, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [[9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 9, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': True}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]})], 4: [({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': [], 'last': 16, 'subscribed': True}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 1, 'demand': 16, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[12, 'b'], [16, 'c']], 'values': ['b', 'c'], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 16, 'remaining': 14, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 16, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]})], 5: [({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': False}, {'eligible': [[15, 'b'], [20, 'c']], 'values': ['b'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': [], 'last': 20, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': 'complete', 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 20, 'subscribed': True}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': ['a', 'b', 'c'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 15, 'demand': 20, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [[20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 19, 'attach_live': False, 'history_order': [1, 15, 20]})]}
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)
Boundary fixtureActualExpectedOutcome
transition 0{'attach_live': True, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}{'attach_live': False, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}Failed
transition 1{'attach_live': True, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}Failed
transition 2{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 3{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Failed
transition 4{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Passed
transition 5{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 6{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 7{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}Passed

SHA-256 / 8aea8cd9e1930a0ab51cf468e5d16acf613d9579ac0276f5762ea33c77920931

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    return {
        'eligible': [r for r in s['history'] if r[0]>s['cursor']],
        'values': [r[1] for r in s['history'] if r[0]>s['cursor']][:s['demand']] if not s['cancel'] else [],
        'gap': bool(s['history']) and s['cursor']<s['history'][0][0]-1,
        'terminal': s['terminal'] if s['want_terminal'] and not s['cancel'] and not s['replaying'] else None,
        'live': list(s['live']) if not s['replaying'] and not s['cancel'] else [],
        'deferred': list(s['live']) if s['replaying'] and not s['cancel'] else [],
        'cursor': max([s['cursor']]+[r[0] for r in s['history'] if r[0]>s['cursor']][:s['demand']]),
        'remaining': max(0,s['demand']-len([r for r in s['history'] if r[0]>s['cursor']])),
        'attach_live': not s['subscribed'] and not s['cancel'],
        'history_order': [r[0] for r in s['history']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 1, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 2, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': [], 'last': 4, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 3, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 1, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a']], 'cursor': 3, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 3, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 3, 'attach_live': False, 'history_order': [1, 3, 4]})], 2: [({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': False}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 6, 'demand': 8, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 8, 'remaining': 7, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': [], 'last': 8, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 6, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 6, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []})], 3: [({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': False}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 1, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [[9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 9, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': True}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]})], 4: [({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': [], 'last': 16, 'subscribed': True}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 1, 'demand': 16, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[12, 'b'], [16, 'c']], 'values': ['b', 'c'], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 16, 'remaining': 14, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 16, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]})], 5: [({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': False}, {'eligible': [[15, 'b'], [20, 'c']], 'values': ['b'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': [], 'last': 20, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': 'complete', 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 20, 'subscribed': True}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': ['a', 'b', 'c'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 15, 'demand': 20, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [[20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 19, 'attach_live': False, 'history_order': [1, 15, 20]})]}
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)
Boundary fixtureActualExpectedOutcome
transition 0{'attach_live': True, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}{'attach_live': False, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}Failed
transition 1{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}Passed
transition 2{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 3{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Passed
transition 4{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Passed
transition 5{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 6{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 7{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}Passed

SHA-256 / 27856720ed936f7e96e8a732ca01879920dd5ce9348b83da38ca7dd280446c25

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(s):
    return {
        'eligible': [r for r in s['history'] if r[0]>s['cursor']],
        'values': [r[1] for r in s['history'] if r[0]>s['cursor']][:s['demand']] if not s['cancel'] else [],
        'gap': bool(s['history']) and s['cursor']<s['history'][0][0]-1,
        'terminal': s['terminal'] if s['want_terminal'] and not s['cancel'] and not s['replaying'] else None,
        'live': list(s['live']) if not s['replaying'] and not s['cancel'] else [],
        'deferred': list(s['live']) if s['replaying'] and not s['cancel'] else [],
        'cursor': max([s['cursor']]+[r[0] for r in s['history'] if r[0]>s['cursor']][:s['demand']]),
        'remaining': max(0,s['demand']-len([r for r in s['history'] if r[0]>s['cursor']])),
        'attach_live': not s['subscribed'] and s['terminal'] is None and not s['cancel'],
        'history_order': [r[0] for r in s['history']],
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 1, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': False}, {'eligible': [[3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 2, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 3, 4]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': [], 'last': 4, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 3, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 1, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a']], 'cursor': 3, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 3, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [3, 'b'], [4, 'c']], 'cursor': 3, 'demand': 4, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 4, 'subscribed': True}, {'eligible': [[4, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 4, 'remaining': 3, 'attach_live': False, 'history_order': [1, 3, 4]})], 2: [({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': False}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 6, 'demand': 8, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 8, 'remaining': 7, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': [], 'last': 8, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [6, 'b'], [8, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 8, 'subscribed': True}, {'eligible': [[1, 'a'], [6, 'b'], [8, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 6, 8]}), ({'history': [], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 1, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 6, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': [], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 6, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []})], 3: [({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': False}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a']], 'cursor': 0, 'demand': 1, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[1, 'a'], [9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 1, 'demand': 1, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [[9, 'b'], [12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 9, 'remaining': 0, 'attach_live': False, 'history_order': [1, 9, 12]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [9, 'b'], [12, 'c']], 'cursor': 9, 'demand': 12, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 12, 'subscribed': True}, {'eligible': [[12, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 12, 'remaining': 11, 'attach_live': False, 'history_order': [1, 9, 12]})], 4: [({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': [], 'last': 16, 'subscribed': True}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': ['a'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 1, 'demand': 16, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [[12, 'b'], [16, 'c']], 'values': ['b', 'c'], 'gap': False, 'terminal': 'complete', 'live': ['live'], 'deferred': [], 'cursor': 16, 'remaining': 14, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': ['live'], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 0, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': False, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [12, 'b'], [16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': False, 'history_order': [1, 12, 16]}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [12, 'b'], [16, 'c']], 'cursor': 12, 'demand': 16, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 16, 'subscribed': True}, {'eligible': [[16, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 16, 'remaining': 15, 'attach_live': False, 'history_order': [1, 12, 16]})], 5: [({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': False}, {'eligible': [[15, 'b'], [20, 'c']], 'values': ['b'], 'gap': False, 'terminal': None, 'live': [], 'deferred': ['live'], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': True, 'terminal': None, 'want_terminal': False, 'replaying': True, 'live': ['live'], 'last': 0, 'subscribed': False}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 1, 'demand': 1, 'cancel': False, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': [], 'last': 20, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': 'complete', 'live': [], 'deferred': [], 'cursor': 1, 'remaining': 1, 'attach_live': False, 'history_order': [1]}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 0, 'demand': 20, 'cancel': False, 'terminal': None, 'want_terminal': True, 'replaying': True, 'live': [], 'last': 20, 'subscribed': True}, {'eligible': [[1, 'a'], [15, 'b'], [20, 'c']], 'values': ['a', 'b', 'c'], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 17, 'attach_live': False, 'history_order': [1, 15, 20]}), ({'history': [[1, 'a']], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 0, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': [1]}), ({'history': [], 'cursor': 15, 'demand': 0, 'cancel': True, 'terminal': None, 'want_terminal': True, 'replaying': False, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 15, 'remaining': 0, 'attach_live': False, 'history_order': []}), ({'history': [], 'cursor': 0, 'demand': 0, 'cancel': False, 'terminal': None, 'want_terminal': False, 'replaying': False, 'live': [], 'last': 0, 'subscribed': False}, {'eligible': [], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 0, 'remaining': 0, 'attach_live': True, 'history_order': []}), ({'history': [[1, 'a'], [15, 'b'], [20, 'c']], 'cursor': 15, 'demand': 20, 'cancel': True, 'terminal': 'complete', 'want_terminal': True, 'replaying': True, 'live': ['live'], 'last': 20, 'subscribed': True}, {'eligible': [[20, 'c']], 'values': [], 'gap': False, 'terminal': None, 'live': [], 'deferred': [], 'cursor': 20, 'remaining': 19, 'attach_live': False, 'history_order': [1, 15, 20]})]}
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)
Boundary fixtureActualExpectedOutcome
transition 0{'attach_live': False, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}{'attach_live': False, 'cursor': 1, 'deferred': ['live'], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': ['a']}Passed
transition 1{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 2, 'terminal': None, 'values': []}Passed
transition 2{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [[1, 'a'], [3, 'b'], [4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 3{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Passed
transition 4{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 1, 'terminal': None, 'values': []}Passed
transition 5{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 3, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [1], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 6{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}{'attach_live': True, 'cursor': 0, 'deferred': [], 'eligible': [], 'gap': False, 'history_order': [], 'live': [], 'remaining': 0, 'terminal': None, 'values': []}Passed
transition 7{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}{'attach_live': False, 'cursor': 4, 'deferred': [], 'eligible': [[4, 'c']], 'gap': False, 'history_order': [1, 3, 4], 'live': [], 'remaining': 3, 'terminal': None, 'values': []}Passed

SHA-256 / 4c65a79d5add3b3eca048732e97d95848319edb6322da4f95113d9a91ceb48c3

Verification & scope

A deterministic, bounded, single-threaded transition planner. Returned plans model state changes; they do not implement a production event framework. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:43:46.396861+00:00.

Case digest / aed75fb5811b0321f994d6f200020a4dc5531d4be5ad482e1be5e604e2882be1