{"record":{"id":"d1d627157799f719","repo":"xai-org/grok-build","slug":"cannot-rename-locked-executable-e-close-all","errorCode":null,"errorMessage":"cannot rename locked executable {}: {e}\nClose all running grok sessions and retry.","messagePattern":"cannot rename locked executable (.+?): (.+?)\nClose all running grok sessions and retry\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-update/src/auto_update.rs","lineNumber":2134,"sourceCode":"    let mut rename_result = tokio::fs::rename(dest, &aside).await;\n    // Pid reuse can collide a diverted name with a dead updater's\n    // still-locked leftover, and a racer can occupy a just-checked-free\n    // .old; a fresh unique sibling clears both tails (3 attempts total).\n    for _ in 0..2 {\n        match &rename_result {\n            Err(e) if matches!(e.raw_os_error(), Some(32) | Some(5)) => {\n                tracing::debug!(\n                    \"rename aside to {} failed; retrying with a fresh name: {e}\",\n                    aside.display()\n                );\n                aside = unique_temp_sibling(&old, \"old\");\n                rename_result = tokio::fs::rename(dest, &aside).await;\n            }\n            _ => break,\n        }\n    }\n    rename_result.map_err(|e| {\n        anyhow::anyhow!(\n            \"cannot rename locked executable {}: {e}\\n\\\n             Close all running grok sessions and retry.\",\n            dest.display(),\n        )\n    })?;\n    match tokio::fs::copy(src, dest).await {\n        Ok(_) => Ok(()),\n        Err(e) => {\n            // Rollback: restore the old binary so the install isn't broken.\n            let _ = tokio::fs::rename(&aside, dest).await;\n            Err(e.into())\n        }\n    }\n}\n\n/// Best-effort removal of `<exe>.old` plus the unique\n/// `<exe>.old.{pid}-{seq}.old` asides accumulated by prior update cycles.\n/// Locked ones (still-running images) survive and are collected by a later","sourceCodeStart":2116,"sourceCodeEnd":2152,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-update/src/auto_update.rs#L2116-L2152","documentation":"On Windows the running executable is locked, so replacing it requires renaming the old file aside first. This error is raised after exhausting retry attempts to rename the locked destination executable, telling the user another process still holds it open. It is a deliberate, user-actionable error rather than a raw OS error.","triggerScenarios":"tokio::fs::rename(dest, aside) failing repeatedly during a self-update because grok.exe (the destination) is locked by a running process; the loop retries/moves aside and finally gives up with this message.","commonSituations":"Multiple grok sessions (or an attached editor/terminal with the binary memory-mapped) running during update; antivirus scanning the binary holding a handle; a hung background grok process on Windows.","solutions":["Close all running grok sessions/processes and retry the update","Check Task Manager for lingering grok.exe processes and kill them, then retry","Temporarily disable antivirus real-time scanning of the install directory if it holds the file lock","Reboot to release all locks, then run the update"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match update.run().await {\n    Err(e) if e.to_string().contains(\"cannot rename locked executable\") => {\n        eprintln!(\"close all grok sessions and run the update again\");\n    }\n    result => result?,\n}","preventionTips":["Exit all grok processes before self-updating on Windows","Check Task Manager for lingering grok.exe processes before updating","Exclude the install directory from antivirus scanning to avoid transient locks","Retry the update after a reboot if locks persist"],"tags":["windows","filesystem","locked-file","update"],"backgroundTag":"file-in-use-locked","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}