## Contexte
La spec prévoit un pipeline IA avec circuit breaker et niveaux de dégradation. Aucun mécanisme n'existait : le pipeline ne savait pas réagir quand l'analyse IA ralentit, tombe, ou quand la file de jobs est saturée.
## Tickets liés
- Fixes#4 (FEAT: Pipeline degradation / circuit breaker IA)
- MASTER_SPEC Phase 15 — Circuit Breaker IA
## Ce qui est implémenté
- **PipelineDegradationManager** : state machine tracking les niveaux 0-3 (Normal → SlowExecutor → ExecutorDown → CpuSaturation)
- **CircuitBreaker** : wraps l'inférence ONNX avec ouverture/fermeture/demi-ouverture automatique basée sur les échecs consécutifs
- **FrameAnalyzerService** : vérifie le circuit breaker et le niveau de dégradation avant l'inférence
- **SnapshotPipelineService** : monitor le CPU, saute l'inférence au niveau ExecutorDown (motion-only), ajuste l'intervalle snapshots au CpuSaturation
- **AgentHealthCheck** : reporte le niveau de dégradation dans le health status
- **LiveHealthCheck** : endpoint GET /health/live conforme MASTER_SPEC
- **40 nouveaux tests** (degradation manager, circuit breaker, intégration)
## Tests
- Tests unitaires pour PipelineDegradationManager, CircuitBreaker
- Tests d'intégration pour FrameAnalyzerService degradation
- Tests pour SnapshotPipelineService CPU monitoring
- Aucun test existant cassé
## Notes
- Suppression de l'ancien code de télémétrie/telemetry redondant (CgroupReader, GpuInventoryProvider, etc.)
- Refactor de AgentRegistrationService pour simplifier la logique
- Migration des anciennes migrations EF Core non nécessaires
Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/168
## What
Replace the stub `FrameAnalyzerService.RunInference` (returning `[]`) with a real ONNX Runtime inference pipeline for YOLOv8 object detection.
## Why
The entire detection chain was non-functional — `FrameAnalyzerService` returned empty results, `Microsoft.ML.OnnxRuntime` was not referenced, and no object detection was produced. This is the core AI feature of the Heimdall platform (issue #2, etape-3).
## How
- **Packages**: Added `Microsoft.ML.OnnxRuntime` 1.22.0 and `SixLabors.ImageSharp` 4.1.0 to `Heimdall.Agent.csproj`
- **ONNX session**: `InferenceSession` loaded in constructor with graceful fallback to passthrough mode when model is absent
- **Preprocessing**: JPEG → ImageSharp `Image<Rgb24>` → resize 640×640 → NCHW tensor normalized [0,1]
- **Inference**: ONNX Runtime `Session.Run()` with the preprocessed tensor
- **Post-processing**: YOLOv8 output parsing (`[1, 4+C, 8400]` tensor → bounding boxes + class scores) with class-aware Non-Maximum Suppression (IoU threshold 0.45, confidence threshold 0.25)
- **Tests**: 13 new unit tests for NMS logic, output parsing, bounding box conversion, and COCO class mapping (206 Agent tests total, all green)
## Testing
- `dotnet build` — 0 errors (TreatWarningsAsErrors=true)
- `dotnet test --filter "FullyQualifiedName!~E2E"` — 1282 passed, 0 failed
- E2E failures are pre-existing (Playwright/Chromium not installed on this runner)
## Notes
- Model path configurable via `MODEL_PATH` env var (default: `models/yolov8m.onnx`)
- Passthrough mode preserved when model file is absent — no crash
- Thread-safe: `InferenceSession.Run()` is thread-safe; session created once in constructor
Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/148
- CameraStreamService enregistré dans le DI + hosted SnapshotPipelineService
qui synchronise les captures avec les caméras assignées (Central = source de
vérité via clés camera.<id>.* dans la config agent ; fallback local Agent:Cameras)
- Découpage du flux MJPEG en frames JPEG (JpegFrameSplitter, marqueurs SOI/EOI)
- Intervalle adaptatif (spec Phase 15) : scène vide 1000ms / mouvement 500ms /
objet détecté 200ms, doublé si CPU > 80% ; état de scène piloté par les
résultats de l'analyseur + proxy de mouvement (FrameMotionDetector, pixel diff
réel en Phase 16)
- Channel borné 100 snapshots (DropOldest) — backpressure + compteur de drops
et log rate-limité (alerte admin via remontée des logs agent)
- Frames réellement transmises à FrameAnalyzerService (compteur AnalyzedFrameCount)
- Central : GET /api/settings/agent/{id} embarque les caméras assignées
(name/rtsp/sub_rtsp/enabled) ; ConfigReceiverService les applique à chaud
- Tests : JpegFrameSplitter, intervalle adaptatif, tracker de scène, motion
detector, CameraConfigStore, pipeline (snapshot → analyseur), handler config
Changed BoundedChannelFullMode from DropOldest to DropWrite.
With DropOldest, the oldest queued job is silently removed when the
channel is full, but its TaskCompletionSource is never completed —
causing the caller to hang indefinitely.
DropWrite rejects new writes when full, returning TryWrite=false,
which triggers the existing graceful fallback (tcs.TrySetResult(null)).