{"record":{"id":"37be56bd958ff2c9","repo":"Hmbown/CodeWhale","slug":"refusing-to-replace-its-bytes-differ-from-the-running","errorCode":null,"errorMessage":"Refusing to replace {}: its bytes differ from the running executable. This may be another installation or an unrelated command. No command is removed automatically.\n\n{GITHUB_MIGRATION_HELP}","messagePattern":"Refusing to replace (.+?): its bytes differ from the running executable\\. This may be another installation or an unrelated command\\. No command is removed automatically\\.\n\n(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/update.rs","lineNumber":591,"sourceCode":"        Ok(metadata) => metadata,\n        Err(error) if error.kind() == std::io::ErrorKind::NotFound && target != identity.path => {\n            return Ok(());\n        }\n        Err(error) => {\n            return Err(error)\n                .with_context(|| format!(\"failed to inspect update target {}\", target.display()));\n        }\n    };\n    if !metadata.is_file() || metadata.is_symlink() {\n        bail!(\n            \"Refusing to replace {}: the update target is not a regular file.\\n\\n{GITHUB_MIGRATION_HELP}\",\n            target.display()\n        );\n    }\n    let bytes = std::fs::read(target)\n        .with_context(|| format!(\"failed to identify update target {}\", target.display()))?;\n    if sha256_hex(&bytes) != identity.file_hash {\n        bail!(\n            \"Refusing to replace {}: its bytes differ from the running executable. This may be another installation or an unrelated command. No command is removed automatically.\\n\\n{GITHUB_MIGRATION_HELP}\",\n            target.display()\n        );\n    }\n    Ok(())\n}\n\nfn protected_update_path(path: &Path) -> bool {\n    [\n        \"/usr/bin\",\n        \"/usr/sbin\",\n        \"/bin\",\n        \"/sbin\",\n        \"/nix/store\",\n        \"/gnu/store\",\n    ]\n    .iter()\n    .any(|prefix| path.starts_with(prefix))","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/update.rs#L573-L609","documentation":"Before replacing a file, the updater hashes it (sha256) and compares against the running executable's hash (identity.file_hash). If the bytes differ, the target is some other installation or an unrelated command that merely shares the name, so the updater refuses — no command is ever removed automatically.","triggerScenarios":"validate_update_target reads the target file and its sha256_hex does not equal identity.file_hash; raised for stale copies from older versions, different builds, or unrelated binaries placed next to the real one.","commonSituations":"Two independent installations of codewhale exist (one built from source, one downloaded); a different tool was named `codewhale` in the same bin dir; the binary was modified/patched after install.","solutions":["Identify which copy you actually use (`which -a codewhale`, compare hashes) and run update from the binary you want updated.","Remove the foreign/stale binary manually after confirming it is not yours; the updater will not delete it for you.","Reinstall from the official installer so only one managed copy exists, then update."],"exampleFix":"// before: stale v0.1 binary next to running v0.2 refuses replacement\n$ sha256sum ~/.local/bin/codewhale  # differs from running binary\n// after: delete the stale copy yourself, then update\n$ rm ~/.local/bin/codewhale-old && codewhale update","handlingStrategy":"validation","validationCode":"use sha2::{Digest, Sha256};\nfn matches_running_binary(path: &std::path::Path, expected: &str) -> bool {\n    std::fs::read(path).map(|b| Sha256::digest(&b) == *expected.as_bytes()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain exactly one codewhale installation; remove duplicates before updating","Don't rename unrelated binaries to `codewhale` in the same bin directory","Compare `sha256sum` of installed copies against the running binary when in doubt"],"tags":["self-update","checksum-mismatch","ownership","safety-guard"],"backgroundTag":"checksum-mismatch","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}