{"record":{"id":"6a8f7589ac90936e","repo":"astrid-runtime/astrid","slug":"unexpected-response-while-resolving-principal-uid","errorCode":null,"errorMessage":"unexpected response while resolving principal UID: {body:?}","messagePattern":"unexpected response while resolving principal UID: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/logs.rs","lineNumber":64,"sourceCode":"        let entry = entry?;\n        let path = entry.path();\n        if !path.is_file() {\n            continue;\n        }\n        let modified = entry.metadata()?.modified()?;\n        if newest.as_ref().is_none_or(|(t, _)| *t < modified) {\n            newest = Some((modified, path));\n        }\n    }\n    Ok(newest.map(|(_, p)| p))\n}\n\nasync fn resolve_principal_uid(principal: &PrincipalId) -> Result<PrincipalUid> {\n    let mut client = crate::admin_client::connect_as_active_agent().await?;\n    let body = client.request(AdminRequestKind::AgentList).await?;\n    let body = crate::admin_client::into_result(body)?;\n    let AdminResponseBody::AgentList(entries) = body else {\n        anyhow::bail!(\"unexpected response while resolving principal UID: {body:?}\");\n    };\n    entries\n        .into_iter()\n        .find(|entry| entry.principal == *principal)\n        .and_then(|entry| entry.owner_uid)\n        .ok_or_else(|| anyhow::anyhow!(\"principal '{principal}' has no admitted durable UID\"))\n}\n\nasync fn resolve_log_dir(principal: &PrincipalId, capsule: Option<&str>) -> Result<PathBuf> {\n    let home = AstridHome::resolve().context(\"Failed to resolve Astrid home directory\")?;\n    Ok(match capsule {\n        // Capsule runtime logs are operational state, not home content. The\n        // daemon's immutable-UID projection owns the canonical path; resolve\n        // the UID through the authenticated admin roster before reading it.\n        Some(name) => home\n            .log_dir()\n            .join(\"principals\")\n            .join(resolve_principal_uid(principal).await?.to_string())","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/logs.rs#L46-L82","documentation":"resolve_principal_uid asks the admin daemon for the agent list to map a principal to its durable UID. If the daemon returns a response body whose variant is not AgentList, the CLI cannot interpret it and throws this error — usually indicating a protocol/version mismatch between CLI and daemon.","triggerScenarios":"`aos logs` resolving a log directory when the admin daemon replies to AgentList with a different AdminResponseBody variant (wrong daemon version, request routed to a non-agent-list endpoint, or corrupted response).","commonSituations":"Running a newer CLI against an older daemon (or vice versa); pointing the CLI at a different admin service that answers differently; a proxy/middleware rewriting responses.","solutions":["Restart the admin daemon and retry the command","Upgrade the CLI and daemon to matching versions","Check that the CLI's admin endpoint config points at the correct astrid admin daemon"],"exampleFix":"// before\n# CLI v2 -> daemon v1\n$ aos logs --principal alice\n// after\n$ aos version && aos daemon version  # align both, restart daemon\n$ aos logs --principal alice","handlingStrategy":"retry","validationCode":"// Verify daemon reachability and version parity before the call\nassert!(admin_daemon_reachable());\nassert_eq!(cli_version(), daemon_version());","typeGuard":"if let AdminResponseBody::AgentList(entries) = body { /* proceed */ } else { /* version mismatch */ }","tryCatchPattern":"match resolve_principal_uid(&principal).await {\n    Err(e) if e.to_string().contains(\"unexpected response\") => {\n        // restart/upgrade daemon, then retry once\n    }\n    other => other,\n}","preventionTips":["Keep CLI and daemon versions in lockstep","Pin daemon version in CI","Check daemon logs when response shapes look off"],"tags":["rpc","protocol-mismatch","daemon"],"backgroundTag":"unexpected-response-shape","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"}