openai/codex · error · anyhow::Error

failed to initialize sqlite state runtime after moving…

Error message

failed to initialize sqlite state runtime after moving damaged database file into a backup folder: {err}

What it means

Raised during sqlite state-db bootstrap corruption recovery. The runtime detected a damaged (or blocking) database file, moved it into a backup folder, and retried initializing a fresh state runtime — but that re-initialization still failed with {err}. The recovery path itself therefore failed after the salvage step, so the state db cannot be opened or rebuilt.

Solutions

  1. Inspect {err} to find why the fresh runtime init failed (permissions, disk space, lock held by another process)
  2. Check the backup folder location is writable and the moved files are not still locked
  3. Verify codex_state runtime prerequisites (directory exists, schema migration can run)
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at codex-rs/app-server/src/lib.rs:1266 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/a29e13edaf9a90fa. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/app-server/src/lib.rs:1266

                    }
                }
                return Ok(StateDbInitResult {
                    state_db: Some(state_db),
                    recovery_notice,
                });
            }
            Err(err) => err,
        };
        let database_path = codex_state::runtime_db_path_for_corruption_error(&err)
            .unwrap_or_else(|| config.sqlite_config().state_db_path());
        if !codex_state::is_sqlite_corruption_error(&err)
            && !sqlite_home_is_blocking_file(database_path.as_path())
        {
            return Err(err);
        }

        if !attempted_backups.insert(database_path.clone()) {
            return Err(anyhow::anyhow!(
                "failed to initialize sqlite state runtime after moving damaged database file into a backup folder: {err}"
            ));
        }

        let original_error = err.to_string();
        emit_state_db_backup_warning(&format!(
            "Codex local database at {} appears damaged. Moving it into a backup folder so the app server can rebuild it from saved data.",
            database_path.display()
        ));
        let backups = codex_state::backup_runtime_db_for_fresh_start(database_path.as_path())
            .await
            .map_err(|backup_err| {
                anyhow::anyhow!(
                    "failed to move damaged sqlite state database files into a backup folder: {backup_err}; original error: {original_error}"
                )
            })?;
        for backup in &backups {
            emit_state_db_backup_warning(&format!(

View on GitHub (pinned to 339751715c)