{"record":{"id":"53632fc30dd7ce88","repo":"jdx/mise","slug":"brew-cask-token-homebrew-took-ownership-of-this","errorCode":null,"errorMessage":"brew-cask:{token}: Homebrew took ownership of this cask while installation was pending","messagePattern":"brew-cask:(.+?): Homebrew took ownership of this cask while installation was pending","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/state.rs","lineNumber":108,"sourceCode":"        ),\n    }\n}\n\npub(super) fn ensure_homebrew_did_not_take_ownership(token: &str, stage: &Path) -> Result<()> {\n    let metadata_present = match homebrew_metadata_present(token) {\n        Ok(present) => present,\n        Err(err) => {\n            file::remove_all(stage).wrap_err_with(|| {\n                format!(\n                    \"failed to remove mise stage after Homebrew ownership check failed: {err:#}\"\n                )\n            })?;\n            return Err(err);\n        }\n    };\n    if metadata_present {\n        file::remove_all(stage)?;\n        bail!(\n            \"brew-cask:{token}: Homebrew took ownership of this cask while installation was pending\"\n        );\n    }\n    Ok(())\n}\n\npub(super) fn homebrew_metadata_present(token: &str) -> Result<bool> {\n    let path = caskroom_token_dir(token).join(\".metadata\");\n    match path.symlink_metadata() {\n        Ok(_) => Ok(true),\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(false),\n        Err(err) => Err(err).wrap_err_with(|| {\n            format!(\n                \"brew-cask:{token}: failed to inspect Homebrew metadata at '{}'\",\n                path.display()\n            )\n        }),\n    }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/cask/state.rs#L90-L126","documentation":"While mise was installing a cask into its own staging directory, Homebrew's .metadata marker appeared for that token, meaning Homebrew performed its own install/upgrade of the same cask concurrently. mise detects the ownership race, deletes its staging directory, and aborts rather than fighting Homebrew for ownership of the Caskroom.","triggerScenarios":"ensure_homebrew_did_not_take_ownership(token, stage) is called at the end of install_one_with_ancestors and finds homebrew_metadata_present(token) is true after staging. This is the race guarded by tests ownership_race_guard_removes_only_mise_stage and ownership_race_probe_error_removes_mise_stage.","commonSituations":"A background `brew bundle`/`brew upgrade` (or brew autoupdate service) installed or upgraded the same cask while a mise operation was in flight; another terminal or CI job ran brew concurrently.","solutions":["Re-run the mise command; if Homebrew completed the install, mise will adopt/see the Homebrew-managed state instead of failing.","Stop concurrent Homebrew activity (brew autoupdate, scheduled brew bundle/upgrade) before running mise package operations.","Verify the cask's state with `brew list --cask <token>` and retry once no other brew process is running."],"exampleFix":"// before: brew autoupdate racing mise\n$ brew autoupdate start --immediate\n$ mise pkg install cask:google-chrome   # ERROR: Homebrew took ownership\n\n// after: pause background brew during mise operations\n$ brew autoupdate stop\n$ mise pkg install cask:google-chrome   # ok","handlingStrategy":"retry","validationCode":"// before installing, ensure no concurrent brew process holds the token\nlet out = std::process::Command::new(\"pgrep\").args([\"-f\", \"brew .*(install|upgrade|bundle)\"]).output()?;\nif out.status.success() { /* defer operation */ }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"took ownership\") => {\n        // Homebrew won the race; adopt its state and retry\n        retry_with_backoff(3)\n    }\n    r => r,\n}","preventionTips":["Disable brew autoupdate or scheduled brew bundle during mise runs.","Serialize all package-manager operations in CI (mutex/lock).","Re-run mise after the error; Homebrew's completed install is usually usable."],"tags":["homebrew","cask","race-condition","concurrency"],"backgroundTag":"file-already-exists","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"}