Files
Heimdall/skills/camera-toggle-acceptance/SKILL.md
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

6.1 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 entry in todo.md, 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.
  • 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.
  • 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

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.