{"record":{"id":"de146b32c391ce8e","repo":"astrid-runtime/astrid","slug":"cannot-confirm-pid-p-is-the-astrid-daemon-possi","errorCode":null,"errorMessage":"Cannot confirm PID {p} is the Astrid daemon (possible PID reuse); refusing to auto-restart. Inspect PID {p} — if it is not Astrid, remove {pid_path} and retry.","messagePattern":"Cannot confirm PID (.+?) is the Astrid daemon \\(possible PID reuse\\); refusing to auto-restart\\. Inspect PID (.+?) — if it is not Astrid, remove (.+?) and retry\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/astrid-cli/src/commands/restart.rs","lineNumber":78,"sourceCode":"            \"{}\",\n            Theme::warning(&format!(\n                \"A process holding the recorded daemon PID {pid} is still alive after stop — \\\n                 verifying before restart.\"\n            ))\n        );\n        match daemon_control::terminate_orphan(&pid_path).await {\n            daemon_control::KillOutcome::StillAlive => {\n                anyhow::bail!(\n                    \"The previous Astrid daemon (PID {pid}) did not exit even after SIGKILL; \\\n                     refusing to start a second daemon while the lock may still be held.\"\n                );\n            },\n            daemon_control::KillOutcome::Unverified(p) => {\n                // Fail-secure: a live PID we can't confirm is the daemon (likely\n                // PID reuse) is NOT killed. Don't blindly spawn either — if it\n                // *were* the daemon, the lock is still held and the spawn would\n                // fail on it anyway. Make the operator resolve it explicitly.\n                anyhow::bail!(\n                    \"Cannot confirm PID {p} is the Astrid daemon (possible PID reuse); \\\n                     refusing to auto-restart. Inspect PID {p} — if it is not Astrid, \\\n                     remove {} and retry.\",\n                    pid_path.display()\n                );\n            },\n            _ => {\n                let _ = std::fs::remove_file(&pid_path);\n            },\n        }\n    }\n\n    daemon::spawn_persistent_daemon().await?;\n    drop(start_fence);\n    Ok(ExitCode::SUCCESS)\n}\n","sourceCodeStart":60,"sourceCodeEnd":95,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/commands/restart.rs#L60-L95","documentation":"When restart's `terminate_orphan` returns `Unverified(p)`, a live process occupies the recorded PID but the CLI cannot confirm it is the Astrid daemon — likely PID reuse by an unrelated process. By design it does not kill the process or spawn a new daemon; it demands the operator resolve the ambiguity explicitly (fail-secure behavior).","triggerScenarios":"A stale pid file whose PID was recycled by another application between daemon death and restart; kill-verification cannot match the process to Astrid.","commonSituations":"Long-lived machines with high PID churn, pid files left behind after a crash, containers restarting with overlapping PID namespaces.","solutions":["Check what PID p actually is: `ps -p <p> -o pid,cmd`","If it is not Astrid, delete the pid file (`rm <pid_path>`) and rerun `astrid restart`","If it IS a leftover Astrid daemon, kill it manually, confirm exit, then restart","Consider enabling longer-lived lock/pid hygiene (e.g. clean pid files on graceful shutdown)"],"exampleFix":"# before\nastrid restart\n# after\nps -p 12345 -o pid,cmd        # confirm it is not astrid\nrm /var/run/astrid/daemon.pid\nastrid restart","handlingStrategy":"try-catch","validationCode":"pid=$(cat \"$PID_FILE\")\ncmd=$(ps -p \"$pid\" -o cmd= 2>/dev/null || true)\ncase \"$cmd\" in\n  *astrid*) echo \"leftover astrid daemon; kill it first\" ;;\n  *) rm -f \"$PID_FILE\"; echo \"stale pid file (PID reuse) removed\" ;;\nesac","typeGuard":null,"tryCatchPattern":"match outcome {\n    KillOutcome::Unverified(p) => {\n        eprintln!(\"inspect PID {p}; if not astrid, remove the pid file and retry\");\n        std::process::exit(1);\n    }\n    _ => { /* proceed */ }\n}","preventionTips":["Remove pid files on graceful shutdown","Verify PID identity (cmdline match) before deleting pid files","Never blind-kill PIDs recorded in stale files","Use lock files with process identity, not just PID, where possible"],"tags":["daemon","pid-reuse","fail-safe"],"backgroundTag":"stale-pid-file","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"}