Skip to main content

Module bootstrap

Module bootstrap 

Source
Expand description

Server bootstrap sequence, extracted from main().

Each function here corresponds to one (or a small cluster of) the numbered phases that used to live inline in async fn main(): crash-monitor branch -> parent-process watchdog -> logging init -> PATH enrichment -> CLI/config parsing -> data-dir + migration setup -> DB/store opening -> event bus + subagent watcher + background task spawns -> TCP listener binds -> router/AppState build -> ESTART stderr emission -> stdin-watch thread -> SIGINT/SIGTERM handler.

This module is purely a relocation of that logic into named functions; main() calls them in the same order with the same effect.

Re-exportsΒ§

pub use watchers::*;
pub use logging::*;
pub use stores::*;
pub use background::*;
pub use network::*;
pub use plumbing::*;
pub use shutdown::*;
pub use delivery::*;
pub use state_services::*;

ModulesΒ§

background πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
carry_forward πŸ”’
A new version starts with the data of the version before it (docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md Β§6).
delivery πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
logging πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
messaging_bridges πŸ”’
The messaging bridges (Discord, Telegram, Slack, WhatsApp) started once the settings are loaded, one function each. Moved out of spawn_background_subsystems without a change in behaviour.
network πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
plumbing πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
shared_guard πŸ”’
Two AgentMux installs of different versions must not write the shared stores together.
shared_root πŸ”’
A srv given a data folder of its own must not write into the real shared folder by accident.
shutdown πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
state_services πŸ”’
What app_main starts once the app state exists, in the order it started them: the hooks that let an agent be reached and resumed, the job run ledger and the cron scheduler, the sagas an earlier run left unresolved, and the services that run beside the server. Moved out of app_main without a change in behaviour.
store_attach πŸ”’
The steps of open_stores_and_migrate that attach the registries and open each store, one function each, in the order they ran. Moved out of that function without a change in behaviour.
store_boot πŸ”’
The steps of open_stores_and_migrate that prepare the data folder, seed the first launch and install the key resolvers. Moved out of that function without a change in behaviour.
stores πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).
watchers πŸ”’
Split out of the single-file bootstrap module unchanged (SPEC_LARGE_FILE_MODULE_ANALYSIS_2026_09_30.md Β§4.3).

MacrosΒ§

eprintln_lossy πŸ”’
eprintln! that can’t panic. srv’s stderr is a pipe the launcher reads, so once the launcher is gone a write fails with EPIPE (Rust ignores SIGPIPE), and eprintln! panics on a failed write. On the paths that must run when the launcher has died, the parent and stdin watchers, that panic killed the watcher thread before it could shut srv down, which left srv running with no launcher, holding srv.lock, so the app could not be opened again.