Skip to the content.

Task 80 — Graceful shutdown and drain

Phase: 5 Initiative: 45 Status: done Owner: hercules-coder Started: 2026-08-16 Completed: 2026-08-16 Slug: graceful-shutdown-drain

Goal

Нет graceful shutdown/drain: IHostApplicationLifetime injected в McpServerHost но не используется. LifecycleService.DrainAgentAsync (:185-215) устанавливает Draining state но ничего не hooks — новые запросы продолжают приниматься. In-flight запросы и background services отменяются abruptly via CancellationToken при shutdown. При K8s rolling deploy in-flight запросы теряются.

Acceptance criteria

Sub-tasks

Scope / Likely files

src/agent/Program.cs, src/agent/Hercules.WebApi/Program.cs, src/agent/Lifecycle/LifecycleService.cs, src/agent/Agent/AgentCore.cs, src/agent/Agent/IInFlightTracker.cs (new), src/agent/Agent/InFlightTracker.cs (new), src/agent/Mcp/McpServerHost.cs, src/agent/Offline/OfflineSyncService.cs, src/agent/appsettings.json

Dependencies

Risks / Rollback

Drain timeout 30s может задержать shutdown; configurable. In-flight tracker добавляет overhead на каждый request (Interlocked Increment/Decrement — minimal). Rollback: убрать ApplicationStopping callback (но in-flight запросы теряются при deploy).

Implementation notes (2026-08-16)

Behaviour delivered

Validation