Skip to content

Proposed fix: normalize Windows SQL migration line endings #32643

Open

Description

@JoNil-Botta

Summary

SQLx hashes the exact migration SQL bytes. Official Windows Codex builds have embedded CRLF migration files, while a Windows source checkout with core.autocrlf=false embeds LF files. A locally built binary can therefore reject a healthy database created by the official Windows package with:

migration 1 was previously applied but has been modified

The proposed fix canonicalizes runtime migrations to CRLF on Windows before SQLx executes or validates them. This makes Windows builds compatible with official Windows databases regardless of the developer checkout's line-ending configuration. It applies centrally to state, logs, goals, memories, and thread-history runtime migrators.

This addresses the native-Windows side of the migration checksum failures discussed in #23841, #23848, and #23863. Those reports also involve WSL processes opening the same Windows database; accepting both legacy LF and CRLF histories cross-platform may be a preferable broader policy. The attached patch is deliberately limited to compatibility with already-released Windows databases.

Evidence

For migration 1:

  • LF SHA-384: 627EF19164C9BB298A0CD99945981C9B7BDA3D9E6CF12EB35145E3B1D3BF7CF8740F0DBAA0B475185FC2993397078049
  • CRLF SHA-384: 54BBD6F47905A4E4C674034575963D82DA7B534E66E9A37A81EC2AFB6A4B56CE6DE9B3ECF3032796A800F650239847D4

The CRLF hash exactly matched the live database. Read-only inspection and byte-level hashing confirmed that all 40 applied state migrations matched their CRLF forms. The database was not corrupt, and no migration-table rows were edited.

Proposed patch

Validation

  • just test -p codex-state: 154 passed
  • focused CRLF-release/LF-checkout compatibility test passed
  • just fix -p codex-state
  • just fmt
  • a corrected release build opened a copied database and the live database successfully
  • codex doctor --summary --no-color --ascii: state databases healthy, 0 failures

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    on Jul 12, 2026
  2. jamespud commented on Aug 14, 2026

    @jamespud

    I've prepared a complete fix for this CRLF/LF migration checksum issue and would like to contribute it, but I'm unable to open a pull request because PRs in this repository are currently restricted to collaborators. Could a maintainer pull my branch (or invite me as a collaborator) to review it?

    Branch: jamespud:fix/32643-state-migration-line-endings
    Commit: 6247dabb4

    What it does

    • Canonicalizes runtime migrations to LF line endings on all platforms in runtime_migrator(), so embedded checksums no longer depend on the checkout's core.autocrlf / line-ending policy.
    • Adds repair_migration_line_ending_checksums(): when opening any runtime SQLite database, _sqlx_migrations rows whose checksum was computed from CRLF migration files are rewritten to the canonical LF checksum. Databases created by either CRLF or LF builds can then be opened interchangeably.
    • Applies to all six migrators (state, logs, goals, memories, queue, thread history) via the existing open_runtime_db path.

    This goes beyond the Windows-only approach described in the issue: it also covers the WSL/Linux side opening a database created by a Windows build (and vice versa), which is exactly the shared-home scenario tracked in #25216 and reported in #23777 / #23841 / #23848 / #23863.

    Verification

    • just test -p codex-state: 174 passed, including 4 new tests (LF invariant across all runtime migrators, CRLF→LF canonicalization, CRLF-applied history accepted after repair, LF-applied history unchanged).
    • just fix -p codex-state: clean (clippy).
    • cargo fmt --check: clean.

    Changes are limited to codex-rs/state/src/migrations.rs, codex-rs/state/src/sqlite.rs, and codex-rs/state/src/migrations_tests.rs (+205/-1 total).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workingwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions