astrid-runtime/astrid · error

unexpected response from kernel: {body:?}

Error message

unexpected response from kernel: {body:?}

What it means

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.

Source

Thrown at crates/astrid-cli/src/commands/audit.rs:122

async fn run_prune(args: &AuditPruneArgs) -> Result<ExitCode> {
    if args.retain_entries == 0 {
        bail!("--retain-entries must be at least 1");
    }
    if args.retain_bytes == Some(0) {
        bail!("--retain-bytes must be greater than 0");
    }
    let mut client = connect_as_active_agent().await?;
    let body = into_result(
        client
            .request(AdminRequestKind::AuditPrune {
                retain_entries: args.retain_entries,
                retain_bytes: args.retain_bytes,
            })
            .await?,
    )?;
    let AdminResponseBody::AuditPruned(result) = body else {
        bail!("unexpected response from kernel: {body:?}");
    };
    let format = ValueFormat::parse(&args.format);
    if format.is_pretty() {
        print_prune_pretty(&result);
    } else {
        emit_structured(&result, format)?;
    }
    Ok(ExitCode::SUCCESS)
}

async fn run_health(args: &AuditHealthArgs) -> Result<ExitCode> {
    let mut client = connect_as_active_agent().await?;
    let body = into_result(client.request(AdminRequestKind::AuditHealth).await?)?;
    let AdminResponseBody::AuditHealth(health) = body else {
        bail!("unexpected response from kernel: {body:?}");
    };
    let degraded = health.degraded;
    let format = ValueFormat::parse(&args.format);

View on GitHub (pinned to affd8760f4)

Solutions

  1. Compare the {body:?} dump in the error against AdminResponseBody variants to identify the actual reply
  2. Upgrade CLI and kernel to matching versions so the prune response contract aligns
  3. Check kernel logs for why the prune did not return an AuditPruned result
  4. Retry the prune after fixing the kernel-side condition

Example fix

// before
let AdminResponseBody::AuditPruned(result) = body else {
    bail!("unexpected response from kernel: {body:?}");
};
// after
let AdminResponseBody::AuditPruned(result) = body else {
    bail!(
        "unexpected response from kernel (expected AuditPruned, got {body:?}); \
         ensure kernel supports audit prune"
    );
};
Defensive patterns

Strategy: type-guard

Validate before calling

// Pre-flight: confirm the kernel supports audit prune by checking version/capabilities before sending AuditPrune.

Type guard

fn as_audit_pruned(body: AdminResponseBody) -> Option<AuditPruneResult> {
    match body {
        AdminResponseBody::AuditPruned(r) => Some(r),
        _ => None,
    }
}

Try / catch

match run_prune(&args).await {
    Ok(code) => code,
    Err(e) if e.to_string().contains("unexpected response from kernel") => {
        eprintln!("prune failed: {e:#}\nhint: check kernel audit support and CLI/kernel versions");
        ExitCode::from(2)
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/83fe0a9b56eeba01. Report an issue: GitHub.