@on_boot registers a function to run before the SSE listener subscribes to the platform: useful for warming caches, opening database pools, validating environment, or pre-fetching data. @on_shutdown registers a function to run during graceful shutdown.
Decorator forms
| Parameter | Type | Default | Description |
|---|---|---|---|
configuration | Configuration | None | Reserved for future use. Currently only the Events module reads config; boot/shutdown handlers receive no arguments. |
Lifecycle ordering
@on_boot handler raises, the worker fails to start: the exception propagates and the process exits. If a @on_shutdown handler raises, the error is logged but the runtime continues with the next shutdown handler.
Examples
Open a DB pool at boot, close on shutdown
Validate env at boot
@on_boot aborts startup before the worker takes any tasks: useful for fail-fast environment validation.
Multiple handlers
1 then 2. The runtime awaits each one before moving on.
Sync and async mix
Notes
- Boot/shutdown handlers are class-level on
Events. They register globally per process: there’s no scoping to a specificEventsinstance. This is fine for a one-process-one-agent model. - Shutdown handlers run after the SSE listener is stopped but before final cleanup. By then the process is no longer accepting new tasks; in-flight tasks are cancelled.

