{"record":{"id":"8fbaa5ea916c90f3","repo":"xai-org/grok-build","slug":"compaction-checkpoint-file-corrupt-checkpoint-pa","errorCode":null,"errorMessage":"Compaction checkpoint file corrupt: {checkpoint_path}. Cannot safely rewind past the compaction point.","messagePattern":"Compaction checkpoint file corrupt: (.+?)\\. Cannot safely rewind past the compaction point\\.","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/session/helpers/replay.rs","lineNumber":325,"sourceCode":"                            checkpoint_path.display()\n                        ),\n                    ));\n                }\n                Err(e) => return Err(e),\n            };\n            match serde_json::from_slice::<CompactionCheckpointFile>(&bytes) {\n                Ok(file) => {\n                    if self.original_user_info.is_none() {\n                        self.original_user_info = file.original_user_info;\n                    }\n                }\n                Err(e) => {\n                    tracing::error!(\n                        ?e,\n                        path = %checkpoint_path.display(),\n                        \"Compaction checkpoint file corrupt, cannot restore original user_info\"\n                    );\n                    return Err(io::Error::new(\n                        io::ErrorKind::InvalidData,\n                        format!(\n                            \"Compaction checkpoint file corrupt: {}. \\\n                             Cannot safely rewind past the compaction point.\",\n                            checkpoint_path.display()\n                        ),\n                    ));\n                }\n            }\n            tracing::debug!(\n                target = self.target,\n                checkpoint_at = info.prompt_index_at_compaction,\n                \"Replay: using raw updates (target is pre-compaction), original_user_info extracted\"\n            );\n            Ok(ReplayAction::Continue)\n        } else {\n            let checkpoint_path = session_dir.join(&info.checkpoint_file);\n            let bytes = match std::fs::read(&checkpoint_path) {","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/session/helpers/replay.rs#L307-L343","documentation":"During pre-compaction rewind replay, the checkpoint file exists but serde_json cannot deserialize it into CompactionCheckpointFile (needed to restore the original user_info). The library throws io::ErrorKind::InvalidData because replaying with wrong/missing user_info data would corrupt the conversation. Replay aborts at the compaction point.","triggerScenarios":"process_update/handle_checkpoint hits SessionUpdate::Xai(CompactionCheckpoint) with target < prompt_index_at_compaction and std::fs::read succeeds but serde_json::from_slice::<CompactionCheckpointFile> fails on the bytes.","commonSituations":"File truncated by crash mid-write or full disk; file edited by hand or by external sync tool (merge conflicts, partial sync); schema drift after upgrading or downgrading between versions with different checkpoint JSON shapes; non-UTF8/garbage bytes on disk.","solutions":["Restore the checkpoint file from backup or re-sync the session directory","Delete the corrupt checkpoint and rewind only to targets at/after the compaction point","Regenerate the session by replaying the raw jsonl log without the compaction shortcut, or start a new session","Upgrade/downgrade the CLI to the version that wrote the checkpoint so the schema matches"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let bytes = std::fs::read(&ckpt_path)?;\nif let Err(e) = serde_json::from_slice::<serde_json::Value>(&bytes) {\n    eprintln!(\"checkpoint not valid JSON ({}): {}\", e, ckpt_path.display());\n}","typeGuard":"fn checkpoint_parses(bytes: &[u8]) -> Option<serde_json::Value> {\n    serde_json::from_slice(bytes).ok()\n}","tryCatchPattern":"match serde_json::from_slice::<CompactionCheckpointFile>(&bytes) {\n    Ok(f) => proceed(f),\n    Err(e) => {\n        tracing::error!(?e, \"checkpoint corrupt; falling back to raw-update replay\");\n        fallback_to_pre_compaction_rewind();\n    }\n}","preventionTips":["Don't edit checkpoint files by hand","Use file-level (not line-level) sync for session dirs to avoid merge corruption","Ensure clean shutdowns — crashes mid-write can truncate JSON","Verify sessions after copying between machines"],"tags":["io","json","serialization","compaction","corrupt-data"],"backgroundTag":"corrupt-json-file","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}