{"record":{"id":"07164ba15d02fa32","repo":"jdx/mise","slug":"package-plugin-ownership-state-belongs-to-manag","errorCode":null,"errorMessage":"package plugin ownership state {} belongs to manager '{}', not '{manager}'","messagePattern":"package plugin ownership state (.+?) belongs to manager '(.+?)', not '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/plugin.rs","lineNumber":153,"sourceCode":"                packages: BTreeMap::new(),\n            });\n        }\n        let state: PackagePluginState = serde_json::from_str(&crate::file::read_to_string(path)?)\n            .wrap_err_with(|| {\n            format!(\n                \"failed to read package plugin ownership state {}\",\n                crate::file::display_path(path)\n            )\n        })?;\n        if state.schema_version != STATE_SCHEMA_VERSION {\n            bail!(\n                \"unsupported package plugin ownership state version {} in {}\",\n                state.schema_version,\n                crate::file::display_path(path)\n            );\n        }\n        if state.manager != manager {\n            bail!(\n                \"package plugin ownership state {} belongs to manager '{}', not '{manager}'\",\n                crate::file::display_path(path),\n                state.manager\n            );\n        }\n        Ok(state)\n    }\n\n    fn load_state(&self) -> Result<PackagePluginState> {\n        Self::load_state_at(&self.state_path(), &self.name)\n    }\n\n    fn save_state_at(path: &std::path::Path, state: &PackagePluginState) -> Result<()> {\n        crate::file::create_dir_all(path.parent().expect(\"package plugin state parent\"))?;\n        let mut contents = serde_json::to_vec_pretty(state)?;\n        contents.push(b'\\n');\n        crate::file::write_atomic(path, contents)\n    }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/plugin.rs#L135-L171","documentation":"The package-plugin ownership state file records which package manager (plugin) wrote it. When `load_state_at` reads a state file whose `manager` field differs from the manager performing the current operation, mise bails out instead of letting one plugin mutate or misattribute another plugin's installed packages. This prevents two package plugins from claiming or uninstalling each other's packages.","triggerScenarios":"Invoking an operation (install, uninstall, prune, status) on plugin B while the ownership state file at that path was last written by plugin A; e.g. after renaming a plugin or switching a package set to a different manager that resolves to the same state path.","commonSituations":"Renaming or replacing a package plugin in config while old state remains on disk; migrating packages from one plugin to another without clearing state; two plugins configured with colliding state directories; copying mise state between projects using different managers.","solutions":["Remove or archive the ownership state file shown in the message so the correct manager can write fresh state (reinstall its packages afterwards if needed).","Uninstall the packages through the manager named in the message ('belongs to manager X') before switching to the new manager.","Fix plugin configuration so each manager uses a distinct state path (avoid renames that orphan state).","Verify you are invoking mise with the same plugin/config that created the state, not a renamed or duplicate plugin definition."],"exampleFix":"// before: state written by manager 'npm' but operation targets 'pnpm'\nrm <state-file-from-message>\npmise install   # current manager now owns and rewrites the state","handlingStrategy":"validation","validationCode":"// Verify the state file's manager matches the manager you will operate with\nimport { readFileSync } from 'node:fs';\nconst state = JSON.parse(readFileSync(statePath, 'utf8'));\nif (state.manager !== expectedManager) {\n  console.warn(`State ${statePath} belongs to '${state.manager}', not '${expectedManager}' — migrate or delete it first`);\n}","typeGuard":"const isOwnedBy = (state, manager) => state?.manager === manager;","tryCatchPattern":"try { await misePluginUninstall(plugin, pkgs) } catch (e) { if (String(e).includes(\"belongs to manager\")) { const owner = e.message.match(/manager '(.*?)'/)?.[1]; console.error(`Uninstall via '${owner}' first, or remove the state file`); } else throw e; }","preventionTips":["Do not rename or swap package plugins while ownership state exists; uninstall via the old manager first.","Give each package manager/plugin a distinct state path to avoid collisions.","When migrating packages between managers, clear the old state file as part of the migration.","Keep plugin definitions stable in committed mise.toml files."],"tags":["state-file","ownership-conflict","package-plugin","state-mismatch"],"backgroundTag":"state-manager-mismatch","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"}