Merge pull request #138 Co-authored-by: Arnaud Dartois <admin@tordais.cc>
3.2 KiB
name, description
| name | description |
|---|---|
| heartbeat-failover | Validate that stale Agents are marked offline and assigned cameras move safely to online peers. |
Heimdall heartbeat and Agent failover
Read AGENTS.md, the Heartbeat/failover item in todo.md, skills/heimdall-dotnet/SKILL.md, and skills/compose-disposable-recipe/SKILL.md before changing this path.
Behavior contract
- Use the configured global heartbeat interval or per-Agent override, bounded to 5–300 seconds. A stale Agent is not eligible for new work.
- The failover sweep owns the stale-to-Offline transition and camera reassignment. Do not add a competing heartbeat monitor that races this transition.
- Preserve camera assignment history: close the old row and create a new active row for an online Agent in the same site. If there is no replacement, clear the active assignment and let periodic reconciliation retry when an Agent recovers.
- Use short-lived EF Core contexts and test status, camera ownership, and assignment history against PostgreSQL.
Required validation
- Run the PostgreSQL tests in
HeartbeatMonitorJobTests,AgentFailoverJobTests, andCameraAssignmentServiceTests. - Run the integration scenario with two registered Agents: heartbeat both, assign a camera to the source, age only the source heartbeat past the maximum accepted timeout, execute the real
AgentFailoverJobandCameraAssignmentService, then verify the source is Offline, the online peer owns the camera, and both assignment records retain the correct released/active state. - Before any build/start, install an EXIT cleanup trap. Build Central from the changed source in a unique disposable Compose project. Generate database/JWT credentials, use unique loopback ports, network, volumes and image tag, empty Sentry DSN, bootstrap a synthetic admin/site and two synthetic Agents, and assign a synthetic camera. Age the source heartbeat only in the disposable PostgreSQL fixture and let the real Hangfire recurring failover job run; verify the active assignment and historical rows through API/PostgreSQL.
- The trap tears down that project with volumes/orphans, verifies zero project containers, volumes and networks, then removes and verifies absence of the exact source-built Central image tag even on failure. Keep upstream Postgres/.NET base images, preserve test exit status, report cleanup failures, and never use
--rmi allor broad image pruning. - Mark physical Agent loss, network partitions and multi-host timing as unverified unless exercised against deployed Agents.
Current local evidence
5 November 2026: new relational integration scenario passed 1/1. Disposable source-built project hmd-failover-1793882220-a9bc9c registered two Agents, assigned the synthetic camera to the first, aged its heartbeat to 900 seconds, and observed the real Hangfire failover mark it Offline and move the camera to the still-online peer. PostgreSQL confirmed the previous assignment was released and the replacement assignment active. Teardown left zero containers/volumes/networks and removed/verified absence of the exact Central image tag. This proves the local scheduled path and relational state, not a real network partition or deployed multi-host timing.