nikivdev/code · error · anyhow::Error
failed to stop daemon {}
Error message
failed to stop daemon {} What it means
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.
Source
Thrown at src/supervisor.rs:142
if let Some(message) = response.message {
println!("OK {}", message);
}
}
Ok(())
}
pub fn stop_daemon_managed(name: &str, config_path: Option<&Path>, announce: bool) -> Result<()> {
let socket_path = resolve_socket_path(None)?;
ensure_supervisor_running(&socket_path, announce, false)?;
let request = IpcRequest {
action: SupervisorIpcAction::StopDaemon {
name: name.to_string(),
config_path: config_path.map(|p| p.display().to_string()),
},
};
let response = send_request(&socket_path, &request)?;
if !response.ok {
bail!(
"{}",
response
.message
.unwrap_or_else(|| format!("failed to stop daemon {}", name))
);
}
if announce {
if let Some(message) = response.message {
println!("OK {}", message);
}
}
Ok(())
}
pub fn is_running() -> bool {
resolve_socket_path(None)
.map(|path| supervisor_running(&path))
.unwrap_or(false)View on GitHub (pinned to a747e741ae)
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.
Example fix
// before myapp supervisor stop mydaemon // failed to stop daemon mydaemon // after myapp supervisor status # find real state / pid kill <pid> # if hung myapp supervisor stop mydaemon
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm the daemon is registered before stopping
const status = await supervisor.status();
if (!status.daemons.some(d => d.name === 'mydaemon' && d.running)) {
console.log('Daemon not running; nothing to stop.');
return;
} Type guard
type DaemonStopResponse = { ok: true } | { ok: false; message?: string };
function stopFailed(r: DaemonStopResponse): r is Extract<DaemonStopResponse, { ok: false }> {
return r.ok === false;
} Try / catch
try {
await supervisor.stopDaemon('mydaemon');
} catch (e) {
if (String(e).includes('failed to stop daemon')) {
console.error('Could not stop daemon cleanly; check supervisor status and kill the pid manually if hung.');
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to start daemon {}
- failed to read from codex: {}
- codex app-server response timed out
- failed to read from codex app-server: {}
- codex app-server closed stdout unexpectedly
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/829f0f38bf9da734.
Report an issue: GitHub.