{"record":{"id":"6c2d911fcc340057","repo":"jdx/mise","slug":"agent-name-cannot-set-both-keep-alive-and-k","errorCode":null,"errorMessage":"agent '{name}' cannot set both `keep_alive` and `keep_alive_on_failure`","messagePattern":"agent '(.+?)' cannot set both `keep_alive` and `keep_alive_on_failure`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/launchd.rs","lineNumber":121,"sourceCode":"    pub request: LaunchdRequest,\n    pub path: PathBuf,\n    pub loaded: bool,\n    pub state: LaunchdState,\n}\n\nimpl LaunchdRequest {\n    pub(crate) fn from_toml(name: String, config: LaunchdTomlConfig) -> Result<Self> {\n        if !valid_name(&name) {\n            bail!(\"agent name '{name}' must contain only letters, numbers, '.', '_', or '-'\");\n        }\n        let Some(program) = config.program.map(|s| s.trim().to_string()) else {\n            bail!(\"agent '{name}' must set `program`\");\n        };\n        if program.is_empty() {\n            bail!(\"agent '{name}' must set a non-empty `program`\");\n        }\n        if config.keep_alive && config.keep_alive_on_failure {\n            bail!(\"agent '{name}' cannot set both `keep_alive` and `keep_alive_on_failure`\");\n        }\n        if config.nice.is_some_and(|nice| !(-20..=20).contains(&nice)) {\n            bail!(\"agent '{name}' `nice` must be between -20 and 20\");\n        }\n        if let Some(interval) = &config.start_calendar_interval {\n            interval.validate(&name)?;\n        }\n        for dir in &config.queue_directories {\n            if dir.trim().is_empty() {\n                bail!(\"agent '{name}' `queue_directories` must not contain empty entries\");\n            }\n            // checked against the raw string rather than `Path::is_absolute` on the\n            // expanded value: the plist is consumed by macOS launchd, so POSIX rules\n            // apply regardless of the platform parsing the config, and on Windows\n            // `Path::new(\"/var/spool\").is_absolute()` is false (root, but no prefix)\n            if !is_absolute_launchd_path(dir) {\n                bail!(\n                    \"agent '{name}' `queue_directories` entry '{dir}' must be an absolute path \\","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/launchd.rs#L103-L139","documentation":"launchd offers two mutually exclusive keep-alive semantics: keep_alive (always keep running) and keep_alive_on_failure (restart only on failure). LaunchdRequest::from_toml bails if both are set to true on the same agent, because the resulting plist KeepAlive value would be ambiguous. Only one strategy can be chosen per agent.","triggerScenarios":"An agent config with both keep_alive = true and keep_alive_on_failure = true, typically from merging two agent templates or incremental edits.","commonSituations":"Combining shared config snippets each setting a different keep-alive flag; trying to express 'restart always AND on failure' without realizing they overlap; copy-paste between agents that used different flags.","solutions":["Keep only one of keep_alive or keep_alive_on_failure set to true","Use keep_alive = true for unconditional restarts","Use keep_alive_on_failure = true to restart only on non-zero exits"],"exampleFix":"# before\n[agent.worker]\nprogram = \"/usr/bin/worker\"\nkeep_alive = true\nkeep_alive_on_failure = true\n# after\n[agent.worker]\nprogram = \"/usr/bin/worker\"\nkeep_alive_on_failure = true","handlingStrategy":"validation","validationCode":"if agent_cfg.get(\"keep_alive\") and agent_cfg.get(\"keep_alive_on_failure\"):\n    raise ValueError(f\"agent '{name}': pick one keep_alive strategy\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document one canonical keep-alive flag per use case","Check for both flags when merging agent config snippets","Validate agent configs in CI"],"tags":["launchd","config","conflicting-options"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}