Expand description
v0.7.x (issue #1174 follow-up #1192 / #1196) — cross-surface
RuntimeContext for substrate state that spans the HTTP daemon,
the MCP stdio binary, and the CLI.
§Why this module exists
Pre-#1192 / #1196 the substrate carried a handful of process-wide
static slots — webhook HMAC override, transcript decompression
cap, audit sink + sequence counter, session-recall tracker, X25519
keypair cache — that none of AppState (HTTP), the MCP
Connection, or the per-command CLI handlers could own jointly.
PR7 (#1192) and PR8 (#1196) on release/v0.7.0 identified that the
correct refactor is a single Arc<RuntimeContext> that all three
surfaces can hold and that internally backs every former static.
This module is that struct. The design preserves the existing
public surface (e.g. crate::config::active_hooks_hmac_secret,
crate::audit::emit, crate::reranker::global_session_recall_tracker)
— those accessors now delegate to the process-wide
RuntimeContext singleton. The wire / chain / cache semantics are
byte-for-byte unchanged; the storage merely moved from
static FOO: ... = ... to a field on RuntimeContext.
§Singleton vs. injected instance
RuntimeContext is a struct, not a global. Tests construct fresh
instances via RuntimeContext::default and exercise the typed
accessors directly; production code wires a single instance through
RuntimeContext::install_global at boot so the legacy free
functions (crate::config::set_active_hooks_hmac_secret,
crate::audit::emit, etc.) keep working without churning ~60
callsites across the codebase.
The global() accessor returns &'static RuntimeContext (via a
LazyLock-style OnceLock seeded on first read). Install order
matters only at the very first read; once a context is installed it
sticks for the lifetime of the process, matching the prior
OnceLock / RwLock<Option<...>> semantics of every individual
extracted static.
Structs§
- Audit
State - V-4 audit chain state. Owns the same
(sink, sequence)pair the pre-#1192src/audit.rsmodule-level statics owned; the publiccrate::audit::*functions delegate here. - Runtime
Context - Cross-surface substrate state.