Files
Heimdall/skills/camera-toggle-acceptance/SKILL.md
T
arnaud.dartois dc8a313deb
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 21m18s
Heimdall Gitea / Build and scan server image (push) Successful in 8m5s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m29s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 33m56s
Heimdall Gitea / Publish versioned installer release (push) Successful in 4m13s
Heimdall Gitea / CI policy (push) Successful in 2s
[Camera] Keep activated cameras offline until agent confirmation (#325)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-12 02:06:10 +01:00

8.4 KiB

name, description
name description
camera-toggle-acceptance Validate that Central camera enable/disable changes stop and resume the real Agent FFmpeg capture process and persist across Agent restarts.

Camera enable/disable lifecycle

Read AGENTS.md, the Toggle caméra #59/#199 Gitea issue, skills/heimdall-dotnet/SKILL.md, and skills/compose-disposable-recipe/SKILL.md before changing this flow.

Implementation path

  • POST /api/cameras/{id}/toggle-status requires the normal camera-write permission and persists Camera.Status in Central. Enabling a Disabled camera sets it to Offline (enabled, connectivity not yet confirmed); only an Agent status report can set it Online. Toggling any enabled status sets it to Disabled.
  • Agent status reports require the API key to resolve to the same Agent ID in the route and the camera to be assigned to that Agent. Authenticate and authorize both resources with ResourceAccess; never trust the route ID alone. Keep the existing same-site camera check in ReportCameraStatusCommandHandler.
  • AppDbContext.SaveChangesAsync publishes a payload-free config invalidation after camera/assignment/profile changes. Agent refetches its authorized full camera snapshot over its ConfigHub/API path and acknowledges the digest.
  • GetEffectiveAgentConfigQuery emits camera.<id>.enabled from the persisted status. CameraConfigStore atomically replaces the snapshot and raises Changed.
  • SnapshotPipelineService reconciles enabled assignments with CameraStreamService; disabling/removing an assignment kills FFmpeg, awaits its read loop cleanup and releases its stream permit. Enabling starts the stream. Keep central status authoritative; an Agent status report must not re-enable a disabled camera.
  • Camera counts and lists consider only Online cameras connected. An enabled Offline/Error camera remains enabled in the Agent configuration but is not counted as Online. UI toggle messages treat every status except Disabled as enabled.
  • Agent identity and API key are protected in AgentState under the configured state directory. Mount a project-scoped volume there so a restart reuses the same Agent identity and the Central configuration is refetched from persistent camera state.

Local verification

The Central status contract is covered by ToggleCameraStatusCommandTests and the CamerasControllerTests.ToggleStatus_WithAuth_TogglesCamera relational API test: activation persists Offline, the authorized same-site Agent status endpoint can confirm Online, and a subsequent administrative toggle persists Disabled. Run these focused tests alongside the Agent lifecycle suites when changing this contract.

Run the focused Agent lifecycle suites:

dotnet test tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --filter 'FullyQualifiedName~CameraStreamServiceTests|FullyQualifiedName~SnapshotPipelineServiceTests' --no-restore

These tests cover session idempotence, process termination, and synchronization without claiming a full Central/Agent workflow.

Central + Agent disposable acceptance

  • Build Central and Agent from this checkout with unique tags recorded before the first build. Retain upstream Postgres, MediaMTX, FFmpeg, SDK and ASP.NET base images.
  • Use a fresh project-scoped database, JWT/site credentials, loopback-only Central/Postgres ports, network and volumes. Add a project network Agent and a synthetic MediaMTX RTSP publisher. Do not use host networking or real camera credentials.
  • Bootstrap a synthetic Admin/site, create a camera pointed at the synthetic RTSP path, register the actual Agent container with the generated site token, and assign the camera to that Agent.
  • Toggle ON and confirm an Agent ffmpeg pull process exists against the synthetic path. Toggle OFF and verify the API says Disabled, Agent reports no assigned stream via its active process count and the FFmpeg process disappears in under 2 seconds. Toggle ON and verify the process returns within 10 seconds.
  • Restart the Agent while ON; verify it reuses its single existing identity and restarts capture within 10 seconds. Then toggle OFF, restart again, and verify the camera remains Disabled and no capture process returns.
  • Use docker top only to count FFmpeg processes; never print its command lines because they contain the RTSP URL. Record elapsed durations and sanitized HTTP statuses only.
  • Install an EXIT cleanup trap before the first build/start. Teardown only the named Compose project, verify zero containers/volumes/networks, remove each exact project-unique Central/Agent image tag and verify absent, then delete the temporary environment and scripts. Keep the original test status and fail if cleanup verification fails.

This acceptance proves the source-built Central/Agent software lifecycle with a synthetic RTSP stream. It does not validate hardware codecs, physical cameras, LAN multicast, or deployed-host timing.

Observed simulator pitfalls

  • Do not count docker top output when the runtime's top implementation differs. Prefer an in-container process identity check (/proc/*/comm equals ffmpeg) and ensure the inspection process cannot match itself. A shell command line containing the text ffmpeg creates a false positive if the check scans all command lines.
  • Before asserting lifecycle timing, first confirm Agent Online, persisted camera assignment, effective config enabled value and version, and LastAppliedCameraConfigVersion acknowledgement. A failed precondition is not an OFF/ON timing result.
  • On failed acceptance, collect sanitized Central, Agent, RTSP server and publisher diagnostics before the cleanup trap runs. Then verify project resource counts and exact image tags as described above.
  • Current disposable attempts proved bootstrap, registration, assignment and Disabled config acknowledgement, but have not yet proved toggle timing or restart persistence. Treat #59/#199 as open until a corrected process measurement completes the whole cycle.

Latest source-built run

The fifth disposable Compose attempt used /proc/*/comm == ffmpeg, avoiding self-counting by the measurement shell. It confirmed the Disabled baseline at zero processes and progressed through ON, OFF, ON, then Agent restart while ON with capture restored. The next OFF returned Central state Disabled and effective Agent config enabled=false, with zero FFmpeg processes, but the latest config digest was not acknowledged inside the two-second OFF bound. Therefore the full OFF/ON/restart acceptance is still incomplete; do not mark #59/#199 complete. Investigate whether Agent ACK version is stale or the API config digest changes after toggle, while keeping the OFF process release measurement distinct from ACK convergence.

Sixth source-built run

The sixth run kept the FFmpeg process deadline separate from the config ACK deadline and verified exact initial digest equality between the Central config version and Agent LastAppliedCameraConfigVersion. It failed the OFF process bound: Central and Agent effective config both showed Disabled, but /proc/*/comm reached zero only after the two-second assertion timed out. No restart-OFF/persisted identity acceptance ran. Treat OFF <2 seconds and OFF restart persistence as unverified; investigate the measured delay before changing the acceptance threshold.

Camera status contract acceptance

For status semantics (issue #291), run CamerasControllerTests.ToggleStatus_WithAuth_TogglesCamera against PostgreSQL and the ToggleCameraStatusCommandTests suite. The relational test must assert Disabled → Offline and the online counter remains zero before connectivity, register and heartbeat a synthetic same-site Agent, reject its report before camera assignment, assign the synthetic camera, accept that Agent's Online report, reject a request that uses its API key with a different route Agent ID, and then confirm admin toggle → Disabled.

A source-built disposable Central + PostgreSQL Compose run on 2026-11-11 used project heimdall-291-acceptance-1794427561-8428, synthetic bootstrap/site/Agent/camera data, loopback ports 18543/15439, and image heimdall:heimdall-291-acceptance-1794427561-8428-central. It observed health HTTP 200, activation Offline, online count 0, then Agent-confirmed Online and online count 1. Cleanup verified zero project containers, volumes and networks, the exact image tag absent, and temporary files removed. This is software acceptance only; it does not satisfy validation:field hardware/deployment evidence.