Concepts

Lifecycle Prototype

Starting a process is easy. Stopping one without losing work is the hard part. Clamp's lifecycle model is designed around both.

Status. Phase 5 is complete as a prototype. Core provides opt-in synchronous phase traits (Initialize, Start, Ready, Drain, Stop) with an identity-only LifecycleContext; example 05 drives them against fake resources with an example-local dispatcher. It is a proof, not a public production lifecycle API. Each row below says what it covers.

Alive does not mean Ready. Ready does not mean Healthy.

Phases#

PhaseWhat happensStatus
CreatedThe application exists structurally. No side effects yet.Planned
ConfiguredConfiguration is resolved from defaults, files, environment and arguments. Missing required configuration fails before any work is accepted.Planned
ComposedModules, capabilities and contributions are assembled. Describe what exists and what is required — no I/O.Prototype
ValidatedThe known composition is checked before external resources open: missing or ambiguous providers, cycles, orphan contributions.Prototype
InitializedExternal resources are prepared — pools, keys, telemetry — in dependency order: providers before the modules that need them.Prototype
StartedComponents begin active work. initialize() prepares; start() begins.Prototype
ReadyThe process is prepared to accept its intended workload. Never ready if startup or a required health check failed.Prototype
RunningNormal execution under supervision — see Runtime.Prototype
StoppedReached through the shutdown pipeline below, or through Failed → cleanup from any phase.Prototype

Shutdown, in order#

Shutdown starts by refusing new work, not by destroying dependencies.

  1. Shutdown requested.
  2. Readiness becomes false; admission closes.
  3. In-flight work drains, bounded by a deadline — consumers first (Worker, then the modules it uses).
  4. Remaining cancellable work is cancelled. Cancellation stops work; it does not undo side effects that already happened.
  5. Participants stop in reverse dependency order — providers last.
  6. Final diagnostics are flushed, within a bound.
  7. Infrastructure closes; the process exits.

What the prototype proves#

The lifecycle prototype freezes and validates a Worker projection (Worker → Users → a fake Database capability) before running any lifecycle operation, then derives order from Kernel's resolved requirements. Its twelve default-feature tests cover:

  • Initialization and startup order derived from dependencies; cleanup in reverse.
  • No readiness after a startup failure or a failed required health check.
  • Cleanup of only the resources that were actually acquired.
  • Cleanup that continues after injected errors.
  • Drain deadlines, optional degradation, programmatic shutdown, and a bounded final flush.
  • External ownership: a caller-owned Database skips its initialize and stop hooks and stays open after shutdown.

Around those tests the example also proves:

  • Coexisting processes. Worker and Reporter, frozen from one blueprint, share an application-owned database but keep separate process state; stopping one leaves the other running, and stopping both leaves the database to its owner.
  • Execution scope. An execution resource handle can be created only for a root in the frozen projection, and each handle stops independently. No locator, no transient object manager.
  • Inspection. Outcome::inspection() reports provider-to-consumer edges, actual owners, the phases each participant implements, and cleanup state — sticky-failed if any cleanup phase fails.
PathDatabase ownerInitialize/stop hooksAfter shutdown
DefaultLifecycle fixtureBoth runClosed
ExternalCaller (ExternalDatabaseOwner)Neither runsStill open

Status keeps started, ready, alive, accepting_work and health as separate values rather than one boolean.

cargo run --offline --locked --manifest-path examples/a5-lifecycle/Cargo.toml --example a5-lifecycle

With the fixture's fake clock, the managed path is ready in 5 ms and fully shut down in 14 ms. These are configured durations for ordering and timeout tests, not hardware performance.

Health vocabulary#

SignalQuestion it answers
LivenessIs the process alive?
ReadinessShould new work be sent to this process?
HealthHow is each component doing? Per component, not a single yes or no.