Files
AutopilotMonitor/src
Oliver Kieselbach 0bc04c3a9a v2 single-rail 5.3c: Program.cs terminate callback waits for shutdown completion
Plan §6.2 synchronous-shutdown — the ServerActionDispatcher terminate
callback now blocks until the main-thread cleanup sequence (orchestrator
stop, client disposal) has fully run, instead of returning
Task.CompletedTask immediately after terminationHandler.Handle.

Mechanism: a second ManualResetEventSlim `shutdownComplete` is Set() at
the very end of the finally block (after orchestrator.Stop + HTTP-client
disposal). The terminate callback waits on it for up to 60s after
terminationHandler.Handle returns. If the bound expires we log and return
rather than deadlock the ingest-dispatcher thread forever.

Effect: no fresh ingest call can happen between
terminationHandler.Handle returning and the process actually exiting,
which would otherwise give the backend another window to re-deliver
terminate_session. Combined with the PR #3a dedup this closes the
77×-storm loop from the root.

Non-server-action termination paths (decision-engine enrollment_complete,
max-lifetime, auth-failure, Ctrl+C) are unaffected — they already drive
shutdown from the main thread itself.

V2.Core: 538, DecisionCore: 108, all green.
2026-04-23 14:01:07 +02:00
..