{"record":{"id":"829f0f38bf9da734","repo":"nikivdev/code","slug":"failed-to-stop-daemon","errorCode":null,"errorMessage":"failed to stop daemon {}","messagePattern":"failed to stop daemon (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/supervisor.rs","lineNumber":142,"sourceCode":"        if let Some(message) = response.message {\n            println!(\"OK {}\", message);\n        }\n    }\n    Ok(())\n}\n\npub fn stop_daemon_managed(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {\n    let socket_path = resolve_socket_path(None)?;\n    ensure_supervisor_running(&socket_path, announce, false)?;\n    let request = IpcRequest {\n        action: SupervisorIpcAction::StopDaemon {\n            name: name.to_string(),\n            config_path: config_path.map(|p| p.display().to_string()),\n        },\n    };\n    let response = send_request(&socket_path, &request)?;\n    if !response.ok {\n        bail!(\n            \"{}\",\n            response\n                .message\n                .unwrap_or_else(|| format!(\"failed to stop daemon {}\", name))\n        );\n    }\n    if announce {\n        if let Some(message) = response.message {\n            println!(\"OK {}\", message);\n        }\n    }\n    Ok(())\n}\n\npub fn is_running() -> bool {\n    resolve_socket_path(None)\n        .map(|path| supervisor_running(&path))\n        .unwrap_or(false)","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/supervisor.rs#L124-L160","documentation":"stop_daemon_managed sends a stop request for a named daemon to the supervisor over its Unix socket. If the supervisor responds with ok == false (and no overriding message), it bails with \"failed to stop daemon <name>\". The supervisor could not cleanly stop the daemon.","triggerScenarios":"Calling stop_daemon_managed when the IPC response reports failure with no message — daemon not actually running under the supervisor, daemon ignored/hung on shutdown signal, or name not registered with the supervisor.","commonSituations":"Daemon already exited but supervisor still tracks it (stale state); daemon process stuck and not responding to SIGTERM; typo'd daemon name; supervisor was restarted and lost track of the daemon.","solutions":["Check supervisor status for the daemon to confirm it's registered and running before stopping.","Force-kill a hung daemon process manually (kill <pid>), then reconcile supervisor state.","Restart the supervisor to clear stale tracking entries, then retry the stop.","Verify the daemon name spelling matches the configured name."],"exampleFix":"// before\nmyapp supervisor stop mydaemon\n// failed to stop daemon mydaemon\n// after\nmyapp supervisor status           # find real state / pid\nkill <pid>                        # if hung\nmyapp supervisor stop mydaemon","handlingStrategy":"try-catch","validationCode":"// confirm the daemon is registered before stopping\nconst status = await supervisor.status();\nif (!status.daemons.some(d => d.name === 'mydaemon' && d.running)) {\n  console.log('Daemon not running; nothing to stop.');\n  return;\n}","typeGuard":"type DaemonStopResponse = { ok: true } | { ok: false; message?: string };\nfunction stopFailed(r: DaemonStopResponse): r is Extract<DaemonStopResponse, { ok: false }> {\n  return r.ok === false;\n}","tryCatchPattern":"try {\n  await supervisor.stopDaemon('mydaemon');\n} catch (e) {\n  if (String(e).includes('failed to stop daemon')) {\n    console.error('Could not stop daemon cleanly; check supervisor status and kill the pid manually if hung.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Check supervisor status before issuing stop to avoid stopping stale entries.","Give daemons a short, honored shutdown handler so SIGTERM always works.","Restart the supervisor periodically after upgrades to drop stale tracking state.","Keep daemon names consistent between start and stop invocations."],"tags":["daemon","supervisor","ipc","process","shutdown"],"backgroundTag":"daemon-stop-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}