bugger.
All challenges/Pythonmediumgsoc-ignite-filtered-handlers-v1
THE INVESTIGATION

The filtered callback that survives removal

Removing a training event handler works until a filter wraps its callable and hides the identity the registry expects.

MLUpstream bugsPyTorch-IgniteCallback identity

What’s going wrong

ML practice for NumFOCUS / PyTorch-Ignite. This historical teaching adaptation isolates a documented filtered-event removal repair in original Bugger code; it does not execute the upstream package.

An event engine registers callbacks and returns removal handles. An unfiltered handle removes its callback, but a filtered callback continues to run after its handle is removed. Repair Handle.remove while preserving filters and the registry’s original-callback identity contract.

Read {"commands":[...]} from stdin. The commands are add, emit and remove. An add is {"op":"add","token":"h1","event":"epoch","handler":"report","every":2}. Each token uniquely names a removal handle and is never reused. Handler names identify shared original callables: the same name always refers to the same original callback, even across events. every is null for an unfiltered registration or an integer from 1 to 10 for a filtered wrapper. An emit is {"op":"emit","event":"epoch","tick":2}; it calls current registrations for that event in registration order, invoking a filtered callback only when tick is divisible by every. The supplied tick is used directly; there is no internal counter.

A remove is {"op":"remove","token":"h1"} and always refers to an earlier add. Its handle identifies the original handler and event. It must remove every current registration of that original handler at that event, including registrations using other filters or no filter, while preserving other handlers and events. Repeating a removal with nothing matching is harmless. Handles remain usable after removal: a later removal also removes any new matching registration.

Print an array of {"handler":"report","event":"epoch","tick":2} entries, one for each callback actually invoked, in invocation order. Add, remove and filtered-out emissions produce no entries. There are 0 to 32 commands and at most 8 adds. All names and tokens are nonempty case-sensitive ASCII strings of at most 16 characters; ticks are integers from 1 to 100. Unknown event names simply have no callbacks. Inputs are valid. Callbacks only append to the log; they never change registrations during emit.

Expected behavior

Resolve a filtered handle to its original callback before removing matching registrations at its event, preserving unrelated registrations and filter behavior.

Reproduction

01 A filtered callback must stop after removal
{"commands":[{"op":"add","token":"h","event":"epoch","handler":"report","every":2},{"op":"emit","event":"epoch","tick":2},{"op":"remove","token":"h"},{"op":"emit","event":"epoch","tick":4}]}
[{"handler":"report","event":"epoch","tick":2}]
02 An unfiltered removal is a passing control
{"commands":[{"op":"add","token":"h","event":"epoch","handler":"report","every":null},{"op":"emit","event":"epoch","tick":1},{"op":"remove","token":"h"},{"op":"emit","event":"epoch","tick":2}]}
[{"handler":"report","event":"epoch","tick":1}]
03 Filtering still selects only matching ticks
{"commands":[{"op":"add","token":"h","event":"step","handler":"metric","every":3},{"op":"emit","event":"step","tick":1},{"op":"emit","event":"step","tick":3},{"op":"emit","event":"step","tick":4},{"op":"emit","event":"step","tick":6}]}
[{"handler":"metric","event":"step","tick":3},{"handler":"metric","event":"step","tick":6}]

Before you begin

  • Callable identity
  • Wrapper functions
  • Event registration lifecycle

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.