{"record":{"id":"2e4c5b150cecfc2b","repo":"jdx/mise","slug":"another-daemon-profile-is-active-for-stop-its-daemons-and","errorCode":null,"errorMessage":"another daemon profile is active for {}; stop its daemons and leave its shell sessions before switching MISE_ENV","messagePattern":"another daemon profile is active for (.+?); stop its daemons and leave its shell sessions before switching MISE_ENV","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/daemons/runtime.rs","lineNumber":210,"sourceCode":"            }\n        }\n        Ok(false)\n    }\n\n    pub(crate) async fn prepare(\n        &self,\n        root: &Path,\n        set: &DaemonSet,\n        force_registration: bool,\n    ) -> Result<(State, fslock::LockFile)> {\n        let lock = crate::lock_file::LockFile::at(&state_dir(root).join(\"project.lock\")).lock()?;\n        let previous = read_state(root)?;\n        let profile = crate::env::MISE_ENV.clone();\n        if !previous.namespace.is_empty()\n            && previous.profile != profile\n            && self.active(root, &previous).await?\n        {\n            bail!(\n                \"another daemon profile is active for {}; stop its daemons and leave its shell sessions before switching MISE_ENV\",\n                root.display()\n            );\n        }\n        let namespace = if !previous.namespace.is_empty() {\n            previous.namespace.clone()\n        } else {\n            namespace(root)?\n        };\n        let mut state = State {\n            root: root.into(),\n            profile,\n            namespace,\n            ids: previous.ids,\n            bin: self.bin.clone(),\n            config_hash: String::new(),\n        };\n        for daemon in set.daemons.values() {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/daemons/runtime.rs#L192-L228","documentation":"mise records which MISE_ENV profile owns a project's daemon state. During daemon prepare, if saved state shows a different profile and at least one of that profile's daemons (or its pitchfork sessions) is still active, mise refuses to proceed to avoid two profiles fighting over the same daemon namespace. The user must stop the old profile's daemons and close its shell sessions before switching MISE_ENV.","triggerScenarios":"Calling prepare (via emit) where read_state(root) returns a previous state with a non-empty namespace, previous.profile != current MISE_ENV, and active(root, previous) finds a daemon in running/waiting/stopping state or a live pitchfork session for this root.","commonSituations":"Switching `MISE_ENV=staging` to `MISE_ENV=production` (or unsetting it) in a project that still has daemons started under the previous environment, with old shell sessions or a supervisor still holding them.","solutions":["Stop the daemons belonging to the old profile: switch MISE_ENV back and run `mise daemons stop` (or `pitchfork stop` for the project).","Close leftover shell sessions started under the previous MISE_ENV so pitchfork's liveness no longer reports them.","If the state is truly stale, remove the project's daemon state directory after confirming nothing is running, then retry.","Verify with `pitchfork supervisor status --json` and `pitchfork project list --json` that nothing for this root is live before switching."],"exampleFix":"// before\nMISE_ENV=production mise daemons start   # daemons still running under staging\n\n// after\nMISE_ENV=staging mise daemons stop       # stop old profile first\nMISE_ENV=production mise daemons start","handlingStrategy":"try-catch","validationCode":"# Before switching MISE_ENV, ensure no daemons from the old profile are live\nMISE_ENV=$OLD_ENV pitchfork project list --json | jq -e '.[] | select(.directory==\"'$PWD'\" and .liveness_status!=\"dead\")' \\\n  && echo \"stop old-profile daemons first\" || echo \"safe to switch\"","typeGuard":null,"tryCatchPattern":"try {\n  await mise.daemons.start();\n} catch (e) {\n  if (String(e).includes(\"another daemon profile is active\")) {\n    console.error(\"Stop the previous MISE_ENV profile's daemons and close its shells, then retry.\");\n  }\n}","preventionTips":["Always `mise daemons stop` under the old MISE_ENV before switching environments","Close shell sessions started under the previous profile so liveness checks pass","Check `pitchfork project list --json` for live entries for the project root before switching"],"tags":["daemon","profile-conflict","state"],"backgroundTag":"invalid-state-transition","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"}