Expand description
Daemon runtime — orchestration shell for the ai-memory binary.
W6 lifted serve() and the top-level dispatch out of main.rs so the
production HTTP daemon, the integration test harness, and the
coverage-instrumented tests in this module all share one source of
truth. main.rs keeps its #[tokio::main] entry point but immediately
delegates here for every subcommand.
§Public surface (post-W6)
run— top-level CLI dispatch (called frommain()).serve— full HTTP daemon body (TLS or plain).bootstrap_serve— testable struct-returning state builder.build_router— composition wrapper aroundlib::build_router.build_embedder,build_vector_index— single canonical builders used by bothserve()andcli::recall::run.spawn_gc_loop,spawn_wal_checkpoint_loop— daemon background tasks, returning aJoinHandleso callers can abort on shutdown.is_write_command— write-command predicate driving the post-write WAL checkpoint.passphrase_from_file,apply_anonymize_default— startup helpers.
§Pre-W6 helpers retained
serve_http_with_shutdown,serve_http_with_shutdown_future— the in-process HTTP harness the integration suite drives.run_sync_daemon_with_shutdown,run_sync_daemon_with_shutdown_using_client,sync_cycle_once— the sync-daemon body.run_curator_daemon_with_shutdown,run_curator_daemon_with_primitives— the curator-daemon body.
Structs§
- Bench
Args - Cli
- Completions
Args - Doctor
CliArgs - Arguments for the
doctorsubcommand. Lives next toCliso clap derives them automatically; the actual report logic lives incli::doctor::run. - Governance
CliArgs ai-memory governanceparent argument struct.- Serve
Args - Serve
Bootstrap - Aggregated state produced by
bootstrap_serve.
Enums§
- Command
- Governance
Action ai-memory governancesub-subcommands. K11 migrator + 7th-forminstall-defaults(issue #760) bulk-activator for seed rules R001-R004 live here; future K-track work may add more verbs (lint,explain, …) so the surface is shaped as an enum from day one.
Functions§
- apply_
anonymize_ default - Apply the configured
anonymize_defaultto the runtime env: when the config asks for anonymization but the user hasn’t already setAI_MEMORY_ANONYMIZE, set it to"1". Idempotent — repeated calls are a no-op once the env var is set. - bootstrap_
serve - Build all daemon state and spawn background tasks. Returns the aggregated state without binding any sockets — testable in isolation.
- build_
embedder - Construct the
Embedderfor a given tier. ReturnsNonefor the keyword tier (no embedder requested) and on load failure (caller degrades to keyword fallback). On failure the diagnostic is emitted viatracing::error!so operators see it injournalctl. - build_
llm_ client - v0.7.0 L5 — construct the LLM [
OllamaClient] for autonomy-hook capable feature tiers (smart/autonomous). ReturnsNonefor thekeyword/semantictiers (nollm_modeldeclared in the [TierConfig]) and on Ollama unreachability (caller degrades to non-LLM behaviour). On failure the diagnostic is emitted viatracing::warn!so operators see it injournalctlwithout killing the daemon — autonomy hooks are best-effort and the store path must keep working when Ollama is offline. - build_
router - Compose the production HTTP router. Thin wrapper around
crate::build_router(the W3-vintage source of truth for the route table).daemon_runtime::build_routerexists so test code in this module can build the router without namingcrate::build_routerdirectly, and so future router-composition logic (e.g. middleware reorder, custom layers) lives in one place. - build_
vector_ index - Build the in-memory
VectorIndexfromconn. Whenembedder_presentis false, returnsNone(the keyword-only path doesn’t need an index). When the embedder is present but the DB is empty (or query errors), returnsSome(VectorIndex::empty())so write paths can populate it in-place. - is_
write_ command - Returns true if
cmdis a write-class subcommand. The post-run WAL checkpoint inrunruns only when this returnstrue. - passphrase_
from_ file - Read the
SQLCipherpassphrase frompath. Strips a single trailing newline / CRLF; rejects an empty passphrase (post-strip) with an error; preserves all other internal whitespace. - resolve_
admin_ agent_ ids - #976 (2026-05-20) — resolve the admin-allowlist with env-var
precedence over the config-file
[admin].agent_idsblock. - run
- Top-level CLI dispatch. Called from
main()afterCli::parse(). - run_
curator_ daemon_ with_ primitives - Curator-daemon loop body, primitive-arg flavour for the binary.
- run_
curator_ daemon_ with_ shutdown - Run the curator daemon with a programmable shutdown.
- run_
sync_ daemon_ with_ shutdown - Run the sync-daemon main loop with a programmable shutdown.
- run_
sync_ daemon_ with_ shutdown_ using_ client - Variant of
run_sync_daemon_with_shutdownthat takes a caller-builtreqwest::Client. The productioncmd_sync_daemon()constructs an mTLS-aware client (viabuild_rustls_client_config) and threads it in here so the helper drives the same loop body the test version drives — keepingdaemon_runtimeas the single source of truth for the sync-daemon loop while preserving the production TLS contract. - serve
- Run the HTTP memory daemon. Loads TLS state, builds
AppState, spawns the GC + WAL-checkpoint loops, and binds a listener (TLS or plain HTTP). - serve_
http_ with_ shutdown - Run the HTTP daemon (plain HTTP, no TLS) with a programmable shutdown.
- serve_
http_ with_ shutdown_ future - Variant of
serve_http_with_shutdownthat takes an arbitrary shutdown future. The productionserve()needs to run a WAL checkpoint after the OS signal but before tearing down the listener; that cleanup work is awkward to express through aNotifyalone. Accepting aFuturelets the caller embed any async cleanup into the shutdown future itself, while the helper keeps thebuild_router+TcpListener::bind+axum::servebody it already owns. - serve_
http_ with_ shutdown_ future_ and_ timeout - v0.7.0 H7 (round-2) — variant of
serve_http_with_shutdown_futurethat accepts an explicit per-request timeout. Used by tests to drive the slow-POST edge directly. - spawn_
agent_ quota_ reset_ loop - v0.7.0 K8 — spawn the periodic agent-quota daily-counter reset sweeper.
- spawn_
gc_ loop - Spawn the periodic GC loop. Sleeps
interval, then runsdb::gc,db::auto_purge_archive, and (Cluster G, #767) the shadow- observation retention sweep against the daemon’s shared connection. The returnedJoinHandleis owned by the caller;serve()aborts it on shutdown. - spawn_
gc_ loop_ with_ shadow_ retention - Cluster G (#767) —
spawn_gc_loopvariant that takes an explicit shadow-observation retention window. Used bybootstrap_serveso the operator-tunable[confidence] shadow_retention_daysfromconfig.tomlflows through.spawn_gc_loopis the no-arg wrapper that picks the compiled default for legacy call sites (tests). - spawn_
pending_ timeout_ sweep_ loop - v0.7.0 K2 — spawn the periodic
pending_actionstimeout sweeper. - spawn_
transcript_ lifecycle_ sweep_ loop - v0.7.0 I3 — spawn the periodic transcript archive→prune sweeper.
- spawn_
vector_ index_ boot_ load - #1579 B3 — async boot HNSW warm-up for
serve. - spawn_
wal_ checkpoint_ loop - Spawn the periodic WAL checkpoint loop. First checkpoint runs
interval / 2after start (staggered from the GC loop to avoid lock-contention bursts on cold start), then on a fixed cadence. - sync_
cycle_ once - Run a single sync cycle against one peer — pull then push.