error returnedfrom database: (code: 5) database is locked
What version of the Codex App are you using (From “About Codex” dialog)?
26.609.4995.0
What subscription do you have?
plus
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What issue are you seeing?
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 beenrestored. If the database cannot be opened, Back Up and Rebuild moves it aside sothe app can create a fresh one.
Error: (code=1, signal=null).
Most recent error: Error: failed to initialize sqlite state runtime underWwsl.localhost\Ubuntu-22.04\home\x\.codex: failed to initialize stateruntime at \\wsl.localhost\Ubuntu-22.04\home\x\.codex: error returnedfrom database: (code: 5) database is locked
Retry
Back Up and Rebuild
Quit
What steps can reproduce the bug?
runCodexInWindowsSubsystemForLinux = true
What is the expected behavior?
_No response_
Additional information
_No response_
5 Comments
Neither Retry nor Back Up and Rebuild fixed the issue.
I also tried using a new Codex home directory inside WSL, but the issue still persists.
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:
.sqlitefiles under any.codexdirectory..sqlitefiles to keep them as backups, for example: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
.bakbackups in case they are needed later.I have already tried this approach, but the issue still persists. I even set up a new CODEX_HOME directory and let Codex regenerate the required files from scratch, but it still reports the same error.
This workaround is not an option and based on my experience causing more trouble than help
Also getting this issue on Linux and this issue is really annoying. Trying multiple times to start codex helps, so technically it can be dealt with, so that's why I recommend to now mess around with the
.sqlitefiles. Note that I usually have multiple Codex sessions running at the same time!Source trace from current main that may explain why this is recoverable by retrying but still surfaces as a hard startup failure:
codex-rs/state/src/runtime.rs(state,logs,goals,memoriesspecs).base_sqlite_optionsenables WAL and setsbusy_timeout(Duration::from_secs(5)).open_sqliteopens the pool, then runs migrations immediately. If migration fails, it closes the pool and returnsRuntimeDbInitErrorwith the phase label (openormigrate).codex-rs/state/src/runtime/recovery.rs:"database is locked"/"database is busy".codex-rs/cli/src/state_db_recovery.rsprints the generic "another Codex process is using its local data" message for any classified lock.The Linux report above looks specifically like a migration-phase lock:
That makes this different from corruption, and also different from a permanently bad sqlite file. Renaming/rebuilding sqlite files is unlikely to help if another process or concurrent startup immediately hits the same migration lock again; the user's observation that retrying startup sometimes works is consistent with transient contention.
Possible bounded fix:
SQLITE_BUSYseparately from corruption in startup UX and recovery.state_5.sqlite, instead of failing after the sqlite busy timeout once.state DB,migrate) in the user-facing locked guidance, so users do not get routed toward destructive state-reset workarounds for a contention problem.StateRuntime::initcalls against the same freshCODEX_HOMEand verifies one does not leave the other in a permanent startup-failed state.