{"record":{"id":"0b656705c399be96","repo":"astrid-runtime/astrid","slug":"mcp-attach-host-session-key-is-empty","errorCode":null,"errorMessage":"MCP attach host session key is empty","messagePattern":"MCP attach host session key is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/mcp/attach.rs","lineNumber":100,"sourceCode":"}\n\nfn build_registration(\n    caller: &astrid_core::PrincipalId,\n    workspace: Option<&Path>,\n    ready: &super::lifecycle::GatewayReady,\n) -> Result<AttachRegistration> {\n    let host = std::env::var(\"ASTRID_HOST\")\n        .or_else(|_| std::env::var(\"AOS_MCP_HOST\"))\n        .or_else(|_| std::env::var(\"MCP_HOST\"))\n        .ok()\n        .filter(|value| !value.trim().is_empty())\n        .unwrap_or_else(|| \"aos\".to_owned());\n    let host_session_id = std::env::var(\"ASTRID_SESSION_ID\")\n        .or_else(|_| std::env::var(\"AOS_MCP_SESSION_ID\"))\n        .or_else(|_| std::env::var(\"MCP_SESSION_ID\"))\n        .context(\"MCP attach requires the host session key in ASTRID_SESSION_ID\")?;\n    if host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host session key is empty\");\n    }\n    build_registration_with_context(caller, workspace, ready, &host, &host_session_id)\n}\n\nfn build_registration_with_context(\n    caller: &astrid_core::PrincipalId,\n    workspace: Option<&Path>,\n    ready: &super::lifecycle::GatewayReady,\n    host: &str,\n    host_session_id: &str,\n) -> Result<AttachRegistration> {\n    if host.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host is empty\");\n    }\n    if host_session_id.trim().is_empty() {\n        anyhow::bail!(\"MCP attach host session key is empty\");\n    }\n    let workspace_abs = absolute_workspace(workspace)?;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/mcp/attach.rs#L82-L118","documentation":"build_registration reads the host session key from ASTRID_SESSION_ID (falling back to AOS_MCP_SESSION_ID / MCP_SESSION_ID). If the variable is not set at all, the .context() error surfaces; if it is set but blank/whitespace, this explicit error is thrown, since an empty session key would produce an unusable attach registration.","triggerScenarios":"`aos mcp attach` with ASTRID_SESSION_ID (or fallback vars) set to \"\" or whitespace only.","commonSituations":"Exporting ASTRID_SESSION_ID= empty in a shell profile; a wrapper script exporting the var before assigning it; CI templates with an unfilled placeholder.","solutions":["Set ASTRID_SESSION_ID to a non-empty session identifier before attaching","Verify no empty override: `echo \"[$ASTRID_SESSION_ID]\"`","Remove blank AOS_MCP_SESSION_ID / MCP_SESSION_ID exports that shadow a valid value"],"exampleFix":"// before\nexport ASTRID_SESSION_ID=\naos mcp attach\n// after\nexport ASTRID_SESSION_ID=\"sess-8f3c...\"\naos mcp attach","handlingStrategy":"validation","validationCode":"let sid = std::env::var(\"ASTRID_SESSION_ID\").unwrap_or_default();\nif sid.trim().is_empty() { return Err(\"ASTRID_SESSION_ID must be a non-empty session key\"); }","typeGuard":"fn has_session_key() -> bool { std::env::var(\"ASTRID_SESSION_ID\").map(|v| !v.trim().is_empty()).unwrap_or(false) }","tryCatchPattern":"match std::env::var(\"ASTRID_SESSION_ID\") {\n    Ok(v) if !v.trim().is_empty() => { /* proceed */ }\n    _ => return Err(anyhow!(\"set a non-empty ASTRID_SESSION_ID before mcp attach\")),\n}","preventionTips":["Export ASTRID_SESSION_ID in every shell that runs attach","Never leave the var set-but-empty in profiles/CI templates","Check `echo \"[$ASTRID_SESSION_ID]\"` when attach fails"],"tags":["mcp","env","validation"],"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"}