Refs #270 Caps successful analysis result payloads to Central’s 500-detection limit after type filtering, preserving input/model order for ObjectDetection, PersonDetection, and VehicleClassification. Adds >500 boundary/order tests for all three types and updates the analysis pipeline skill. Validation: `dotnet test tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --no-restore --filter FullyQualifiedName~AnalysisJobPollingServiceTests` passed 16/16; `git diff --check` passed. Compose acceptance remains incomplete. Source-built disposable stacks were started with unique projects, generated secrets/ports/volumes and unique Central image tags. Two runs did not reach healthy Postgres; a later run reached healthy Central but the isolated bootstrap-admin returned HTTP 400 because the generated test password did not meet Identity complexity. Therefore no 501 rejection / 500 persistence assertions were made. For each project, Compose teardown completed; label queries confirmed no project containers, volumes, or networks; each exact local image tag was inspected absent. One incomplete trap's two known JSON files were individually removed with `unlink` and its empty directory with `rmdir`. A later trap had harmless unlink attempts for not-yet-created paths and reported a cleanup error; independent checks confirmed its temp directory, project resources, and exact image tag were absent. Do not treat the Compose acceptance as passed. The server controller and readback shape were inspected in source only. Post-deployment GlitchTip validation also remains open. Reviewed-on: #279 Co-authored-by: Arnaud Dartois <admin@tordais.cc>
7.3 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 Gitea issue, and skills/heimdall-dotnet/SKILL.md. For database behavior, also follow skills/ef-core-persistence/SKILL.md.
Current supported job types
ObjectDetection: return detections produced by the configured YOLO COCO model in model order, capped at 500 because Central rejects larger successful results. The Agent truncates deterministically before serialization so the result can be persisted; detections after the first 500 are intentionally omitted.PersonDetection: use the same frame/model path and return only COCO class 0 (person), capped at 500 after filtering while preserving model order.VehicleClassification: use the same frame/model path and return COCO motor-vehicle classes 2 (car), 3 (motorcycle), 5 (bus) and 7 (truck), capped at 500 after filtering while preserving model order. 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.
- For every job type, cap successful result detections at Central’s 500-item limit in stable model order. For filtered types, filter first and then cap so unrelated model classes do not consume the result budget. Add boundary tests proving the output count and retained order for ObjectDetection and filtered types. This prevents Central’s permanent HTTP 400 rejection from silently discarding the whole result, while making the truncation explicit.
- 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.