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#
| Phase | What happens | Status |
|---|---|---|
| Created | The application exists structurally. No side effects yet. | Planned |
| Configured | Configuration is resolved from defaults, files, environment and arguments. Missing required configuration fails before any work is accepted. | Planned |
| Composed | Modules, capabilities and contributions are assembled. Describe what exists and what is required — no I/O. | Prototype |
| Validated | The known composition is checked before external resources open: missing or ambiguous providers, cycles, orphan contributions. | Prototype |
| Initialized | External resources are prepared — pools, keys, telemetry — in dependency order: providers before the modules that need them. | Prototype |
| Started | Components begin active work. initialize() prepares; start() begins. | Prototype |
| Ready | The process is prepared to accept its intended workload. Never ready if startup or a required health check failed. | Prototype |
| Running | Normal execution under supervision — see Runtime. | Prototype |
| Stopped | Reached 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.
- Shutdown requested.
- Readiness becomes false; admission closes.
- In-flight work drains, bounded by a deadline — consumers first (Worker, then the modules it uses).
- Remaining cancellable work is cancelled. Cancellation stops work; it does not undo side effects that already happened.
- Participants stop in reverse dependency order — providers last.
- Final diagnostics are flushed, within a bound.
- 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.
| Path | Database owner | Initialize/stop hooks | After shutdown |
|---|---|---|---|
| Default | Lifecycle fixture | Both run | Closed |
| External | Caller (ExternalDatabaseOwner) | Neither runs | Still 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#
| Signal | Question it answers |
|---|---|
| Liveness | Is the process alive? |
| Readiness | Should new work be sent to this process? |
| Health | How is each component doing? Per component, not a single yes or no. |