xai-org/grok-build · error · io::Error

Compaction checkpoint file corrupt: {checkpoint_path}. Canno

Error message

Compaction checkpoint file corrupt: {checkpoint_path}. Cannot safely rewind past the compaction point.

What it means

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.

Source

Thrown at crates/codegen/xai-grok-shell/src/session/helpers/replay.rs:325

                            checkpoint_path.display()
                        ),
                    ));
                }
                Err(e) => return Err(e),
            };
            match serde_json::from_slice::<CompactionCheckpointFile>(&bytes) {
                Ok(file) => {
                    if self.original_user_info.is_none() {
                        self.original_user_info = file.original_user_info;
                    }
                }
                Err(e) => {
                    tracing::error!(
                        ?e,
                        path = %checkpoint_path.display(),
                        "Compaction checkpoint file corrupt, cannot restore original user_info"
                    );
                    return Err(io::Error::new(
                        io::ErrorKind::InvalidData,
                        format!(
                            "Compaction checkpoint file corrupt: {}. \
                             Cannot safely rewind past the compaction point.",
                            checkpoint_path.display()
                        ),
                    ));
                }
            }
            tracing::debug!(
                target = self.target,
                checkpoint_at = info.prompt_index_at_compaction,
                "Replay: using raw updates (target is pre-compaction), original_user_info extracted"
            );
            Ok(ReplayAction::Continue)
        } else {
            let checkpoint_path = session_dir.join(&info.checkpoint_file);
            let bytes = match std::fs::read(&checkpoint_path) {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Restore the checkpoint file from backup or re-sync the session directory
  2. Delete the corrupt checkpoint and rewind only to targets at/after the compaction point
  3. Regenerate the session by replaying the raw jsonl log without the compaction shortcut, or start a new session
  4. Upgrade/downgrade the CLI to the version that wrote the checkpoint so the schema matches
Defensive patterns

Strategy: try-catch

Validate before calling

let bytes = std::fs::read(&ckpt_path)?;
if let Err(e) = serde_json::from_slice::<serde_json::Value>(&bytes) {
    eprintln!("checkpoint not valid JSON ({}): {}", e, ckpt_path.display());
}

Type guard

fn checkpoint_parses(bytes: &[u8]) -> Option<serde_json::Value> {
    serde_json::from_slice(bytes).ok()
}

Try / catch

match serde_json::from_slice::<CompactionCheckpointFile>(&bytes) {
    Ok(f) => proceed(f),
    Err(e) => {
        tracing::error!(?e, "checkpoint corrupt; falling back to raw-update replay");
        fallback_to_pre_compaction_rewind();
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/8fbaa5ea916c90f3. Report an issue: GitHub.