Files
Heimdall/skills/mdns-camera-discovery/SKILL.md
T
arnaud.dartois adf8d73476
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 24m57s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 8m19s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m21s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 15m3s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 2m15s
Heimdall Gitea / CI policy (push) Successful in 1s
fix(agent): observe mDNS UDP receive cancellation (#309)
## Résumé
Le propriétaire des sockets UDP mDNS annule et observe maintenant les tâches de réception avant de quitter leur portée. Les erreurs socket inattendues restent propagées à la frontière de découverte.

Refs #301

## Validation
- `dotnet restore tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --locked-mode` : réussi.
- Test de régression ciblé annulation / erreur socket : 1/1 réussi; suite `Heimdall.Agent.Tests` : 440/440 réussis.
- Compose jetable `heimdall-agent-mdns-udp-retry-20261108162648-13721` : restore verrouillé réussi et tests ciblés : 9/9 réussis.
- Nettoyage Compose vérifié : conteneurs, volumes et réseau absents; images construites localement : aucune; image SDK partagée conservée.
- CI du commit `ee865931` : détection de portée réussie; build/tests et CI policy à revérifier après mise à jour de branche.
- L’observation GlitchTip post-déploiement pendant 7 jours reste ouverte; le ticket reste donc référencé par `Refs #301`.

Skill mise à jour : `skills/mdns-camera-discovery/SKILL.md`.

Reviewed-on: #309
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-08 18:37:45 +01:00

5.3 KiB

name, description
name description
mdns-camera-discovery Implement and validate HomeKit camera discovery from DNS-SD mDNS announcements in Heimdall Agent.

Heimdall mDNS camera discovery

Read AGENTS.md, the focused mDNS Gitea issue, skills/heimdall-dotnet/SKILL.md, and skills/compose-disposable-recipe/SKILL.md before changing discovery behavior.

Ownership and data flow

  • Heimdall.Mdns/MdnsClient owns UDP multicast and DNS-SD PTR/SRV/TXT/A parsing. Keep network operations cancellable and dispose sockets per operation.
  • HomeKitMdnsProbe maps only categories 17 (camera) and 18 (doorbell) into Agent discovery records.
  • NetworkCameraScanner is the Agent-side source of LAN probes. Preserve HomeKit metadata when its TCP scan has already found the same IP. Central persists and returns metadata; it must not probe the camera LAN.
  • Resolve an accessory address from an A record attached to the instance or from the exact SRV target hostname. Never use another advertisement's arbitrary A record as a fallback.
  • At Central confirmation, persist only capabilities proven by the discovery result and selected stream. Derive RTSP port from the selected RTSP URL (554 default for RTSP, 322 for RTSPS when omitted) or a probed RTSP port, HTTP port from the HTTP probe, and ONVIF service port from the device-service URL. Do not confuse UDP WS-Discovery port 3702 with the camera's HTTP ONVIF service port. Do not claim PTZ, audio, snapshot, or native motion support unless the probe actually verifies it.

Synthetic acceptance

  • Build synthetic DNS response packets with PTR _hap._tcp.local → instance, SRV instance → hostname/port, TXT ci, sf, id, md, and A hostname → address. Include an unrelated A record to verify strict SRV association.
  • Verify camera and doorbell categories are kept, unrelated categories are filtered, sf=0 maps to paired, and missing SRV-target A does not invent an address.
  • Verify HomeKitMdnsProbe maps address/name/id/model/category/pairing/port into its Agent contract, and cancellation yields an empty result.
  • Run the focused Agent tests and the full Agent test project after changes.
  • The synthetic packet path validates DNS assembly and mapping only. A disposable Compose test can exercise the Agent source in isolation; only a real camera on a representative LAN validates multicast routing and hardware behavior. Keep that item open until such a run exists.
  • The PostgreSQL integration scenario ConfirmDiscovery_PersistsOnlyVerifiedPortsAndCapabilities exercises confirmation from discovery metadata through persisted camera fields, including an ONVIF service port distinct from UDP 3702. Preserve that relational coverage when changing confirmation mapping.

UDP receive lifetime at shutdown

MdnsClient owns each UdpClient for one probe/discovery call. When a receive window expires, cancel the receive with a linked token and await its task before leaving the socket scope; this observes the expected cancellation and prevents a pending receive task from surfacing later as UnobservedTaskException. Do not swallow unrelated SocketException failures: keep them observable (or log a sanitized exception type at the discovery boundary). The focused regression test ObserveCanceledReceiveAsync_ObservesExpectedCancellationAndPropagatesSocketFailures covers expected cancellation and an unexpected socket failure. Run the focused and full Heimdall.Agent.Tests suites after changes to this lifecycle.

Disposable Compose

Run a one-shot isolated Compose test from the changed source with the SDK pinned by global.json (currently mcr.microsoft.com/dotnet/sdk:10.0.100). Copy only the Agent test project and its recursively referenced source projects, plus root build props/targets and global.json, into a temporary archive outside the repository. Mount the archive read-only, extract it inside the SDK container with tar --no-same-owner into /tmp (the container filesystem there is writable), and restore with --locked-mode. For mDNS lifecycle changes, run HomeKitMdnsProbeTests and the focused receive-cancellation regression test; otherwise run the relevant focused Agent tests. Use a unique Compose project, project-scoped NuGet package volume, and isolated bridge; publish no ports and never use host networking. The container is read-only except for /tmp, /root/.local/share/NuGet (NuGet HTTP cache), and the project-scoped package volume. Do not mark the bridge internal: locked restore may need NuGet network access; the bridge remains isolated from host/production networks. Install an EXIT cleanup trap before starting. This recipe builds no local images: remove only the named project with down --volumes --remove-orphans, verify its containers, volumes, and network are gone, then delete the archive and Compose file, retaining the shared SDK image. Record local image tags: none in the acceptance result. If a future variant builds an app/helper image, tag it uniquely and remove/verify that exact tag in the same cleanup trap. This proves source/test behavior in a container, not multicast delivery or camera discovery on a real LAN.

This SDK-only recipe creates no local Heimdall image. Retain the shared SDK base image; if future changes add a local build, use a project-unique tag and remove/verify that exact tag after teardown under skills/compose-disposable-recipe/SKILL.md.