Architecture: Daemon and Services¶
This document describes the YAMS daemon runtime strictly in terms of its implementation. Each subsection references the concrete source files that execute the behavior.
Runtime Responsibilities (src/daemon/daemon.cpp)¶
YamsDaemon::YamsDaemonresolves socket, PID, and log paths, seedsYAMS_IN_DAEMON, and installs plugin directory configuration before any service starts.YamsDaemon::startdrives a phased boot sequence: reset the lifecycle FSM, initializeLifecycleComponent, startTuningManager, bring upServiceManager, and finally bind the IPC socket viaSocketServer.YamsDaemon::stopshuts down the IPC server, stops services, and clears lifecycle state, ensuringrunning_flips false exactly once.
Service Coordination (src/daemon/components/ServiceManager.cpp)¶
ServiceManager::startAllinstantiates the content store, metadata database, vector backend, and ingestion services, wiring them through a sharedWorkerPool.- The manager also exposes
ServiceManager::autoloadPluginsNow, which consults the trust store and loads eligible plugins via thePluginLoader. - Maintenance helpers (
ServiceManager::scheduleMaintenance,ServiceManager::shutdownAll) back pressure ingestion and search workers before teardown.
Lifecycle State Machine (src/daemon/components/DaemonLifecycleFsm.cpp)¶
- The FSM enumerates states such as
Starting,Ready,Draining, andStopped; transitions are triggered by explicit events fromYamsDaemon::start/stopand watchdogs. - Each transition publishes
LifecycleEventobjects thatDaemonMetricsingests to expose readiness levels to clients.
Metrics and Health (src/daemon/components/DaemonMetrics.cpp)¶
DaemonMetrics::recordStartupPhaseattaches timestamps to each startup stage and surfaces them through IPCStatusreplies.DaemonMetrics::snapshotaggregates worker pool depth, pending ingest counts, vector backlogs, and plugin status so the CLI and API can render health summaries.
IPC Contract (include/yams/daemon/ipc/ipc_protocol.h, src/daemon/ipc/ipc_protocol.cpp)¶
IpcEnvelopedefines message framing, version headers, and payload routing identifiers.serialize_envelope/deserialize_envelopeenforce length-prefix encoding and emit typed errors used byconnection_fsmwhen envelopes are malformed or time out.
Plugin Hosting (src/daemon/resource/*.cpp)¶
PluginLoader::loadPlugin(plugin_loader.cpp) dlopens shared objects, inspects exported factory symbols, and rejects libraries that expose neither model providers nor graph adapters.PluginHost::trustandPluginHost::enumerateTrusted(plugin_host.cpp) maintain the on-disk trust manifest and gate which plugin pathsServiceManager::autoloadPluginsNowwill admit.AbiPluginLoaderandWasmRuntimeconstruct ABI shims (abi_plugin_loader.cpp) or WASM instances (wasm_runtime.cpp) to bind plugin callbacks into daemon services.
Keep this document synchronized with docs/delivery/038/artifacts/architecture-traceability.md when responsibilities move or new subsystems are introduced.