database is locked
Open 💬 7 comments Opened Jul 5, 2026 by nuliknol
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
What version of Codex CLI is running?
v0.142.5
What subscription do you have?
PRO 20x
Which model were you using?
all of them
What platform is your computer?
Linux Ubuntu
What terminal emulator and version are you using (if applicable)?
xterm-256color
Codex doctor report
What issue are you seeing?
I have many agents with the same CODEX_HOME coding in parallel. But out of the sudden I ran into a race condition (at starting a new codex session):
Codex couldn't start because another Codex process is using its local data.
Quit any other copies of Codex that may still be running, then try again.
Technical details:
Location: /home/mf/codex-cli/state_5.sqlite
Cause: failed to initialize state runtime at /home/mf/codex-cli: failed to open state DB at /home/mf/codex-cli/state_5.sqlite: error returned from database: (code: 5) database is locked: error returned from database: (code: 5) database is locked: (code: 5) database is locked
ERROR: failed to initialize sqlite local db at /home/mf/codex-cli/state_5.sqlite: failed to initialize state runtime at /home/mf/codex-cli: failed to open state DB at /home/mf/codex-cli/state_5.sqlite: error returned from database: (code: 5) database is locked: error returned from database: (code: 5) database is locked: (code: 5) database is locked
Could you please add the PID of blocking process? This message doesn't help, I need to know which process is blocking so I can kill it. Also, locks should be timed out automatically if there is no running queries. If the process has the DB locked, and it is not alive, you should drop the connection and put the DB in unlocked state
What steps can reproduce the bug?
Race condition, not reproducible
What is the expected behavior?
_No response_
Additional information
_No response_
7 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
After 15 minutes I got a prompt, so probably it is related to heavy I/O on my disk. Maybe you could reproduce it if you start some disk io benchmark, and at the same time, try to open a few codex-cli instances
this happens when disk has too many write requests and can't execute the IO request from codex. I got this race condition when using multiple agents on HDD filesystem. After moving to SSD filesystem, these errors disappeared. But still this is a race condition, I should not see this , I should see a timeout, like : io request timed out, startup aborted
Hit this on Codex CLI (Linux) from a different trigger than a race or slow disk: a single crashed front-end left its backend orphaned, and the orphan kept holding the lock.
When the TUI died, three processes stayed alive:
codexnpx launchercodexbinary — this one heldstate_5.sqlite+logs_2.sqlitecodex-code-mode-hostfuser state_5.sqlite logs_2.sqlitepointed straight at the still-running backend PID. Relaunch stayed blocked until those were killed; after that it started clean. No concurrency, NFS, or HDD involved — just one crash that leaked its own children.So +1 on the two asks in this issue:
A front-end that reaped its child processes on crash would also prevent this outright.
A tested fix is available in this fork:
The change addresses both failure modes discussed here:
auto_vacuum, which can require a write lock and cause startup to fail while another connection is writing.SIGHUPto the native Codex child if its terminal/frontend parent disappears, preventing orphaned processes from retainingstate_5.sqliteandlogs_2.sqlite.Validation completed:
just test -p codex-state: 159 passedGitHub currently shows that upstream pull requests are restricted to repository collaborators, so I cannot open the PR from the fork. If a maintainer can enable the PR, open it internally from this commit, or cherry-pick the change, the branch is ready.
I was having a similar issue, on Rocky Linux, I made a backup folder of codex, simply using
mv .codex .codex.bak. Then opened the locked db file in the .codex.bak using sqlite3 and made a backup db using.backup main backup.sqlite. After making the backup I did acp backup.sqlite ../.codex/<locked db name>and remove the -shm and -wal files of the affected db. After that codex ran smoothlyRegarding SQLite
database is locked/ WAL lock contention in Codex:This error occurs when a previously killed Codex background worker or subagent leaves an open advisory file descriptor (OFD lock) or uncommitted WAL transaction on
~/.codex/state_*.sqlite/logs_2.sqlite. Because standard SQLite connections fail fast when a writer holds the lock, restarting the TUI or app-server throwsdatabase is locked.To diagnose lock holders and recover the database state without losing chat rollouts:
You can use the open-source Vetto Codex adapter:
How it handles the lock:
wal_checkpoint(PASSIVE)under an isolated session context.~/.codex.