lablup / lablup/backend.ai

Register every event type on the dispatcher, replacing _register_dict

Open
#13,721 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
15h 13m
Merged PRs (30d)
368

Description

### Problem

No single place knows every event type. Broadcast events self-register into `AbstractBroadcastEvent._register_dict` as an import-time side effect of `__init_subclass__`, while anycast events are not registered at all. So name-to-class resolution exists only for broadcast (`deserialize_from_wrapper`), nothing can enumerate the event catalogue, and the registry is a side effect of importing a module rather than a deliberate act.

### Scope

- Give the dispatcher an explicit event-type registry covering both delivery patterns.
- Replace `_register_dict` and the `__init_subclass__` side effect with it, and move the `deserialize_from_wrapper` lookup onto the registry.
- Add a unit test that round-trips every registered event type through `to_message()` / `from_message()`, asserting that field values and their types survive — not merely that the call does not raise.

### Why the test needs this issue first

Guaranteeing that every event is covered currently means walking `__subclasses__` after force-importing all event modules. That works, but it fails open: if discovery silently collects nothing, the completeness check passes vacuously. Enumerating from the registry removes that failure mode. The test should fail naming any registered event that has no sample.

### Watch out

Two distinct concrete events share both a class name and an event name — `DoTerminateSessionEvent` exists in the session anycast and broadcast modules. The registry must key on the class object and delivery pattern, never on the bare name, and failure messages must qualify the class by module or one of the two is silently masked.

### Blocks

The dispatcher handler-registration refactor depends on this, which is what lets one handler per event be enforced structurally.

JIRA Issue: BA-7341

Contributor guide

Open the contributing guide

Research direction

Locate AbstractBroadcastEvent._register_dict, its __init_subclass__ registration, deserialize_from_wrapper, and the dispatcher’s event definitions. Trace both broadcast and anycast event paths before designing the explicit registry. Done means every registered event has a round-trip unit test preserving field values and types, including module-qualified handling of duplicate event names.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, backend-api-design, distributed-systems
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.