{"record":{"id":"960a25ba9eb2af82","repo":"astrid-runtime/astrid","slug":"ps-failed-while-inspecting-mcp-processes","errorCode":null,"errorMessage":"ps failed while inspecting MCP processes","messagePattern":"ps failed while inspecting MCP processes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/commands/mcp/lifecycle.rs","lineNumber":905,"sourceCode":"        .get(index)\n        .is_some_and(|token| matches!(command_file_name(token), \"astrid\" | \"aos\"))\n}\n\nfn is_reapable_mcp(command: &str) -> bool {\n    is_long_mcp_serve(command) || is_mcp_attach(command)\n}\n\n/// Remove orphaned long-timeout `mcp serve` and `mcp attach` processes.\n///\n/// Never signals Python `aos-mcp-frame` processes. Those abort on 3.14 if a\n/// SIGKILL races `Buffered_close`; attach children are the reap target.\npub(crate) fn gc() -> Result<ExitCode> {\n    let output = Command::new(\"ps\")\n        .args([\"-axo\", \"pid=,ppid=,command=\"])\n        .output()\n        .context(\"failed to inspect MCP processes with ps\")?;\n    if !output.status.success() {\n        anyhow::bail!(\"ps failed while inspecting MCP processes\");\n    }\n    let listing = String::from_utf8_lossy(&output.stdout);\n    let mut reaped = 0_u32;\n    for row in listing.lines().filter_map(parse_process_row) {\n        if row.pid == std::process::id() || !is_reapable_mcp(&row.command) {\n            continue;\n        }\n        let parent_dead =\n            row.ppid == 1 || !crate::commands::daemon_control::is_process_alive(row.ppid);\n        if !parent_dead {\n            continue;\n        }\n        // Re-read the command immediately before signalling to avoid killing a\n        // recycled PID that no longer belongs to a reapable MCP shim.\n        if !process_command(row.pid).is_some_and(|command| is_reapable_mcp(&command)) {\n            continue;\n        }\n        #[cfg(unix)]","sourceCodeStart":887,"sourceCodeEnd":923,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/mcp/lifecycle.rs#L887-L923","documentation":"gc() shells out to `ps -axo pid=,ppid=,command=` to enumerate processes for reaping orphaned MCP servers. If ps runs but exits non-zero, gc cannot enumerate processes and bails with this error. (Launch failure of ps itself produces the context-wrapped 'failed to inspect MCP processes with ps' error instead.)","triggerScenarios":"Running `astrid mcp gc` on a system where the `ps` binary exists but exits with failure — e.g. a restricted/incompatible ps (busybox variants lacking -axo), a broken /proc, or ps blocked by security policy.","commonSituations":"Minimal containers with busybox ps that rejects `-axo pid=,ppid=,command=`; hardened environments blocking ps via seccomp/AppArmor; corrupted PATH picking a shim ps that fails.","solutions":["Verify `ps -axo pid=,ppid=,command=` runs successfully in your shell; fix or replace the failing ps.","Install a full procps ps in the container image (e.g. `apt-get install procps` / Alpine `apk add procps`).","Run astrid outside the sandbox/policy that blocks ps.","Report the issue: gc could fall back to /proc scanning on Linux."],"exampleFix":"// before (Alpine container)\nastrid mcp gc   # -> ps failed while inspecting MCP processes\n// after\napk add procps && astrid mcp gc","handlingStrategy":"fallback","validationCode":"let check = std::process::Command::new(\"ps\")\n    .args([\"-axo\", \"pid=,ppid=,command=\"])\n    .output()?;\nif !check.status.success() {\n    eprintln!(\"ps incompatible; install procps before running astrid mcp gc\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = astrid::mcp::gc() {\n    if e.to_string().contains(\"ps failed\") {\n        eprintln!(\"install procps (apt-get install procps / apk add procps) or run on a host with full ps\");\n    }\n}","preventionTips":["Install procps in minimal container images","Test `ps -axo pid=,ppid=,command=` works before automating gc","Avoid shim/wrapper ps binaries on PATH in hardened environments","Prefer standard Linux base images for astrid workloads"],"tags":["process","cli","ps","subprocess"],"backgroundTag":"command-not-found","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}