{"record":{"id":"03d40c8e8582cf4d","repo":"astrid-runtime/astrid","slug":"failed-to-connect-to-daemon-check-logs","errorCode":null,"errorMessage":"Failed to connect to daemon. Check logs: {}","messagePattern":"Failed to connect to daemon\\. Check logs: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/astrid-cli/src/bootstrap.rs","lineNumber":255,"sourceCode":"            drop(daemon_child);\n            c\n        },\n        Err(e) => {\n            if let Some(child) = daemon_child {\n                // A live first cutover must not be SIGKILL'd because connect\n                // raced the ready sentinel.\n                commands::daemon::disown_if_still_running(child);\n            }\n            let log_hint = astrid_core::dirs::AstridHome::resolve().map_or_else(\n                |_| \"Failed to connect to daemon\".to_string(),\n                |h| {\n                    format!(\n                        \"Failed to connect to daemon. Check logs: {}\",\n                        h.log_dir().display()\n                    )\n                },\n            );\n            return Err(anyhow::Error::new(e).context(log_hint));\n        },\n    };\n\n    crate::commands::chat::run_chat(&mut client, &session_id, INITIAL_TUI_MODEL_LABEL, format).await\n}\n\n#[cfg(test)]\nmod tests {\n    use super::{INITIAL_TUI_MODEL_LABEL, selected_workspace_root};\n\n    #[test]\n    fn interactive_tui_starts_without_a_host_model_label() {\n        assert_eq!(INITIAL_TUI_MODEL_LABEL, \"\");\n    }\n\n    #[test]\n    fn explicit_workspace_root_wins_over_current_directory() {\n        let explicit = tempfile::tempdir().expect(\"explicit workspace\");","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-cli/src/bootstrap.rs#L237-L273","documentation":"This error wraps any failure to establish a connection to the Astrid daemon during CLI bootstrap. The original error (e.g. connection refused, daemon not running, socket stale) is preserved via anyhow context, and a log directory hint is appended so the developer can inspect daemon logs. The library throws it because the CLI cannot proceed to the chat/REPL session without a live daemon connection.","triggerScenarios":"Calling run_or_connect when the daemon is not running, crashed, or listening on a stale/incorrect socket or port; daemon logs are surfaced via h.log_dir().","commonSituations":"Starting the CLI before launching the daemon; daemon died after a previous run leaving a stale socket; wrong daemon address in config; insufficient permissions to open the socket; daemon startup failures visible only in its log files.","solutions":["Check the daemon logs at the directory printed in the error (h.log_dir()) for the root cause","Start the daemon manually, then retry the CLI","Remove any stale socket/pid files left by a crashed daemon and restart","Verify the daemon address/port configuration matches what the daemon is bound to","Check file permissions on the daemon socket directory"],"exampleFix":"// before: CLI fails with 'Failed to connect to daemon'\nastrid chat\n// after: ensure daemon is up first\nastrid daemon start && astrid chat","handlingStrategy":"try-catch","validationCode":"// Before launching the chat session, check if the daemon socket is reachable\nfn daemon_reachable(socket_path: &std::path::Path) -> bool {\n    socket_path.exists() // and/or attempt a lightweight connect/ping\n}","typeGuard":null,"tryCatchPattern":"match run_or_connect().await {\n    Ok(session) => session,\n    Err(e) if e.to_string().contains(\"Failed to connect to daemon\") => {\n        eprintln!(\"{}\\nCheck daemon logs, then start the daemon and retry.\", e);\n        std::process::exit(1);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Start the daemon as part of your launch script or use a supervisor (systemd) with auto-restart","Clean stale socket/pid files after abnormal daemon termination","Monitor daemon logs for crash loops","Keep daemon address/port config in one shared place so client and server agree"],"tags":["network","daemon","connection","cli"],"backgroundTag":"connection-refused","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}