{"record":{"id":"83fe0a9b56eeba01","repo":"astrid-runtime/astrid","slug":"unexpected-response-from-kernel-body","errorCode":null,"errorMessage":"unexpected response from kernel: {body:?}","messagePattern":"unexpected response from kernel: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/audit.rs","lineNumber":122,"sourceCode":"\nasync fn run_prune(args: &AuditPruneArgs) -> Result<ExitCode> {\n    if args.retain_entries == 0 {\n        bail!(\"--retain-entries must be at least 1\");\n    }\n    if args.retain_bytes == Some(0) {\n        bail!(\"--retain-bytes must be greater than 0\");\n    }\n    let mut client = connect_as_active_agent().await?;\n    let body = into_result(\n        client\n            .request(AdminRequestKind::AuditPrune {\n                retain_entries: args.retain_entries,\n                retain_bytes: args.retain_bytes,\n            })\n            .await?,\n    )?;\n    let AdminResponseBody::AuditPruned(result) = body else {\n        bail!(\"unexpected response from kernel: {body:?}\");\n    };\n    let format = ValueFormat::parse(&args.format);\n    if format.is_pretty() {\n        print_prune_pretty(&result);\n    } else {\n        emit_structured(&result, format)?;\n    }\n    Ok(ExitCode::SUCCESS)\n}\n\nasync fn run_health(args: &AuditHealthArgs) -> Result<ExitCode> {\n    let mut client = connect_as_active_agent().await?;\n    let body = into_result(client.request(AdminRequestKind::AuditHealth).await?)?;\n    let AdminResponseBody::AuditHealth(health) = body else {\n        bail!(\"unexpected response from kernel: {body:?}\");\n    };\n    let degraded = health.degraded;\n    let format = ValueFormat::parse(&args.format);","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/audit.rs#L104-L140","documentation":"In `run_prune` (crates/astrid-cli/src/commands/audit.rs:122), after the AuditPrune request the CLI expects AdminResponseBody::AuditPruned(result); any other body triggers bail! with the debug dump. This ensures the prune command only reports results when the kernel actually returned prune statistics.","triggerScenarios":"The AuditPrune admin request returns a variant other than AuditPruned — kernel rejecting the prune with an error/status body, CLI/kernel protocol skew, or a mis-routed admin reply.","commonSituations":"Kernel version without AuditPruned response support; prune request failing kernel-side (e.g. store lock, permissions) and surfacing as a non-AuditPruned body; admin traffic interleaving on a shared connection.","solutions":["Compare the {body:?} dump in the error against AdminResponseBody variants to identify the actual reply","Upgrade CLI and kernel to matching versions so the prune response contract aligns","Check kernel logs for why the prune did not return an AuditPruned result","Retry the prune after fixing the kernel-side condition"],"exampleFix":"// before\nlet AdminResponseBody::AuditPruned(result) = body else {\n    bail!(\"unexpected response from kernel: {body:?}\");\n};\n// after\nlet AdminResponseBody::AuditPruned(result) = body else {\n    bail!(\n        \"unexpected response from kernel (expected AuditPruned, got {body:?}); \\\n         ensure kernel supports audit prune\"\n    );\n};","handlingStrategy":"type-guard","validationCode":"// Pre-flight: confirm the kernel supports audit prune by checking version/capabilities before sending AuditPrune.","typeGuard":"fn as_audit_pruned(body: AdminResponseBody) -> Option<AuditPruneResult> {\n    match body {\n        AdminResponseBody::AuditPruned(r) => Some(r),\n        _ => None,\n    }\n}","tryCatchPattern":"match run_prune(&args).await {\n    Ok(code) => code,\n    Err(e) if e.to_string().contains(\"unexpected response from kernel\") => {\n        eprintln!(\"prune failed: {e:#}\\nhint: check kernel audit support and CLI/kernel versions\");\n        ExitCode::from(2)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify the kernel supports AuditPruned responses before scripting prune","Keep CLI and kernel versions in lockstep","Check kernel store health (locks, disk) when prune returns a non-AuditPruned body","Log the {body:?} dump on mismatch for diagnosis"],"tags":["cli","ipc","protocol-mismatch","audit"],"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"}