BigPizzaV3/CodexPlusPlus · error

restore conflict: file already exists

Error message

restore conflict: file already exists: {path}

What it means

While pre-checking a backup restore, detect_file_restore_conflicts checks whether each file listed in the __files array already exists on disk. Restore must not clobber existing rollout files, so if Path::new(path).exists() is true the operation bails out with this conflict error before any rows or files are written.

Solutions

  1. Delete or move the existing files listed in the error message, then re-run the restore.
  2. Skip the restore if the sessions already exist locally — the data is likely already present.
  3. Restore into a different codex home directory (pass a different home) where the paths don't exist.
  4. If a previous restore failed midway, clean up the partially restored files first.

Example fix

// before
restore_backups(&backup)?; // fails: rollout-2026.jsonl already on disk
// after
for f in &files { let p = Path::new(f); if p.exists() { fs::rename(p, p.with_extension("bak"))?; } }
restore_backups(&backup)?;
Defensive patterns

Strategy: validation

Validate before calling

for (const f of backup.__files ?? []) {
  if (fs.existsSync(f.path)) throw new Error(`restore would clobber existing file: ${f.path}`);
}

Try / catch

match restore_backups(&backup) {
    Err(e) if e.to_string().contains("file already exists") => { /* move existing files aside or skip */ }
    other => other?,
}

Prevention

When it happens

Trigger: Calling restore_backups when a rollout file recorded in the backup's __files array (a threads.rollout_path) already exists at that path on the target machine — typically a second restore of the same backup, or restoring onto a machine that already ran those sessions.

Common situations: Running the same restore twice; restoring onto the original machine after only deleting the DB (not the session files); switching machines where sessions were synced separately; failed partial restore left files behind.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/0715b324e3c537f2. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-data/src/storage.rs:1189

            .map(|(key, _)| vec![key])
            .unwrap_or_default()
    } else {
        keys
    }
}

fn detect_file_restore_conflicts(tables: &Map<String, Value>) -> anyhow::Result<()> {
    let Some(files) = tables.get("__files").and_then(Value::as_array) else {
        return Ok(());
    };
    let allowed_paths = allowed_backup_file_paths(tables);
    for file in files {
        if let Some(path) = file.get("path").and_then(Value::as_str) {
            if !allowed_paths.contains(path) {
                anyhow::bail!("unexpected backup file path: {path}");
            }
            if Path::new(path).exists() {
                anyhow::bail!("restore conflict: file already exists: {path}");
            }
            if let Some(content) = file.get("content_b64").and_then(Value::as_str) {
                base64::Engine::decode(&base64::engine::general_purpose::STANDARD, content)?;
            }
        }
    }
    Ok(())
}

fn allowed_backup_file_paths(tables: &Map<String, Value>) -> HashSet<String> {
    tables
        .get("threads")
        .and_then(Value::as_array)
        .into_iter()
        .flatten()
        .filter_map(|row| row.get("rollout_path").and_then(Value::as_str))
        .filter(|path| !path.trim().is_empty())
        .map(ToString::to_string)

View on GitHub (pinned to b1ed92e5e4)