FAILURE MAP
← Case archive

FA-4531 / Listener lifecycle / Open access

Listener callback registration · case 01

The operation returns a result or retained state that violates this contract: Listeners have identity, event name, once flag, and registration order. Dispatch uses a snapshot; listener actions remove another listener or add a new one. Return callback identities in invocation order. A listener installed by a callback starts participating on the next dispatch and uses the action-specified event name.

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

ROOT CAUSE

A listener installed by a callback starts participating on the next dispatch and uses the action-specified event name. The broken transition violates that invariant.

VERIFIED REPAIR

Listeners have identity, event name, once flag, and registration order. Dispatch uses a snapshot; listener actions remove another listener or add a new one. Return callback identities in invocation order. A listener installed by a callback starts participating on the next dispatch and uses the action-specified event name.

Unsuccessful approach: The attempted transition changes the behavior but still violates the same invariant in at least one independent regression fixture.

Case contract

Listeners have identity, event name, once flag, and registration order. Dispatch uses a snapshot; listener actions remove another listener or add a new one. Return callback identities in invocation order. A listener installed by a callback starts participating on the next dispatch and uses the action-specified event name. Inputs are the finite Python values shown by the executable fixtures; no concurrent execution is assumed.

Why this case matters

A controlled local-runtime regression for collection APIs, language semantics, or ownership wrappers. Fixtures include boundary and interaction cases.

1 / The failure

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

N = 1
observations = []
def solve(x, y=None):
    listeners={}; out=[]
    for event in x:
        op=event[0]
        if op=='on':
            _,k,name,once,action=event
            if True: listeners[k]=[name,once,action]
        elif op=='off':
            listeners.pop(event[1],None)
        elif op=='emit':
            name=event[1]
            batch=list(listeners.items())
            for k,entry in batch:
                if entry[0]==name:
                    if entry[1]:
                        listeners.pop(k,None)
                    out.append(k)
                    action=entry[2]
                    if action and action[0]=='off':
                        listeners.pop(action[1],None)
                    elif action and action[0]=='on':
                        listeners[action[1]]=[name,False,None]
        elif op=='names': out.append(list(listeners))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('replacement changes event but preserves order', solve([['on', 'a', 'old', False, None], ['on', 'b', 'new', False, None], ['on', 'a', 'new', False, None], ['emit', 'new'], ['names']]), ['a', 'b', ['a', 'b']])
check('snapshot removal and once lifetime', solve([['on', 'a', 'e', True, ['off', 'b']], ['on', 'b', 'e', False, None], ['on', 'c', 'e', False, None], ['emit', 'e'], ['emit', 'e'], ['names']]), ['a', 'b', 'c', 'c', ['c']])
check('explicit identity removal and event filtering', solve([['on', 'a', 'e', False, None], ['on', 'b', '*', False, None], ['on', 'c', 'e', False, None], ['off', 'a'], ['emit', 'e'], ['names']]), ['c', ['b', 'c']])
check('callback replaces existing target event', solve([['on', 'a', 'e', True, ['on', 'b', 'later']], ['on', 'b', 'old', False, None], ['emit', 'e'], ['emit', 'later'], ['emit', 'old'], ['names']]), ['a', 'b', ['b']])
check('callback replaces metadata rather than setdefault', solve([['on','a','e',True,['on','b','later']],['on','b','old',False,None],['emit','e'],['emit','later'],['emit','later'],['emit','old']]), ['a','b','b'])
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
replacement changes event but preserves order['a', 'b', ['a', 'b']]['a', 'b', ['a', 'b']]Passed
snapshot removal and once lifetime['a', 'b', 'c', 'c', ['c']]['a', 'b', 'c', 'c', ['c']]Passed
explicit identity removal and event filtering['c', ['b', 'c']]['c', ['b', 'c']]Passed
callback replaces existing target event['a', ['b']]['a', 'b', ['b']]Failed
callback replaces metadata rather than setdefault['a']['a', 'b', 'b']Failed

SHA-256 / 92397ce2dee402ee9ee6327de083f54abb8f00f99b34eab1a3c1e3a9b2185e60

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x, y=None):
    listeners={}; out=[]
    for event in x:
        op=event[0]
        if op=='on':
            _,k,name,once,action=event
            if True: listeners[k]=[name,once,action]
        elif op=='off':
            listeners.pop(event[1],None)
        elif op=='emit':
            name=event[1]
            batch=list(listeners.items())
            for k,entry in batch:
                if entry[0]==name:
                    if entry[1]:
                        listeners.pop(k,None)
                    out.append(k)
                    action=entry[2]
                    if action and action[0]=='off':
                        listeners.pop(action[1],None)
                    elif action and action[0]=='on':
                        listeners.setdefault(action[1],[action[2],False,None])
        elif op=='names': out.append(list(listeners))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('replacement changes event but preserves order', solve([['on', 'a', 'old', False, None], ['on', 'b', 'new', False, None], ['on', 'a', 'new', False, None], ['emit', 'new'], ['names']]), ['a', 'b', ['a', 'b']])
