Codex App fails to launch after update on macOS: state runtime sqlite (state_5.sqlite) "database disk image is malformed"

Resolved 💬 6 comments Opened May 22, 2026 by LaZzyMan Closed Jul 6, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the Codex App are you using (From "About Codex" dialog)?

unknown — the app fails before the About dialog is reachable.

What subscription do you have?

Pro

What platform is your computer?

Darwin 24.6.0 arm64 arm

(MacBook Pro 14" 2024, Apple M4 Pro, 48 GB RAM, macOS Sequoia 15.7.3)

What issue are you seeing?

After updating the Codex App on macOS, the app fails to finish launching and shows a modal error dialog:

Codex cannot access its local database. The app cannot finish launching until its SQLite database is accessible. Database path: Path unavailable in app-server startup error Close other Codex applications, then click Retry to check whether access has been restored. Error: (code=1, signal=null). Most recent error: Error: failed to initialize sqlite state runtime under /Users/xxxx/.codex: failed to initialize state runtime at /Users/xxxx/.codex: error returned from database: (code: 11) database disk image is malformed

Clicking Retry reproduces the same error. Quit is the only way out; the app cannot be used at all.

Filesystem state under ~/.codex

The state runtime sqlite file referenced in the error exists, along with two other sqlite files:

| File | Size |
|---|---|
| state_5.sqlite | 315 KB |
| goals_1.sqlite | 24 KB |
| logs_2.sqlite | 956 MB |

logs_2.sqlite being ~1 GB looks abnormal; not sure whether the corruption is in state_5.sqlite (the file named in the error) or whether the oversized logs DB is contributing to the failure. Happy to upload a sqlite-integrity check report if useful.

What steps can reproduce the bug?

  1. Use the Codex App on macOS normally for some time (regular use over several weeks; sqlite files accumulate).
  2. Let the app auto-update (or update via the in-app updater) to the latest version.
  3. Relaunch Codex.
  4. The "Codex cannot access its local database" modal appears immediately on startup; Retry has no effect.

I cannot provide a session id, token limit usage, or context window usage — the app never reaches a state where any session is started.

What is the expected behavior?

  • The app should launch normally after an update.
  • If a state-runtime SQLite file is detected as corrupt, the app should either (a) auto-recover by quarantining the bad file and re-initializing, or (b) surface a clear remediation path (e.g. "rename state_5.sqlite and restart") rather than wedging at startup with no actionable next step.

This is the same class of issue tracked in #21750 (no auto-recovery for a corrupt state_5.sqlite) — that issue's resolution would address this case too.

Additional information

  • Same symptom reported by another macOS user in #24006 (also Darwin arm64). Filing separately, but treating these as likely the same root cause.
  • Windows-side equivalents: #23780 (closed), #23923, #23893 — pattern of startup-blocking SQLite errors after updates appears cross-platform.
  • #23848 claims to share a fix; if a documented workaround exists, please link it from this issue or pin it somewhere discoverable from the error dialog itself.
  • state_5.sqlite has not been deleted/renamed — happy to keep it intact in case the team wants the corrupt file for diagnostics. Let me know if you'd like me to upload a sanitized copy.

View original on GitHub ↗

6 Comments

github-actions[bot] contributor · 1 month ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #24006
  • #23917
  • #23247
  • #22942
  • #24001

Powered by Codex Action

LaZzyMan · 1 month ago

Update — workaround confirmed. Renaming the corrupt state DB and relaunching gets the app back to a working state:

mv ~/.codex/state_5.sqlite ~/.codex/state_5.sqlite.bak

Then quit and reopen Codex. The app rebuilds a fresh state_5.sqlite on startup and launches normally.

Confirmed on my setup (Darwin 24.6.0 arm64, M4 Pro, macOS 15.7.3, Pro plan). App is fully usable again.

A few notes for anyone hitting this:

  • Keep the .bak file for at least a session or two in case you discover missing state (project metadata, threads, etc.) and want to extract anything via sqlite3 state_5.sqlite.bak ".recover". In my case nothing important seemed lost after the rebuild, but YMMV.
  • logs_2.sqlite (956 MB in my case) was untouched by this workaround and the app launches fine with it in place — so the corruption that wedges startup really is isolated to state_5.sqlite, not the oversized logs DB. That said, ~1 GB for a logs DB still looks like an unbounded-growth bug worth a separate look.
  • This is exactly the auto-recovery behavior requested in #21750 — the app already does the right thing if state_5.sqlite is missing; it just doesn't handle the corrupt case. Detecting SQLITE_CORRUPT / database disk image is malformed at startup and quarantining the file (e.g. rename to state_5.sqlite.corrupt-<timestamp>) before reinitializing would resolve this entire class of post-update startup failures with no user intervention.

Hope this helps whoever lands here next while a proper fix is in flight.

Toolenaar · 1 month ago

For me it was the logs_2.sqlite that gave the crash. I renamed that one and it started working again

jshaofa-ui · 1 month ago

Proposed Solution: SQLite Corruption Auto-Recovery

Root Cause

StateRuntime::init_inner() handles missing databases (re-initializes) but does NOT handle corrupt databases — it hard-fails on any DB error including SQLITE_CORRUPT / "database disk image is malformed".

Fix

  1. Auto-Recovery by Quarantine: Detect corrupt DB at startup, rename to .corrupt.{timestamp}.bak, re-initialize
  2. Pre-Open Integrity Check: Run PRAGMA integrity_check before attempting to use the database
  3. Bounded Log Growth: 50MB cap on logs_2.sqlite with periodic VACUUM
  4. User-Facing Error Message: Clear recovery instructions instead of generic "cannot access database"

Key Code Change

// codex-rs/core/src/runtime.rs
fn recover_corrupt_db(db_path: &Path) -> Result<()> {
    let timestamp = Utc::now().format("%Y%m%d_%H%M%S");
    let backup_path = db_path.with_extension(format!("corrupt.{}.bak", timestamp));
    std::fs::rename(db_path, &backup_path)?;
    warn!("Quarantined corrupt database to {:?}", backup_path);
    Ok(())
}

Full solution: solutions/codex-24030-sqlite-corruption-auto-recovery-fix.md

mgnsharon · 1 month ago

It happens every time it autoupdates for me. Just discovered you can launch it from the command line, it'll prompt you to fix the database, then launch normally without loosing your data.

wangskyone · 1 month ago

Workaround: reset Codex SQLite state

I ran into an issue where Codex could no longer open, and the root cause appeared to be related to its local SQLite state files.

The workaround that fixed it for me was:

  1. Find all .sqlite files under any .codex directory.
  2. Rename those .sqlite files to keep them as backups, for example:
file.sqlite -> file.sqlite.bak
  1. Restart Codex and let it generate fresh SQLite database files automatically.

After doing this, Codex was able to start normally again.

Note that this may reset some local Codex state, but the original SQLite files are still preserved as .bak backups in case they are needed later.