FA-4516 / Listener lifecycle / Open access
Listener dispatch snapshot · 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. Dispatch membership is captured before callbacks; removals during dispatch do not skip captured callbacks.
ROOT CAUSE
Dispatch membership is captured before callbacks; removals during dispatch do not skip captured callbacks. 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. Dispatch membership is captured before callbacks; removals during dispatch do not skip captured callbacks.
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. Dispatch membership is captured before callbacks; removals during dispatch do not skip captured callbacks. 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=[(k,listeners[k]) for k in reversed(listeners)]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| replacement changes event but preserves order | ['b', 'a', ['a', 'b']] | ['a', 'b', ['a', 'b']] | Failed |
| snapshot removal and once lifetime | ['c', 'b', 'a', 'c', ['c']] | ['a', 'b', 'c', 'c', ['c']] | Failed |
| 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 / 6b89661a81eb9efb875a76021bf4cfb9f275c31e76074cf14865f463b22012d2
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=[(k,v) for k,v in listeners.items() if not any(e[2] and e[2][0]=="off" and e[2][1]==k for e in listeners.values())]
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| replacement changes event but preserves order | ['a', 'b', ['a', 'b']] | ['a', 'b', ['a', 'b']] | Passed |
| snapshot removal and once lifetime | ['a', 'c', 'c', ['c']] | ['a', 'b', 'c', 'c', ['c']] | Failed |
| 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 / 540b304a24787c4f92ce8ae88e08136378fae4cbe25f28e710e6db245032e7d2
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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.039584+00:00.
Case digest / f99eaf1762f0abbb75f5d9866536ff51bc156f946e75ee908d8644494c895fca