{"record":{"id":"df5f2b732afb041a","repo":"Hmbown/CodeWhale","slug":"plugin-source-changed-after-review-expected-conte","errorCode":null,"errorMessage":"plugin source changed after review: expected content hash {expected}, copied bytes hash is {actual}; nothing was installed","messagePattern":"plugin source changed after review: expected content hash (.+?), copied bytes hash is (.+?); nothing was installed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/plugins/install/mod.rs","lineNumber":378,"sourceCode":"                expected_content_hash,\n            )\n        }\n    }\n}\n\nfn verify_expected_content_hash(\n    staged: &stage::StagedPlugin,\n    expected_content_hash: Option<&str>,\n) -> Result<()> {\n    let Some(expected) = expected_content_hash else {\n        return Ok(());\n    };\n    if staged.content_hash == expected {\n        return Ok(());\n    }\n    let actual = staged.content_hash.clone();\n    let _ = fs::remove_dir_all(&staged.staged_path);\n    bail!(\n        \"plugin source changed after review: expected content hash {expected}, copied bytes hash is {actual}; nothing was installed\"\n    )\n}\n\n/// Stage and finalize an already-downloaded remote tarball. Kept separate\n/// from [`install`] so [`update`] can compare the checksum of the bytes it\n/// already fetched instead of downloading twice.\n#[allow(clippy::too_many_arguments)]\nfn install_remote_bytes(\n    remote: &InstallSource,\n    bytes: &[u8],\n    url: &str,\n    user_plugins_dir: &Path,\n    max_size: u64,\n    update: bool,\n    name_conflict: &(dyn Fn(&str) -> Option<String> + Send + Sync),\n    expected_content_hash: Option<&str>,\n) -> Result<PluginInstallOutcome> {","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/plugins/install/mod.rs#L360-L396","documentation":"After the user reviews a plugin source, the library re-stages the bytes and compares the staged content hash to the expected hash recorded at review time. If they differ, something changed between review and install, so it deletes the staged copy and refuses to install anything. This is a TOCTOU/supply-chain guard.","triggerScenarios":"Calling `install_inner` / `install_remote_bytes` after user approval when the source file (or remote tarball) was modified, re-downloaded with different bytes, or the staging copy got corrupted between hashing and install.","commonSituations":"The plugin file was saved again by an editor between `--review` and confirmation; a remote tarball was republished upstream with the same URL; a checksum-pinned update found different bytes at the pinned URL.","solutions":["Re-run the install flow so the user reviews the current content and a fresh expected hash is recorded","Verify the source has not changed (check file mtime or upstream checksum) and retry","If a remote republished the tarball, pin to a specific version/URL whose bytes match what you reviewed"],"exampleFix":"// before: review hash taken, then file edited before confirming\n$ codewhale plugin install ./dist --review  # hash abc123\n$ (edit dist/plugin.toml)\n$ codewhale plugin install ./dist            # mismatch -> bail\n// after: re-review so expected == actual\n$ codewhale plugin install ./dist --review\n$ codewhale plugin install ./dist","handlingStrategy":"validation","validationCode":"// after review, before confirming install:\nlet current = sha256(fs::read(source_path)?);\nif current != expected_hash { eprintln!(\"source changed; re-review\"); return; }","typeGuard":null,"tryCatchPattern":"match install_inner(...) {\n    Err(e) if e.to_string().contains(\"changed after review\") => {\n        eprintln!(\"source moved under you; re-run install with --review\");\n    }\n    other => other?,\n}","preventionTips":["Do not edit source files between review and confirmation","Re-review whenever the source file's mtime changes","Pin remote installs to immutable versioned URLs"],"tags":["plugins","integrity","hash"],"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"}