{"record":{"id":"8bf2c149108795ea","repo":"BigPizzaV3/CodexPlusPlus","slug":"failed-to-restore-rollout-file-s","errorCode":null,"errorMessage":"failed to restore {} rollout file(s): {}","messagePattern":"failed to restore (.+?) rollout file\\(s\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/codex-plus-data/src/provider_sync.rs","lineNumber":3657,"sourceCode":"            writer.write_all(line_ending.as_bytes())?;\n            rewritten = true;\n        }\n        if !rewritten {\n            writer.write_all(line.as_bytes())?;\n        }\n    }\n    Ok(format!(\"{:x}\", hasher.finalize()))\n}\n\nfn restore_bulk_session_rewrites(changes: &[AppliedBulkSessionRewrite]) -> anyhow::Result<()> {\n    let mut restore_errors = Vec::new();\n    for change in changes.iter().rev() {\n        if let Err(error) = restore_bulk_session_rewrite(change) {\n            restore_errors.push(format!(\"{}: {error:#}\", change.plan.path.display()));\n        }\n    }\n    if !restore_errors.is_empty() {\n        return Err(anyhow::anyhow!(\n            \"failed to restore {} rollout file(s): {}\",\n            restore_errors.len(),\n            restore_errors.join(\"; \")\n        ));\n    }\n    Ok(())\n}\n\nfn restore_bulk_session_rewrite(change: &AppliedBulkSessionRewrite) -> anyhow::Result<()> {\n    if sha256_file(&change.plan.path)? != change.rewritten_sha256 {\n        return Err(anyhow::anyhow!(\n            \"rollout changed before rollback: {}\",\n            change.plan.path.display()\n        ));\n    }\n\n    codex_plus_core::settings::atomic_write_with(&change.plan.path, |file| {\n        let mut writer = HashingWriter::new(BufWriter::new(file));","sourceCodeStart":3639,"sourceCodeEnd":3675,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/provider_sync.rs#L3639-L3675","documentation":"restore_bulk_session_rewrites iterates applied changes in reverse and calls restore_bulk_session_rewrite for each rollout file. Any per-file failure is collected with the file path; if any failures occurred, this aggregate error is raised listing how many files failed to restore and each `path: error`.","triggerScenarios":"Calling the bulk-session-rewrite rollback path (directly or via the apply-failure handler) when one or more restore_bulk_session_rewrite calls return Err — e.g. hash checks fail or atomic_write_with cannot write the pre-image back.","commonSituations":"Rollout files modified between rewrite and rollback (hash mismatch); files locked by another process; disk or permission failures during the restore write; multiple files failing at once after a shared root cause.","solutions":["Inspect each `path: error` entry; resolve per-file causes (unlock, fix permissions) then retry the restore","For files reported as changed before rollback, restore them from an external backup — the library refuses to overwrite files it did not rewrite","Re-run the full provider sync to regenerate the affected rollout files from source data","Check disk space and AV/indexer interference if many files failed at once"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check each planned path for writability\nlet bad: Vec<_> = plans.iter().filter(|p| metadata_writeable_failed(&p.path)).collect();\nif !bad.is_empty() { return Err(format!(\"{} unwritable targets\", bad.len())); }","typeGuard":null,"tryCatchPattern":"match restore_result {\n    Err(e) => {\n        let msg = e.to_string();\n        // msg enumerates \"path: error\" entries; parse and remediate per file\n    }\n    Ok(_) => {}\n}","preventionTips":["Quiesce all writers of the rollout files before applying or rolling back","Run under an account with write access to the rollout directories","Monitor disk space; batch large rewrites into smaller groups"],"tags":["rust","rollback","file-io"],"backgroundTag":"file-write-failed","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}