{"record":{"id":"4d7fe916d816352d","repo":"Hmbown/CodeWhale","slug":"android-loaded-image-proof-changed-from-to","errorCode":null,"errorMessage":"Android loaded-image proof changed from {:?} to {:?}; refusing to replace the update target","messagePattern":"Android loaded-image proof changed from (.+?) to (.+?); refusing to replace the update target","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/update.rs","lineNumber":547,"sourceCode":"    }\n    Ok(())\n}\n\n#[cfg(any(target_os = \"android\", all(test, unix)))]\nfn android_device_parts(device: u64) -> (u32, u32) {\n    // Linux/Bionic's dev_t encoding, matching makedev(3), major(3), and\n    // minor(3). `/proc/self/maps` renders these components in hexadecimal.\n    let major = ((device >> 8) & 0xfff) as u32;\n    let minor = ((device & 0xff) | ((device >> 12) & 0xfff00)) as u32;\n    (major, minor)\n}\n\nfn validate_primary_update_identity(identity: &UpdateExecutableIdentity) -> Result<()> {\n    #[cfg(target_os = \"android\")]\n    {\n        let fresh = android_loaded_executable_proof()?;\n        if fresh != identity.android_proof {\n            bail!(\n                \"Android loaded-image proof changed from {:?} to {:?}; refusing to replace the update target\",\n                identity.android_proof,\n                fresh\n            );\n        }\n    }\n    let bytes = std::fs::read(&identity.path).context(\"failed to recheck updater binary\")?;\n    if sha256_hex(&bytes) != identity.file_hash {\n        bail!(\n            \"The running executable path changed during the update; no further files were replaced. Run the intended executable again by its full path.\"\n        );\n    }\n    Ok(())\n}\n\n/// Only the running binary and copies of those exact bytes are ours to update.\n/// Command names alone do not establish ownership of an existing sibling.\nfn validate_update_target(target: &Path, identity: &UpdateExecutableIdentity) -> Result<()> {","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/update.rs#L529-L565","documentation":"Immediately before replacing any files, the Android updater re-derives the loaded-image proof (path, device, inode, proof kind) and compares it to the proof captured when the update identity was created. If anything about the running executable changed mid-update, replacing files could act on the wrong binary, so the updater aborts before touching the target.","triggerScenarios":"validate_primary_update_identity (called from run_update just before the swap) when android_loaded_executable_proof() returns a proof different from identity.android_proof.","commonSituations":"The binary file was replaced, deleted, or moved between update start and the swap step (racing installer, prior update finishing, user action); the process restarted under a different path; another self-update ran concurrently.","solutions":["Ensure no other process or updater instance is touching the binary during the update; rerun the update alone.","Restart the newly installed binary by its full path and run the update again from that fresh process.","Check for concurrent automation (CI, sync, package managers) operating on the install directory and serialize updates.","If it recurs, capture both the original and fresh proof (shown in the error) and file a bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before starting the update, snapshot identity and check the environment is quiet:\nlet identity = capture_update_identity()?;\n// ensure no concurrent writers, then call run_update; on failure, restart fresh","typeGuard":null,"tryCatchPattern":"match run_update() {\n    Err(e) if e.to_string().contains(\"loaded-image proof changed\") => {\n        // abort the swap safely; instruct: restart intended binary by full path, retry\n    }\n    other => other?,\n}","preventionTips":["Run only one update process at a time.","Do not modify the install directory during an update.","Restart from a freshly started process after any prior failed/aborted update.","Log the before/after proof values shown in the error when reporting bugs."],"tags":["android","self-update","identity","race-condition"],"backgroundTag":"invalid-state-transition","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"}