FAILURE MAP
← Case archive

FA-4511 / Listener lifecycle / Open access

Listener removal by identity · 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. Removing one identity preserves all other listeners, including listeners for the same event.

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

ROOT CAUSE

Removing one identity preserves all other listeners, including listeners for the same event. 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. Removing one identity preserves all other listeners, including listeners for the same event.

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. Removing one identity preserves all other listeners, including listeners for the same event. 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.clear()
        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']]Failed
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 / 9c08a78b25d5904b0db7b8dcbbf59bc1bad8237d0a25f9bfa8b7546fd06b7964

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={k:v for k,v in listeners.items() if v[0]!=event[1]}
        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['a', 'c', ['a', 'b', 'c']]['c', ['b', 'c']]Failed
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 / 72d386cd9faf7e674d61947d1882e341ae302a3073eb131b7fd0a9b466a58605

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

Case digest / 63f17618514460bed712a558487a196faa0ce57581ccc2bca6c8ab2790ac8286