WSL agent environment corrupts local state_5.sqlite migration on Windows
Open 💬 14 comments Opened May 21, 2026 by daikihashimoto95
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Environment
- Windows 10 Home
- Version: 2009
- Build: 26200
- Architecture: 64-bit
WSL
- WSL version: 2.3.26.0
- Kernel version: 5.15.167.4-1
- Distro: Ubuntu (WSL2)
Installed distros:
Ubuntu Running Version 2
docker-desktop Running Version 2
Codex local directory
C:\Users\daiki\.codex
WSL accesses the same directory through:
/mnt/c/Users/daiki/.codex
---
Reproduction Steps
- Launch Codex normally on Windows
- Existing
.codexdirectory and local chat history already present - Open Codex settings
- Change:
Agent environment -> WSL
- Restart Codex
- Codex fails during startup with:
error: while executing migration 1:
migration 1 was previously applied but has been modified
---
Observed Behavior
state_5.sqlitebecomes unusable- Existing chat history cannot be loaded
- Restoring the previous
.codexdirectory reproduces the same error - Renaming
.codexallows Codex to launch again with a fresh state
---
Expected Behavior
Switching to WSL agent mode should not invalidate existing SQLite migrations or corrupt local state/history.
---
Additional Diagnostics
Relevant files
state_5.sqlite
state_5.sqlite-shm
state_5.sqlite-wal
logs_2.sqlite
Notes
- No manual modification of SQLite files
- No custom
CODEX_HOME - No symlink setup
- Problem started immediately after enabling WSL agent mode
- Looks related to migration checksum mismatch between Windows and WSL environments
---
14 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
same problem
any fixes?
Deleting the .codex directory and restarting Codex fixed the startup issue for me, but it also wiped all local chat history.
At the moment I don't know a way to recover/fix the migration issue while preserving the existing chat history database.
but deleting .codex directory changes WSL to Windows Native as well
You're right. I forgot to mention that.
Deleting the
.codexdirectory also reset the agent environment setting from WSL back to Windows Native. But to be clear, that was just a workaround to get it launching again, not a proper fix for the underlying issue.when i perform an app refresh on a fresh .codex directory to allow wsl again it crash again with the same issue
same issue
yeah. same
I may have found a temporary workaround.
First, install the Codex CLI package wsl side:
Then set the CODEX_HOME environment variable so it points to the Windows .codex directory and run codex
CODEX_HOME=/mnt/c/Users/username/.codex codexCodex should detect the corrupted database and repair it.
<img width="1396" height="215" alt="Image" src="https://github.com/user-attachments/assets/fc8efdfd-04b9-46e6-a483-fe5959a90e87" />
Once the repair is complete, the Codex app should be able to run with WSL support again.
@sabruss it works, thx.
btw, we can run
CODEX_HOME=/mnt/c/Users/username/.codex codexin one line to avoid the restarting.thank you. it works.
Technical Solution for WSL State Corruption
Root Cause
NOT actual database corruption — it is a CRLF/LF line ending mismatch in SQLx migration checksums:
\r\n) line endings\n) line endingssha384(CRLF) != sha384(LF)Proposed Fix (4-part)
.gitattributes+normalize_migration_sql()to ensure consistent line endingsCode Changes
.gitattributes: Add* text=auto eol=lffor SQL filescrates/codex-sqlx/src/migration.rs: Addnormalize_migration_sql()+ checksum repaircrates/codex-app/src/db.rs: Add per-environment DB pathTest Plan
Impact
Full solution:
solutions/codex-23841-wsl-agent-corrupts-state-sqlite-fix.mdThis looks like the same CRLF/LF SQLx checksum mismatch tracked in #23777 and #23787. Switching a Windows-created
CODEX_HOMEto the WSL backend can make the Linux binary expect LF-hashed migrations while the existing SQLite DB has CRLF-hashed_sqlx_migrationsrows. Deleting.codexgets the app launching again, but it loses the existing local history metadata.For a non-destructive recovery path, I published a small Apache-2.0 toolkit here: https://github.com/xdifu/codex-repair
Windows PowerShell / Windows Terminal:
If you run it from WSL bash to repair Windows Codex Desktop data, pass
--codex-home "/mnt/c/Users/<WindowsUser>/.codex"so it does not target WSL's own~/.codex.It extracts the expected checksums from the active Codex backend binary, schema-verifies before any write, backs up
state_5.sqlite/logs_2.sqlite, and can also finish the state backfill outside the 30s GUI timeout.sessions/*.jsonlstays read-only.it's actually logs_2.sqlite
solved here:
https://github.com/openai/codex/issues/23863