Startup, Shutdown, and Recovery

Recovery is a lifecycle, not only a restart

During startup, validate configuration and load required resources before marking ready. During shutdown, first become unready, stop admitting requests, allow in-flight work a bounded drain period, flush safe telemetry, and release resources. This sequence is graceful shutdown.

A supervisor or container orchestrator can restart a process after unexpected exit. Add a short delay or exponential backoff so a permanent failure does not create a hot crash loop. Limit restart attempts and surface terminal failure to operators.

Warning: In-memory queues and chat state vanish on process exit. Important work needs idempotent requests, external durable state, or a protocol that lets clients safely retry.

Separate crashes from intentional clean shutdown. A supervisor should normally restart unexpected nonzero exits but respect an operator-requested stop. Give each process a fresh identifier so tests can prove that a new instance actually started.

Tip: Readiness should remain false after restart until every required dependency is restored. Fast restart plus dishonest readiness only fails requests sooner.