Repository navigation
Description
Hello,
I have a reviewed and tested fix for the SQL migration CRLF/LF checksum issue tracked in #32643.
Root cause:
SQLx checksums the exact migration bytes embedded at compile time. Migration files checked out with CRLF (for example, on Windows with core.autocrlf=true) therefore produce different checksums than LF checkouts. Databases created by one build fail to open in another with:
migration N was previously applied but has been modified
This also breaks the Windows + WSL shared-Codex-home scenario tracked in #25216 (see #23777, #23841, #23848, #23863), where a WSL runtime must open a database created by a Windows build and vice versa.
Fix:
- Canonicalizes runtime migrations to LF line endings on all platforms in
runtime_migrator(), so embedded checksums no longer depend on checkout line-ending policy. - Adds
repair_migration_line_ending_checksums(): when opening any runtime SQLite database,_sqlx_migrationsrows whose checksum was computed from CRLF migration files are rewritten to the canonical LF checksum, so histories created by either build are accepted interchangeably. - Applies to all six runtime migrators (state, logs, goals, memories, queue, thread history).
- Genuine migration drift is still rejected: the repair only rewrites rows that exactly match the CRLF form of the current migration.
Validation:
codex-state: 174/174 tests passed, including 4 new tests (LF invariant across all runtime migrators, CRLF→LF canonicalization, CRLF-applied history accepted after repair, LF-applied history unchanged)- scoped Clippy (
just fix -p codex-state): clean cargo fmt --check: clean- Change is limited to
codex-rs/state(+205/-1 across 3 files)
Prepared patch
The fix is available in my fork:
- Fork:
[jamespud/codex](https://github.com/jamespud/codex) - Branch:
[fix/32643-state-migration-line-endings](https://github.com/jamespud/codex/tree/fix/32643-state-migration-line-endings)
GitHub currently blocks PR creation because only collaborators may open pull requests in this repository.
Could you please either:
- invite
jamespudas a collaborator with permission to open the PR, or - open the PR from the prepared fork branch?
Thank you.
Activity
jdcodes1 commentedon Aug 18, 2026
Independent verification of the root cause against
main(1f41cc5): the six runtime DBs all embed their.sqlfiles via sqlx's compile-time migrator (state/src/sqlite.rs, migration dirs likestate/migrations/,state/queue_migrations/), and the repo's.gitattributescontains no*.sql text eol=lfrule — only two linguist entries. So on acore.autocrlf=truecheckout the embedded bytes really are CRLF, the checksum diverges from LF builds, andmigration N was previously applied but has been modifiedfollows exactly as described. The Windows↔WSL shared-home case (#25216) is the worst hit because two differently-built binaries open the same database file.One addition to the proposed fix: alongside runtime canonicalization + checksum repair, add
*.sql text eol=lfto.gitattributesso future checkouts can't reintroduce the divergence at the source. The repair pass is still needed for databases already stamped with CRLF checksums, and restricting it to rows matching the CRLF form of the current migration keeps genuine-drift detection intact — that design looks right.jamespud commentedon Aug 18, 2026
Thanks for the independent verification — glad the root-cause analysis and the checksum-repair design hold up against
main.I've incorporated your suggestion. The branch now adds a
*.sql text eol=lfrule to.gitattributes(commitc291fa484) so every checkout embeds LF regardless ofcore.autocrlf, closing the source-side gap. For the record,git add --renormalizewas a no-op on the existing.sqlblobs (they're already stored as LF), so the change stays minimal — the runtime canonicalization + checksum repair in6247dabb4remains the part that heals databases already stamped with CRLF checksums.Updated branch:
jamespud:fix/32643-state-migration-line-endings(commits6247dabb4+c291fa484).[-]Request to submit deferred migration line-ending checksum fix[/-][+][Windows App] Request to submit deferred migration line-ending checksum fix[/+]Shad0wWulf commentedon Aug 30, 2026
I can independently confirm this CRLF/LF migration-checksum problem is still reproducible with a current Windows Desktop + WSL setup, and I was able to recover the existing profile without deleting/rebuilding the affected databases.
Environment
26.825.6671.0codex-cli 0.151.0-alpha.7.26.6.87.2-microsoft-standard-WSL2/mnt/c/Users/<user>/.codexFailure
Running the bundled WSL app-server against the real profile failed with:
This was not ordinary SQLite corruption:
PRAGMA quick_checkreturnedokfor the runtime DBs.CODEX_HOMEworked.CODEX_HOMEon/mnt/calso worked, so/mnt/citself was not sufficient to reproduce the failure.Isolation
Using the same bundled WSL runtime and a 30-second app-server startup test, I tested the existing runtime DBs individually:
state_5.sqlite-> FAILgoals_1.sqlite-> FAILmemories_1.sqlite-> FAILqueue_1.sqlite-> FAILthread_history_1.sqlite-> PASSI then generated fresh databases with the exact same WSL runtime and compared
_sqlx_migrations.The migration versions/descriptions matched, but the checksums differed systematically. For example, state migration 1 in the existing DB began
54 bb d6 f4..., while the fresh WSL DB began62 7e f1 91..., matching the CRLF/LF checksum pattern described in this issue.Controlled proof
Before touching the real profile, I made a disposable clone containing the original failing
goals_1.sqlite._sqlx_migrations.checksum, copying the checksum values for matching migration versions from a fresh DB generated by the current WSL runtime.That provided a useful A/B result: no schema/data rebuild was required; changing only the migration checksum metadata changed FAIL -> PASS.
Recovery of the real profile
After making a full backup, I copied the fresh WSL-generated
_sqlx_migrations.checksumvalues into the matching migration rows of:state_5.sqlitegoals_1.sqlitememories_1.sqlitequeue_1.sqliteI left
thread_history_1.sqliteuntouched because it had already passed independently.After that, the original real profile successfully ran the bundled WSL
app-serverfor 30+ seconds. Codex Desktop was then switched back to WSL mode and tested with actual turns: shell commands worked in WSL, files could be created/deleted, and the Desktop Review/diff UI worked normally. Existing profile/history was retained.So this appears to be a strong real-world confirmation of the diagnosis and repair strategy in #38528. In particular, the generic
failed to initialize sqlite state runtimemessage can hide a migration checksum incompatibility even when all DBs pass SQLite integrity checks.I would strongly recommend an upstream automatic/safe repair along the lines proposed here rather than requiring users to delete/rebuild their state databases.
This comment was written with assistance from ChatGPT after an interactive diagnostic session; the commands, outputs, A/B tests, and final recovery were run and verified on the affected machine by the user.
Wuodan commentedon Nov 4, 2026
acp-wsl: ACP proxy for Windows ↔ WSL path translation
Up to now, using ACP to connect clients like IDE plugins to codex or other agents in WSL, did not work due to clients sending Windows paths in ACP.
I just released acp-wsl to solve this.
It's a small ACP proxy which has a pinned ACP schema definition and rules for know path fields in it.
Additionally it converts paths fields outside the official ACP definition. Such protocol extensions are allowed and Codex uses them.
(Performant check: first looks at leading few bytes and secondly at full field value.)
Maybe you can use
acp-wslin your WSL setup or want to include similar code to your project.