edge: D2D parity for peer lifecycle @on handlers (on top of #27)#31
Merged
kavya-chennoju merged 1 commit intoMay 12, 2026
Merged
Conversation
…D mode
The registry publishes device.{online,offline} on a shared subject
per tenant; D2D mode has no registry, so subscribing to that subject
sees nothing. Wire @on(event_name='peer_present'|'peer_lost') through
PresenceCollector callbacks when a D2D collector is present on the
device runtime, so the same decorator gives the same behavior in
both modes.
PresenceCollector grows multi-listener support (backward compatible
with the constructor-form on_new_peer pattern; new add_on_new_peer /
add_on_peer_removed methods) and emits on_peer_removed from both the
graceful-departure branch and the prune-timeout loop.
Per-device event subscriptions are unaffected; they still go through
the broker subject in both modes.
9 new tests, 437 total passing.
kavya-chennoju
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #27. Extends peer lifecycle subscriptions to D2D mode.
What changes
#27 routes `@on(event_name="peer_present"|"peer_lost")` to the registry-published `device-connect..device.{online,offline}` subject. D2D mode has no registry publishing those subjects, so D2D drivers using the same decorator see nothing.
This PR delivers the same logical events via `PresenceCollector` callbacks when a D2D collector is present on the device runtime. The `@on` surface, alias names, and `device_id=` filter (exact + glob) are unchanged -- mode-transparent behavior.
How
`discovery.py`:
`drivers/base.py`:
Glob and exact `device_id=` filters apply post-hoc inside the delivery wrapper (same `_device_id_matches` helper as #27).
Tests
9 new tests, 437 total passing (30 from #27 + 7 prior lifecycle + new):
```
TestLifecycleSubscriptionsD2D
test_peer_lost_routes_through_collector
test_peer_present_routes_through_collector
test_d2d_lifecycle_device_id_filter_exact
test_d2d_lifecycle_device_id_filter_glob
test_d2d_per_device_event_still_uses_broker
TestPresenceCollectorRemovedCallback
test_graceful_departure_fires_on_peer_removed
test_prune_timeout_fires_on_peer_removed
test_add_on_peer_removed_supports_multiple_listeners
test_constructor_callback_coexists_with_listeners
```
Why stacked
This PR depends on #27's `_LIFECYCLE_ALIAS_TO_CANONICAL` and `_device_id_matches` helpers; without #27, the D2D path has no canonical lifecycle name to bind against. Once #27 lands the diff against `main` is the 390 LOC here.