{"record":{"id":"ae9acca14fcd0d34","repo":"unicity-aos/aos-ce","slug":"aos-mcp-broker-call-install-aos-before-handling-traffic","errorCode":null,"errorMessage":"aos-mcp-broker: call install_aos before handling traffic","messagePattern":"aos-mcp-broker: call install_aos before handling traffic","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/aos-mcp-broker/src/profile.rs","lineNumber":25,"sourceCode":"static IDENTITY: OnceLock<&'static McpIdentity> = OnceLock::new();\n\n/// Install the singleton AOS identity if it is not already set.\npub fn install_aos() {\n    match IDENTITY.set(&McpIdentity::AOS) {\n        Ok(()) => {}\n        Err(existing) => assert!(\n            core::ptr::eq(existing, &McpIdentity::AOS),\n            \"aos-mcp-broker: identity already installed\"\n        ),\n    }\n}\n\n#[inline]\nfn identity() -> &'static McpIdentity {\n    IDENTITY\n        .get()\n        .copied()\n        .expect(\"aos-mcp-broker: call install_aos before handling traffic\")\n}\n\n#[inline]\npub(crate) fn log_tag() -> &'static str {\n    identity().log_tag\n}\n\n#[inline]\npub(crate) fn mcp_tool_prefix() -> &'static str {\n    identity().mcp_tool_prefix\n}\n\n#[inline]\npub(crate) fn tools_list_topic() -> &'static str {\n    identity().tools_list_topic\n}\n\n#[inline]","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/crates/aos-mcp-broker/src/profile.rs#L7-L43","documentation":"This is a panic from an internal OnceCell-style registry: `McpIdentity` was never installed, so `identity()` cannot return a value and the `.expect` aborts. The broker requires `install_aos` (which populates IDENTITY) to run before any MCP traffic handling. It is an initialization-ordering guard, not a data error.","triggerScenarios":"Calling `log_tag()`, `mcp_tool_prefix()`, `tools_list_topic()`, or `audit_topic()` before `install_aos(...)` has been invoked; also any request handler path that transitively calls `identity()` during early startup or in tests that skip setup.","commonSituations":"Forgetting broker initialization in a new binary entrypoint, constructing MCP tool names/audit topics in static or lazy contexts that run before install, or writing unit tests that call helper functions without a setup harness.","solutions":["Call `install_aos(...)` with the proper McpIdentity at process startup, before any request handling or topic/tag lookup.","Check that the code path calling log_tag/mcp_tool_prefix/tools_list_topic/audit_topic is not executed before initialization (move it after init or defer it).","In tests, add a setup fixture that calls install_aos once before the helpers under test."],"exampleFix":"// before\nlet tag = broker::log_tag();\n\n// after\nbroker::install_aos(&identity_config);\nlet tag = broker::log_tag();","handlingStrategy":"try-catch","validationCode":"// Rust: guard before calling helpers\nassert!(broker::is_initialized(), \"call install_aos before handling traffic\");\nlet tag = broker::log_tag();","typeGuard":"fn identity_installed() -> bool { broker::is_initialized() }","tryCatchPattern":"// Use std::panic::catch_unwind only at the boundary; the real fix is init ordering\nlet tag = std::panic::catch_unwind(broker::log_tag)\n    .unwrap_or_else(|_| \"uninitialized\");","preventionTips":["Call install_aos as the first statement in main before spawning any handlers.","Add an integration test that exercises every public broker helper in a fresh process.","Route helper access through a single init-checked entry point."],"tags":["initialization","panic","lifecycle","mcp"],"backgroundTag":"module-init-failed","analyzedSha":"f6f22024fb1e8d122f28a1b4a9f75aee448ae839","analyzedAt":"2026-09-13T03:04:44.565Z","contentChangedAt":"2026-09-13T03:04:44.565Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}