{"record":{"id":"15213a2372b4449a","repo":"spacedriveapp/spacedrive","slug":"failed-to-load-launchagent","errorCode":null,"errorMessage":"Failed to load LaunchAgent: {}","messagePattern":"Failed to load LaunchAgent: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/daemon/mod.rs","lineNumber":134,"sourceCode":"\t\tstderr_log = stderr_log.display(),\n\t\tworking_dir = home.display(),\n\t);\n\n\t// Write the plist file\n\tlet mut file = fs::File::create(&plist_path)?;\n\tfile.write_all(plist_content.as_bytes())?;\n\n\tprintln!(\"Created LaunchAgent: {}\", plist_path.display());\n\n\t// Load the service\n\tlet output = std::process::Command::new(\"launchctl\")\n\t\t.arg(\"load\")\n\t\t.arg(&plist_path)\n\t\t.output()?;\n\n\tif !output.status.success() {\n\t\tlet stderr = String::from_utf8_lossy(&output.stderr);\n\t\treturn Err(anyhow::anyhow!(\"Failed to load LaunchAgent: {}\", stderr));\n\t}\n\n\tprintln!(\"Daemon installed successfully!\");\n\tprintln!(\"The daemon will start automatically on login.\");\n\tprintln!();\n\tprintln!(\"Logs:\");\n\tprintln!(\"  stdout: {}\", stdout_log.display());\n\tprintln!(\"  stderr: {}\", stderr_log.display());\n\n\tOk(())\n}\n\n#[cfg(target_os = \"macos\")]\nasync fn uninstall_launchd_service(instance: Option<String>) -> Result<()> {\n\tuse std::fs;\n\n\tlet home =\n\t\tdirs::home_dir().ok_or_else(|| anyhow::anyhow!(\"Could not determine home directory\"))?;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/daemon/mod.rs#L116-L152","documentation":"After writing the plist to ~/Library/LaunchAgents, the installer runs `launchctl load <plist>` and requires exit status 0. If launchctl exits non-zero, its stderr is wrapped in this error. The plist is already on disk, so the failure is in the service manager, not in file generation.","triggerScenarios":"Running `sd-cli daemon install` over SSH or another headless session where the per-user GUI domain (`gui/<uid>`) is unavailable (classic `Load failed: 5: Input/output error` or `Broken funeral`); a stale com.spacedrive.daemon job already registered in a broken state; a hand-edited plist that fails to parse.","commonSituations":"Remote administration over SSH without a logged-in desktop session; re-installing after a partial previous install; macOS versions where `launchctl load` is deprecated in favor of bootstrap/bootout.","solutions":["Read the stderr embedded in the message; it names the exact launchctl failure.","Run the install from a Terminal inside a normal GUI login session instead of SSH.","Clear a stale registration first: `launchctl bootout gui/$(id -u)/com.spacedrive.daemon 2>/dev/null; rm ~/Library/LaunchAgents/com.spacedrive.daemon.plist`, then reinstall.","If `load` keeps failing on newer macOS, load the written plist manually with the modern syntax: `launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.spacedrive.daemon.plist`.","Validate the generated plist with `plutil -lint ~/Library/LaunchAgents/com.spacedrive.daemon.plist`."],"exampleFix":"# before (over SSH, GUI domain missing)\nsd-cli daemon install  # -> Failed to load LaunchAgent: Load failed: 5: Input/output error\n\n# after (in a GUI login session, after clearing stale state)\nlaunchctl bootout gui/$(id -u)/com.spacedrive.daemon 2>/dev/null || true\nsd-cli daemon install  # -> Daemon installed successfully!","handlingStrategy":"try-catch","validationCode":"# shell preflight: a loadable GUI session exists only when this prints a target\nlaunchctl print gui/$(id -u)/com.spacedrive.daemon >/dev/null 2>&1 && echo registered || echo not-loaded","typeGuard":null,"tryCatchPattern":"match install_autostart().await {\n    Err(e) if e.to_string().contains(\"Failed to load LaunchAgent\") => {\n        // plist exists; finish manually with modern syntax and check lint\n        let _ = std::process::Command::new(\"launchctl\")\n            .args([\"bootstrap\", &format!(\"gui/{}\", uid), plist]).status();\n    }\n    other => other?,\n}","preventionTips":["Run daemon install from a GUI login Terminal session, not SSH.","Before reinstalling, bootout any previous com.spacedrive.daemon registration.","After any failure, lint the leftover plist with `plutil -lint` before retrying so you start from a known-good file."],"tags":["macos","launchd","launchctl","daemon","ssh"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}