Expand description
Process-wide state threaded into every bare-naked command::*::execute.
Context is constructed once in main.rs (or by a programmatic
embedder) — synchronously and infallibly, no IO — then borrowed
into the command tree. The three service clients are LAZY: the
first api_client() / viewer_client() / db_client() call
resolves the server’s address (on-disk config, else the matching
spawn flow, which itself short-circuits to the lock-published URL
when the server is already up), builds the client, and memoizes it
in a tokio::sync::OnceCell shared across Context clones (Arc).
Concurrent callers coalesce on one initialization; a failed init
is not cached, so the next call retries. Commands that never touch
a service never spawn or connect to it.
Identity hazard: the memoized API HttpClient snapshots
config.agent_instance_hierarchy + config.mcp_session_id into
headers. A clone that mutates those fields MUST call
Context::reset_api_client afterwards — see that method’s doc.