Merge pull request #138 Co-authored-by: Arnaud Dartois <admin@tordais.cc>
6.6 KiB
name, description
| name | description |
|---|---|
| analysis-job-pipeline | Implement and verify analysis job types across Heimdall Central scheduling and Agent inference. |
Heimdall analysis job pipeline
Read AGENTS.md, the PIPE-01/02 entry in todo.md, and skills/heimdall-dotnet/SKILL.md. For database behavior, also follow skills/ef-core-persistence/SKILL.md.
Current supported job types
ObjectDetection: return every detection produced by the configured YOLO COCO model.PersonDetection: use the same frame/model path and return only COCO class 0 (person).VehicleClassification: use the same frame/model path and return COCO motor-vehicle classes 2 (car), 3 (motorcycle), 5 (bus) and 7 (truck). Keep the model label, confidence, box and class index in the result.MotionDetection: capture two frames from the already active RTSP stream 500 ms apart, downscale both to 32×18, and compare normalized luminance. A changed pixel must differ by at least 0.12; at least 2% changed pixels returns onemotiondetection with changed-region bounds and changed-pixel ratio as confidence. This CPU-only temporal detector does not require the YOLO model; lighting changes and camera shake may produce motion, so tune/measure it against representative cameras before relying on alerts.- The Web request whitelist, Central scheduler whitelist/capability requirements, and Agent parser must agree. The Agent accepts enum names and numeric enum values on the wire. Reject unsupported kinds instead of recording a successful empty result.
- Face and plate recognition have separate model/license/privacy requirements; anomaly and full-scene analysis are not implemented. Do not advertise them as available or map them to generic object detection.
- Jobs stay assigned to the Agent currently responsible for the camera. Keep the attempt ID, atomic claims, retries and late-result rejection intact when adding types.
- Result delivery retries transport failures, timeouts and HTTP 5xx with bounded backoff. A 409/404 attempt is no longer current and stops immediately; other HTTP 4xx responses are permanent for that submission and must also stop immediately so a bad result cannot block the Agent's next poll. Log the status code and job ID only; do not read or log Central response bodies.
Required validation
- Unit-test Agent type parsing, motion comparison for identical/changed frames, and exact COCO class filtering for the object/person/vehicle types, including empty results and unsupported types.
- Run PostgreSQL scheduler tests proving CPU/RAM requirements for supported types and refusal of unsupported types. Do not substitute EF InMemory for relational behavior.
- Run the PostgreSQL integration scenario through the Web API: create each supported job, dispatch to the assigned online Agent, claim it with the Agent API key, submit a result, and verify persisted completion. Verify unsupported type requests receive HTTP 400.
- Build Central from the changed source in a uniquely tagged disposable Compose project with generated credentials, loopback-only ports, project-owned volumes/network, empty Sentry DSN, and OCR disabled unless the scenario explicitly needs it. Bootstrap synthetic Admin/site/camera, register and heartbeat a synthetic Agent, assign the camera, submit supported and unsupported job types, and verify the lease/result boundary where practical.
- Tear down that exact Compose project, verify zero project containers/volumes/networks, remove every source-built image tag from this recipe and verify each exact tag is absent. Retain shared Postgres/.NET base images. Never use broad prune commands.
- Keep hardware, camera-stream inference, and real multi-Agent deployment claims separate from synthetic database/API acceptance.
For event-handler unit tests, initialize every queried set on the IApplicationDbContext substitute with MockDbSetHelper, including empty optional sets such as Recordings. An unconfigured NSubstitute DbSet throws from EF's IQueryable.Provider when the handler applies AsNoTracking or async LINQ. Use PostgreSQL integration tests for provider translation and persistence behavior; this unit fixture is only for handler branching and notification behavior.
The shared Playwright E2ETestBase.GotoWithCircuitAsync dismisses the install-help banner after each navigation. Loopback is a secure browser context, so PWA UI appears in these tests and can intercept clicks on dialogs; browser E2E assertions should exercise the intended application controls after dismissing that unrelated notice.
Current local acceptance evidence
Result delivery has a focused Agent test: SendResultAsync_DoesNotRetryPermanentClientRejection returns after one HTTP 400. The supported result JSON uses web defaults (classIndex, not ClassIndex). The disposable source Compose acceptance below validates the Central job API and persisted result contract; keep transport retry behavior covered by the Agent HTTP-handler test.
On 5 November 2026, Agent selection tests passed 10/10, PostgreSQL scheduler tests passed 10/10, and the integration scenario for the two filtered types passed 2/2. Disposable source-built Compose project hmd-analysis-1793881315-5ba569 bootstrapped synthetic Admin/site/Agent, registered and heartbeated the Agent, assigned a synthetic camera, rejected MotionDetection with HTTP 400, then created, dispatched, claimed, completed and read back persisted PersonDetection and VehicleClassification results. Teardown verified zero containers, volumes and networks and removed/verified absence of heimdall:hmd-analysis-1793881315-5ba569-central. This exercises scheduling and result contracts with synthetic detections, not video inference.
Motion detection implementation and acceptance (5 November 2026): Agent compares two frames 500 ms apart from the active stream at 32×18 luminance; threshold is 0.12 per pixel and 2% changed pixels, and output is one normalized motion region. Central API/scheduler accept the type and its 1-core/512-MB/3-minute capability limits. Tests passed: Agent selection/comparison 13/13, PostgreSQL scheduler 27/27, Web/PostgreSQL API contract 3/3. Source-built disposable Compose project hmd-motion-1793890915-22844 registered a real Agent container, started a synthetic moving RTSP stream, assigned the camera, created a MotionDetection job, and verified the Agent result with label motion and normalized bounds persisted in PostgreSQL. The project was torn down and verified at zero containers/volumes/networks; unique Central/Agent tags were removed and verified absent. Camera shake, exposure/lighting changes and representative real-camera thresholds remain unvalidated.