check('snapshot removal and once lifetime', solve([['on', 'a', 'e', True, ['off', 'b']], ['on', 'b', 'e', False, None], ['on', 'c', 'e', False, None], ['emit', 'e'], ['emit', 'e'], ['names']]), ['a', 'b', 'c', 'c', ['c']])
check('explicit identity removal and event filtering', solve([['on', 'a', 'e', False, None], ['on', 'b', '*', False, None], ['on', 'c', 'e', False, None], ['off', 'a'], ['emit', 'e'], ['names']]), ['c', ['b', 'c']])
check('callback replaces existing target event', solve([['on', 'a', 'e', True, ['on', 'b', 'later']], ['on', 'b', 'old', False, None], ['emit', 'e'], ['emit', 'later'], ['emit', 'old'], ['names']]), ['a', 'b', ['b']])
check('callback replaces metadata rather than setdefault', solve([['on','a','e',True,['on','b','later']],['on','b','old',False,None],['emit','e'],['emit','later'],['emit','later'],['emit','old']]), ['a','b','b'])
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
replacement changes event but preserves order['a', 'b', ['a', 'b']]['a', 'b', ['a', 'b']]Passed
snapshot removal and once lifetime['a', 'b', 'c', 'c', ['c']]['a', 'b', 'c', 'c', ['c']]Passed
explicit identity removal and event filtering['c', ['b', 'c']]['c', ['b', 'c']]Passed
callback replaces existing target event['a', 'b', ['b']]['a', 'b', ['b']]Passed
callback replaces metadata rather than setdefault['a', 'b']['a', 'b', 'b']Failed

SHA-256 / e1b1a9615df98f68648c362df2db481853551ad1cbc2222df32864fcaf330593

3 / The verified repair

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

N = 1
observations = []
def solve(x, y=None):
    listeners={}; out=[]
    for event in x:
        op=event[0]
        if op=='on':
            _,k,name,once,action=event
            if True: listeners[k]=[name,once,action]
        elif op=='off':
            listeners.pop(event[1],None)
        elif op=='emit':
            name=event[1]
            batch=list(listeners.items())
            for k,entry in batch:
                if entry[0]==name:
                    if entry[1]:
                        listeners.pop(k,None)
                    out.append(k)
                    action=entry[2]
                    if action and action[0]=='off':
                        listeners.pop(action[1],None)
                    elif action and action[0]=='on':
                        listeners[action[1]]=[action[2],False,None]
        elif op=='names': out.append(list(listeners))
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('replacement changes event but preserves order', solve([['on', 'a', 'old', False, None], ['on', 'b', 'new', False, None], ['on', 'a', 'new', False, None], ['emit', 'new'], ['names']]), ['a', 'b', ['a', 'b']])
check('snapshot removal and once lifetime', solve([['on', 'a', 'e', True, ['off', 'b']], ['on', 'b', 'e', False, None], ['on', 'c', 'e', False, None], ['emit', 'e'], ['emit', 'e'], ['names']]), ['a', 'b', 'c', 'c', ['c']])
check('explicit identity removal and event filtering', solve([['on', 'a', 'e', False, None], ['on', 'b', '*', False, None], ['on', 'c', 'e', False, None], ['off', 'a'], ['emit', 'e'], ['names']]), ['c', ['b', 'c']])
check('callback replaces existing target event', solve([['on', 'a', 'e', True, ['on', 'b', 'later']], ['on', 'b', 'old', False, None], ['emit', 'e'], ['emit', 'later'], ['emit', 'old'], ['names']]), ['a', 'b', ['b']])
check('callback replaces metadata rather than setdefault', solve([['on','a','e',True,['on','b','later']],['on','b','old',False,None],['emit','e'],['emit','later'],['emit','later'],['emit','old']]), ['a','b','b'])
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
replacement changes event but preserves order['a', 'b', ['a', 'b']]['a', 'b', ['a', 'b']]Passed
snapshot removal and once lifetime['a', 'b', 'c', 'c', ['c']]['a', 'b', 'c', 'c', ['c']]Passed
explicit identity removal and event filtering['c', ['b', 'c']]['c', ['b', 'c']]Passed
callback replaces existing target event['a', 'b', ['b']]['a', 'b', ['b']]Passed
callback replaces metadata rather than setdefault['a', 'b', 'b']['a', 'b', 'b']Passed

SHA-256 / 0935085c19d93738649b6d9ccffd7369a704e5b24acd1f60e71a44e5d457e3d4

Verification & scope

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:37:40.080052+00:00.

Case digest / 7d17e5568e376ecbc12a3912e3527912af5034cce2a6767bca6378c8b45a1e97