{"record":{"id":"c93194f32c09cddf","repo":"astrid-runtime/astrid","slug":"daemon-rejected-capsule-removal-message","errorCode":null,"errorMessage":"daemon rejected capsule removal: {message}","messagePattern":"daemon rejected capsule removal: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/dispatch.rs","lineNumber":467,"sourceCode":"        .await?\n    {\n        astrid_core::kernel_api::KernelResponse::Success(_) => {\n            if purge {\n                let principal = crate::principal::current();\n                let entries =\n                    commands::capsule::install_headless::list_env_entries(&principal, &name)?;\n                for entry in entries {\n                    if matches!(entry.scope, astrid_core::kernel_api::EnvStorageScope::Agent) {\n                        commands::capsule::install_headless::delete_env_entry(\n                            &principal, &name, &entry.key, entry.kind,\n                        )?;\n                    }\n                }\n            }\n            eprintln!(\"Removed '{name}'.\");\n        },\n        astrid_core::kernel_api::KernelResponse::Error(message) => {\n            anyhow::bail!(\"daemon rejected capsule removal: {message}\");\n        },\n        other => anyhow::bail!(\"unexpected daemon response: {other:?}\"),\n    }\n    Ok(ExitCode::SUCCESS)\n}\n\nasync fn dispatch_mcp(command: McpCommands) -> Result<ExitCode> {\n    if !matches!(command, McpCommands::Gc) {\n        commands::daemon::validate_runtime_admission()?;\n    }\n    match command {\n        McpCommands::Serve {\n            workspace,\n            request_timeout: _,\n        } => commands::mcp::serve(None, workspace.as_deref()).await,\n        McpCommands::Attach { workspace } => {\n            commands::mcp::attach(None, workspace.as_deref()).await\n        },","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/dispatch.rs#L449-L485","documentation":"`dispatch_capsule_remove` sends a removal request to the astrid daemon and expects a success response. When the daemon replies with `KernelResponse::Error(message)`, the CLI surfaces the daemon's rejection message wrapped in this bail instead of proceeding to print \"Removed\".","triggerScenarios":"Running a capsule remove command when the daemon cannot perform the removal — e.g. the capsule does not exist, is currently running, or the daemon's kernel refuses the operation — and responds with an Error variant.","commonSituations":"Removing a typo'd or already-deleted capsule name; attempting to remove a capsule with running processes or open references; daemon-side permission or state problems.","solutions":["Read the daemon's message after the colon — it states the actual rejection reason — and address it (fix the capsule name, stop the capsule, etc.).","Verify the capsule exists and is stopped with a list/status command before removing.","Restart the daemon if the capsule is in a stuck state, then retry the removal."],"exampleFix":"// before: removing a running/unknown capsule fails\nastrid capsule remove my-capsule\n// after: check state first, stop, then remove\nastrid capsule list\nastrid capsule stop my-capsule\nastrid capsule remove my-capsule","handlingStrategy":"try-catch","validationCode":"// before removing, confirm the capsule exists and is stopped\nlet status = daemon_client.status(capsule_name)?;\nif !status.exists { return Err(format!(\"capsule '{capsule_name}' not found\").into()); }\nif status.running { return Err(format!(\"stop capsule '{capsule_name}' before removing\").into()); }","typeGuard":"fn is_kernel_success(resp: &astrid_core::kernel_api::KernelResponse) -> bool {\n    !matches!(resp, astrid_core::kernel_api::KernelResponse::Error(_))\n}","tryCatchPattern":"match dispatch_capsule_remove(name) {\n    Err(e) if e.to_string().starts_with(\"daemon rejected capsule removal\") => {\n        let reason = e.to_string().splitn(2, \": \").nth(1).unwrap_or(\"unknown\");\n        eprintln!(\"removal rejected by daemon: {reason}\");\n    }\n    other => other?,\n}","preventionTips":["Verify the exact capsule name with a list command before removal.","Stop running capsules before attempting removal.","Inspect and act on the daemon's rejection message rather than retrying blindly."],"tags":["daemon","capsule","cli"],"backgroundTag":"api-error-response","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"}