Skip to the content.

Task 70 — Backend-профили и деградация

Phase: 4 Initiative: 30 Status: done Owner: — Slug: backend-profiles-degradation

Goal

Профили развёртывания объявляют, какой mesh используется: только локальный SQLite, Redis/Valkey, NATS, PostgreSQL или комбинации. Если бэкенд становится недоступен, агенты деградируют в local-only режим или прекращают приём новых делегаций по policy, а не падают молча. Состояние деградации наблюдаемо.

Acceptance criteria

Sub-tasks

Scope / Likely files

src/agent/Mesh/Profiles/, src/agent/Mesh/Profiles/MeshProfileLoader.cs, src/agent/Mesh/Degradation/HealthMonitor.cs

Dependencies

Risks / Rollback

Тихое падение в degraded-режим без видимости; явный mode flag + alerting + policy-driven refuse-when-stale.

Implementation notes

src/agent/Mesh/Profiles/MeshProfile.cs — 13 types: MeshBackendProfile enum (Local/Redis/Nats/Postgres/Hybrid), MeshBackendConfig, DegradationPolicy, DegradationMode, MeshProfileDefinition, MeshProfileConstraints, MeshBackendHealthStatus, BackendHealthState, BackendHealthChangedEvent.

src/agent/Mesh/Profiles/MeshProfileLoader.cs — loads profiles from config + .meshprofile.json files; built-in “local” profile always available; GetActiveProfile(), GetEffectiveBackend() for per-role resolution.

src/agent/Mesh/Backend/IMeshBackendHealthMonitor.cs — interface: GetBackendStatuses(), SubscribeToChanges(), CheckAllAsync().

src/agent/Mesh/Backend/MeshBackendHealthMonitor.cs — BackgroundService; in-process backends always Healthy (no external calls); external backends monitored on interval; transitions: Healthy→Degraded→Unavailable with consecutive failure tracking; OTel metrics via IMeshObservabilityService; subscriber callbacks fire on background thread.

Config/AppConfig.cs — added MeshProfilesConfig and AppConfig.MeshProfiles property.

Config/AppConfig.cs — added using Hercules.Mesh.Profiles; (added to Profiles dict property).

Mesh/MeshServiceExtensions.cs — registered MeshProfilesConfig and IMeshBackendHealthMonitor in DI.

Program.cs — registered appConfig.MeshProfiles.

Hercules.WebApi/Controllers/MeshProfileController.cs — 5 endpoints: GET /api/mesh/profiles, GET /api/mesh/profiles/{name}, GET /api/mesh/profiles/{name}/backends, GET /api/mesh/backend-status, GET /api/mesh/backend-status/{role}.

Tests (tests/.../Mesh/Profiles/MeshProfileLoaderTests.cs, tests/.../Mesh/Backend/MeshBackendHealthMonitorTests.cs): 24 unit tests covering profile loading, effective backend resolution, state transitions, callbacks, timeout handling, and subscription lifecycle.

Validation