{"record":{"id":"e044b792d57bf7c7","repo":"astrid-runtime/astrid","slug":"grant-preflight-returned-an-unexpected-response","errorCode":null,"errorMessage":"grant preflight returned an unexpected response: {other:?}","messagePattern":"grant preflight returned an unexpected response: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/init_grant.rs","lineNumber":156,"sourceCode":"    preflight_sequence(\n        crate::commands::daemon::ensure_daemon(\"init grant preflight\"),\n        || async move {\n            let mut client = crate::admin_client::connect_for_workspace_as(operator.clone())\n                .await\n                .context(\"grant preflight could not connect to the selected workspace daemon\")?;\n            let body = client\n                .request(AdminRequestKind::AgentModify {\n                    principal: target.clone(),\n                    add_groups: Vec::new(),\n                    remove_groups: Vec::new(),\n                    add_capsules: Vec::new(),\n                    remove_capsules: Vec::new(),\n                })\n                .await\n                .context(\"grant preflight request failed\")?;\n            match crate::admin_client::into_result(body)? {\n                AdminResponseBody::Success(_) => Ok(()),\n                other => bail!(\"grant preflight returned an unexpected response: {other:?}\"),\n            }\n        },\n    )\n    .await\n}\n\nasync fn preflight_sequence<E, C, F>(ensure_daemon: E, check: C) -> anyhow::Result<()>\nwhere\n    E: Future<Output = anyhow::Result<()>>,\n    C: FnOnce() -> F,\n    F: Future<Output = anyhow::Result<()>>,\n{\n    ensure_daemon\n        .await\n        .context(\"grant preflight could not ensure the runtime daemon\")?;\n    check().await\n}\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/init_grant.rs#L138-L174","documentation":"preflight_grants sends a grant preflight request to the admin API and expects an AdminResponseBody::Success. Any other response variant triggers this bail, meaning the server replied with something the preflight path does not understand.","triggerScenarios":"The grant preflight HTTP request succeeded (context wraps transport failures separately) but into_result returned a body that is neither Success nor a handled error — an unexpected AdminResponseBody variant.","commonSituations":"Server running a newer/older API version returning a new response variant; a proxy returning an HTML/error page parsed into an unexpected body; misrouted endpoint returning a different admin response type.","solutions":["Check server and CLI versions; align the admin API version so preflight returns Success.","Inspect the `other:?` debug output in the message to see which variant came back and why.","Verify the endpoint URL/protocol (HTTP vs socket, admin route) used for preflight.","Capture the response and report/fix the deserialization mapping for the new variant."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check admin endpoint reachability and version\nlet ok = admin_ping().is_ok();\nif !ok { eprintln!(\"admin API unavailable; preflight will fail\"); }","typeGuard":null,"tryCatchPattern":"match preflight_grants().await {\n    Err(e) if e.to_string().contains(\"unexpected response\") => {\n        eprintln!(\"admin API version mismatch: {e}\");\n        // inspect variant, upgrade CLI/server\n    }\n    Err(e) => return Err(e),\n    Ok(()) => Ok(()),\n}","preventionTips":["Keep admin server and CLI versions aligned.","Log full unexpected variants for diagnosis.","Verify preflight endpoint URLs and protocol in configuration.","Add integration tests covering all AdminResponseBody variants."],"tags":["api","unexpected-response","preflight"],"backgroundTag":"unexpected-api-response-shape","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"}