Fix SQLite WAL-reset corruption exposure

Codex uses pooled WAL-mode SQLite state databases, and the bundled SQLite 3.46.0 is affected by the documented WAL-reset corruption race. Bundle fixed SQLite 3.51.3 through a pinned libsqlite3-sys override and guard the linked runtime version in codex-state tests.
This commit is contained in:
Brent Traut
2026-05-26 16:36:54 -07:00
parent cd934c8bcb
commit 8e85a35ec6
32 changed files with 582649 additions and 3 deletions
+30
View File
@@ -569,6 +569,36 @@ mod tests {
let _ = tokio::fs::remove_dir_all(codex_home).await;
}
#[tokio::test]
async fn linked_sqlite_has_wal_reset_bug_fix() {
let pool = SqlitePool::connect("sqlite::memory:")
.await
.expect("open in-memory sqlite db");
let sqlite_version: String = sqlx::query_scalar("SELECT sqlite_version()")
.fetch_one(&pool)
.await
.expect("query linked sqlite version");
pool.close().await;
let version = sqlite_version
.split('.')
.map(|part| part.parse::<u32>().expect("numeric sqlite version"))
.collect::<Vec<_>>();
assert_eq!(
version.len(),
3,
"unexpected SQLite version: {sqlite_version}"
);
let version = (version[0], version[1], version[2]);
let includes_wal_reset_fix = version >= (3, 51, 3)
|| (version.0 == 3 && version.1 == 50 && version.2 >= 7)
|| (version.0 == 3 && version.1 == 44 && version.2 >= 6);
assert!(
includes_wal_reset_fix,
"linked SQLite {sqlite_version} is vulnerable to the WAL-reset corruption bug"
);
}
#[tokio::test]
async fn open_state_sqlite_tolerates_newer_applied_migrations() {
let codex_home = unique_temp_dir();