Codex Desktop loses visible chat history when local state SQLite index is corrupted
What issue are you seeing?
After quitting Codex Desktop with Cmd+Q and reopening it, previous chat history appeared to be gone. The underlying rollout/session files were still present under ~/.codex/sessions, but the app history UI could not show them.
Diagnosis:
- codex doctor reported: state database integrity check failed
- state DB: ~/.codex/state_5.sqlite
- error: database disk image is malformed
- rollout files scan: no errors
The actual conversation data was not lost. The history index database was corrupted. Rebuilding state_5.sqlite from rollout files restored the history.
Why this is a product issue
Users should not need to know about state_5.sqlite, SQLite WAL files, or manually rebuild a local thread index. If the index is corrupt but rollout files are intact, Codex should detect this automatically and rebuild/repair the index, or at least show a clear recovery prompt.
Expected behavior
- Codex should not show history as empty when rollout files still exist.
- On startup, if state_5.sqlite integrity check fails, Codex should automatically rebuild the thread index from ~/.codex/sessions and ~/.codex/archived_sessions.
- The app should preserve the corrupted DB as a backup for diagnostics.
- The UI should show a clear message like: History index was repaired; your conversations were preserved.
Actual behavior
History appeared missing after restart, even though rollout files were still present.
Suggested fix
Add startup integrity checking for the local state DB and automatic recovery from rollout JSONL files.
Environment
- Codex Desktop app
- macOS 15.5
- Codex CLI/runtime: 0.138.0-alpha.7
- Storage path: ~/.codex
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Adding another macOS case with the same user-visible failure mode: local conversation history became inaccessible because the Codex state SQLite database was malformed.
Environment:
User-visible error shown by Codex Desktop on launch:
What I found locally:
~/.codex/state_5.sqlitewas malformed..recoverwas able to extract 24 thread rows from that malformed backup.state_5.sqliteandlogs_2.sqliteboth pass integrity checks.session_index.jsonlandexternal_agent_session_imports.jsonreferenced older imported sessions that were missing fromstate_5.sqlite.claude-importthreads, andPRAGMA integrity_checkreturnsok.missing_json: 0.Impact:
This looked like conversation history loss to the user, and Codex Desktop was blocked from launching by the malformed SQLite state database. Recovery required manual database inspection, SQLite recovery, reconstructing missing thread rows, generating rollout JSONL files, and backing up/restoring state. That is too much for a normal user, especially because the conversations may contain important project context.
Suggested product behavior:
state_5.sqlitebefore failing the whole app launch.sessions/**/rollout-*.jsonl,archived_sessions,session_index.jsonl, and imported-session metadata.Database path: Path unavailable.codex doctor --repair-historyor an equivalent Desktop recovery flow.No raw rollout content, full database files, logs, auth files, or private prompts are attached publicly. I can provide redacted diagnostic queries or recovery statistics if maintainers say which fields are useful and safe to share.
This is a clean index-versus-transcript case: SQLite reported
database disk image is malformed, while rollout scanning had no errors and rebuilding the index restored history.I’m testing Codex Rescue as a local-first diagnostic when the durable rollout survives but Codex’s state database does not. It will not repair or modify SQLite and leaves every source rollout untouched. The useful check is whether it can independently enumerate and classify the sessions before any index rebuild.
If you retained the pre-rebuild backup or encounter it again, could you run:
pipx install codex-rescue==0.1.0a3codex-rescue sessionscodex-rescue doctor --latestPlease share sanitized output only—no databases, raw JSONL, prompts, local paths, account data, or secrets.
https://github.com/shleder/codex-rescue
Adding a recurrent macOS case with an archive failure as the user-visible symptom.
Environment
26.820.60940, build711926.6.2, build25G83, Apple Siliconcodex-cli:0.150.0-alpha.8codex-cli:0.150.0~/.codexis on an internal APFS SSDRecurrence
The previous state database became corrupt on August 20. I rebuilt Codex from scratch that evening. The replacement
state_5.sqlitebecame corrupt again by August 26.This has happened repeatedly despite several complete Codex resets, roughly once per week.
Current failure
Archive requests reach
thread/archive, then fail with:PRAGMA quick_checkreports:codex doctor --jsonreports many missing entries across additional thread indexes.logs_2.sqliteis also inconsistent:The goals, memories, queue, and thread-history databases pass integrity checks.
Data and recovery validation
The rollout files remain present:
I created read-only snapshots and tested repairs without modifying the active databases:
The conversation records remain intact, and the current state corruption is repairable without rebuilding all Codex data.
Update timing
The first archive failure was logged at
2026-08-26T23:06:20Z.The Sparkle updater did not begin installing the current update until
2026-08-26T23:06:31Z, so the corruption existed before that update started.No database files or raw rollout content are attached because they contain private thread metadata.