{"record":{"id":"a0918fd6e81c4ea3","repo":"astrid-runtime/astrid","slug":"gateway-is-not-wired-to-a-live-kernel-session-ker","errorCode":null,"errorMessage":"gateway is not wired to a live kernel session; kernel requests unavailable","messagePattern":"gateway is not wired to a live kernel session; kernel requests unavailable","errorType":"http","errorClass":"GatewayError::Internal","httpStatus":500,"severity":"error","filePath":"crates/astrid-gateway/src/state.rs","lineNumber":477,"sourceCode":"    /// HTTP routes have already verified the bearer token and resolved the\n    /// caller/device scope. They should not re-enter the external socket\n    /// handshake, because the gateway intentionally does not possess arbitrary\n    /// agent private keys and would be downgraded to `anonymous`.\n    ///\n    /// # Errors\n    /// Returns an internal error if the state was built without a live event\n    /// bus (the standalone tests-only constructor).\n    pub fn kernel_client_for(\n        &self,\n        caller: &crate::auth::CallerContext,\n    ) -> Result<crate::bus_kernel::BusKernelClient, crate::error::GatewayError> {\n        let bus = self.event_bus.clone().ok_or_else(|| {\n            crate::error::GatewayError::Internal(anyhow::anyhow!(\n                \"gateway is not wired to a live event bus; kernel requests unavailable\"\n            ))\n        })?;\n        let session_id = self.session_id.as_ref().ok_or_else(|| {\n            crate::error::GatewayError::Internal(anyhow::anyhow!(\n                \"gateway is not wired to a live kernel session; kernel requests unavailable\"\n            ))\n        })?;\n        Ok(\n            crate::bus_kernel::BusKernelClient::new(bus, caller.principal.clone(), session_id.0)\n                .with_device_key_id(caller.device_key_id.clone()),\n        )\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn rate_limiter_blocks_within_window() {\n        let mut limiter = RedeemRateLimiter::default();\n        let ip: IpAddr = \"127.0.0.1\".parse().unwrap();","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-gateway/src/state.rs#L459-L495","documentation":"A kernel request was attempted with an event bus present but no kernel session id. BusKernelClient requires the session id to route requests to the kernel session, so kernel_client_for() returns GatewayError::Internal when session_id is None.","triggerScenarios":"Calling kernel_client_for() when event_bus is Some but session_id is None — typically a request racing the session handshake or a construction site that never stored the session id.","commonSituations":"Requests served before kernel session registration completes; failed/skipped session handshake in custom gateway embeddings; test setups wiring a bus but no session.","solutions":["Complete the kernel session handshake and store the session id before serving kernel-backed routes","Investigate startup errors from session registration and fix the root cause","Gate routes on readiness so requests wait until state.session_id is Some","Correct the state construction to pass the established session id"],"exampleFix":"// before\nlet state = GatewayState::new(config, Some(event_bus), None)?;\n// after\nlet session_id = handshake(&event_bus).await?;\nlet state = GatewayState::new(config, Some(event_bus), Some(session_id))?;","handlingStrategy":"validation","validationCode":"fn kernel_session_ready(state: &GatewayState) -> bool {\n    state.event_bus.is_some() && state.session_id.is_some()\n}","typeGuard":"fn session_id(state: &GatewayState) -> Option<SessionId> {\n    state.session_id.clone()\n}","tryCatchPattern":"if state.session_id.is_none() {\n    return Err(StatusCode::SERVICE_UNAVAILABLE);\n}\nlet client = state.kernel_client_for(&caller)?;","preventionTips":["Establish and persist the kernel session id before serving kernel routes","Alert on session registration failures during gateway startup","Serialize request serving behind a readiness gate that requires session_id"],"tags":["configuration","session","kernel"],"backgroundTag":"missing-configuration","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}