{"record":{"id":"dc26c2bf1ce1a9b6","repo":"astrid-runtime/astrid","slug":"mcp-attach-registration-has-an-empty-host-session","errorCode":null,"errorMessage":"MCP attach registration has an empty host_session_id","messagePattern":"MCP attach registration has an empty host_session_id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/mcp/gateway.rs","lineNumber":931,"sourceCode":"        },\n        GatewayRequest::Attach(registration) => validate_registration(registration)?,\n    }\n    Ok(request)\n}\n\nfn validate_registration(registration: &AttachRegistration) -> Result<()> {\n    if registration.version != ATTACH_REGISTRATION_VERSION {\n        anyhow::bail!(\n            \"unsupported MCP attach registration version {}\",\n            registration.version\n        );\n    }\n    super::lifecycle::resolve_principal(Some(&registration.principal))?;\n    if registration.host.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration has an empty host\");\n    }\n    if registration.host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration has an empty host_session_id\");\n    }\n    if registration.hook_token.trim().is_empty() {\n        anyhow::bail!(\"MCP attach registration is missing hook_token\");\n    }\n    validate_workspace(&registration.workspace_abs)?;\n    Ok(())\n}\n\nfn authenticate_registration(\n    registration: &AttachRegistration,\n    state: &GatewayState,\n) -> Result<astrid_core::PrincipalId> {\n    let principal = super::lifecycle::resolve_principal(Some(&registration.principal))?;\n    if principal != state.principal {\n        anyhow::bail!(\n            \"MCP attach registration principal '{}' is not the authenticated gateway principal '{}'\",\n            principal,\n            state.principal","sourceCodeStart":913,"sourceCodeEnd":949,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/mcp/gateway.rs#L913-L949","documentation":"validate_registration checks that an MCP attach registration payload carries all required identity fields before the gateway accepts it. The host_session_id identifies which gateway session the attach request belongs to; when it is absent or whitespace-only, the gateway cannot correlate the request and bails immediately. This is a fail-fast guard on the wire protocol.","triggerScenarios":"Calling the MCP attach flow (read_gateway_request_inner -> validate_registration) with a serialized AttachRegistration whose host_session_id field is missing, empty, or contains only whitespace.","commonSituations":"A hand-written JSON registration payload omitting host_session_id; a client library or older client version that doesn't send the field; template/config placeholders left unfilled (\"\"); env interpolation producing whitespace.","solutions":["Set host_session_id to the gateway session identifier returned by the gateway startup/lifecycle flow before sending the attach request","If hand-building the payload, add the host_session_id field explicitly","Check client version compatibility — older clients may not populate host_session_id; upgrade or add it to the payload","Trim/verify the value on the client side before submitting"],"exampleFix":"// before\nlet registration = AttachRegistration { host: \"127.0.0.1:0\".into(), host_session_id: \"\".into(), .. };\n// after\nlet registration = AttachRegistration { host: \"127.0.0.1:0\".into(), host_session_id: lease.boot_token.clone(), .. };","handlingStrategy":"validation","validationCode":"fn ensure_registration(reg: &AttachRegistration) -> Result<(), String> {\n    if reg.host_session_id.trim().is_empty() { return Err(\"host_session_id is required\".into()); }\n    Ok(())\n}","typeGuard":"fn has_host_session_id(reg: &AttachRegistration) -> bool { !reg.host_session_id.trim().is_empty() }","tryCatchPattern":null,"preventionTips":["Always copy host_session_id from the gateway startup lease, never hardcode","Validate registration fields client-side before serialization","Watch for env interpolation producing empty strings in configs"],"tags":["validation","mcp","ipc"],"backgroundTag":"empty-required-field","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}