Presence tracking publishes device discovered, offline, back online and address changed events #161

Open
opened 2026-10-31 12:42:17 -04:00 by claude · 0 comments
Owner
  • Draft: PN-8
  • Priority: high
  • Agent: coder
  • Depends on: #145
  • Decisions: Q-PN-5, Q-PN-6

Why

Online status is computed when read, never stored (ClientPresenceOptions.cs:11-17), so nothing notices a transition.

What changes

  • New records in src/dotnet/src/Ninlil.Dns.Server.Core/Events/: ClientDiscoveredEvent, ClientWentOfflineEvent, ClientCameOnlineEvent, ClientAddressChangedEvent. Each carries client id, display name, identifier, address and time. Register each in Events/Broker/DnsServerEventTypeRegistry.cs; DnsServerEventTypeRegistryTests must cover them.
  • ClientPresenceFlushService: publish discovered (#145 creation), came online (previous LastSeenUtc older than OnlineWindow) and address changed (the stored Address differs).
  • New ClientPresenceTransitionService (hosted, in Ninlil.Dns.Server.ClientIdentity/Presence/). Each tick it publishes went offline for addresses whose LastSeenUtc crossed now - OnlineWindow since the previous tick.
    • Technical call: this is a database window query, so no in-memory state is lost on restart; at most one tick is double-reported or missed. It needs a repository query by LastSeenUtc range on EF and Mongo, which may need a storage-coder split if the index is missing.
  • Alert scope (Q-PN-5): ClientDiscoveredEvent is published for every device. ClientWentOfflineEvent, ClientCameOnlineEvent and ClientAddressChangedEvent are published only for clients with DnsClientEntity.IsFavorite (DnsClientEntity.cs:83).
    • Technical call: address changed follows the offline/online rule. It is a per-device state alert, and phones with rotating privacy addresses would flood it.
  • Baseline (Q-PN-6): when a flush runs and the registry holds no Discovered row yet, the devices it creates publish no ClientDiscoveredEvent.
    • Technical call: the rule reads the registry, not memory, so it survives a restart and needs no new state. Deleting every discovered device starts a new silent baseline.

Acceptance

  • This test fails first: Flush_ForAFavoriteLastSeenBeforeTheWindow_PublishesClientCameOnline against a recording publisher, in src/dotnet/tests/Ninlil.Dns.Server.ClientIdentity.Tests.
  • Tests: offline detection across one tick; address change; no online, offline or address event for a non-favorite; the first flush with an empty discovered set publishes nothing; a later flush publishes one ClientDiscoveredEvent per new device.
  • Gate: dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClientIdentity.Tests, dotnet test src/dotnet/tests/Ninlil.Dns.Server.Core.Tests. Core changed, so run the whole solution.

Source

audit-feature-parity.md §2A #11.
Owner decision 2026-10-31: "new-device alerts for all, on/offline for favourites" (Q-PN-5); "silent baseline" (Q-PN-6).

- **Draft:** PN-8 - **Priority:** high - **Agent:** coder - **Depends on:** #145 - **Decisions:** Q-PN-5, Q-PN-6 ### Why Online status is computed when read, never stored (`ClientPresenceOptions.cs:11-17`), so nothing notices a transition. ### What changes - New records in `src/dotnet/src/Ninlil.Dns.Server.Core/Events/`: `ClientDiscoveredEvent`, `ClientWentOfflineEvent`, `ClientCameOnlineEvent`, `ClientAddressChangedEvent`. Each carries client id, display name, identifier, address and time. Register each in `Events/Broker/DnsServerEventTypeRegistry.cs`; `DnsServerEventTypeRegistryTests` must cover them. - `ClientPresenceFlushService`: publish discovered (#145 creation), came online (previous `LastSeenUtc` older than `OnlineWindow`) and address changed (the stored `Address` differs). - New `ClientPresenceTransitionService` (hosted, in `Ninlil.Dns.Server.ClientIdentity/Presence/`). Each tick it publishes went offline for addresses whose `LastSeenUtc` crossed `now - OnlineWindow` since the previous tick. - Technical call: this is a database window query, so no in-memory state is lost on restart; at most one tick is double-reported or missed. It needs a repository query by `LastSeenUtc` range on EF and Mongo, which may need a storage-coder split if the index is missing. - Alert scope (Q-PN-5): `ClientDiscoveredEvent` is published for every device. `ClientWentOfflineEvent`, `ClientCameOnlineEvent` and `ClientAddressChangedEvent` are published only for clients with `DnsClientEntity.IsFavorite` (`DnsClientEntity.cs:83`). - Technical call: address changed follows the offline/online rule. It is a per-device state alert, and phones with rotating privacy addresses would flood it. - Baseline (Q-PN-6): when a flush runs and the registry holds no `Discovered` row yet, the devices it creates publish no `ClientDiscoveredEvent`. - Technical call: the rule reads the registry, not memory, so it survives a restart and needs no new state. Deleting every discovered device starts a new silent baseline. ### Acceptance - [ ] This test fails first: `Flush_ForAFavoriteLastSeenBeforeTheWindow_PublishesClientCameOnline` against a recording publisher, in `src/dotnet/tests/Ninlil.Dns.Server.ClientIdentity.Tests`. - [ ] Tests: offline detection across one tick; address change; no online, offline or address event for a non-favorite; the first flush with an empty discovered set publishes nothing; a later flush publishes one `ClientDiscoveredEvent` per new device. - [ ] Gate: `dotnet test src/dotnet/tests/Ninlil.Dns.Server.ClientIdentity.Tests`, `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Core.Tests`. Core changed, so run the whole solution. ### Source `audit-feature-parity.md` §2A #11. Owner decision 2026-10-31: "new-device alerts for all, on/offline for favourites" (Q-PN-5); "silent baseline" (Q-PN-6).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#161
No description provided.