Lightweight coding agent that runs in your terminal
Rust
feat: auto vaccum state DB (#16434)
jif-oaif839f3ff2ed9
diff --git a/codex-rs/state/src/runtime.rs b/codex-rs/state/src/runtime.rsindex 3fc524461c..4d3af301b2 100644--- a/codex-rs/state/src/runtime.rs+++ b/codex-rs/state/src/runtime.rs@@ -147,12 +147,28 @@ fn base_sqlite_options(path: &Path) -> SqliteConnectOptions {}async fn open_state_sqlite(path: &Path, migrator: &'static Migrator) -> anyhow::Result<SqlitePool> {- let options = base_sqlite_options(path);+ let options = base_sqlite_options(path).auto_vacuum(SqliteAutoVacuum::Incremental);let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await?;migrator.run(&pool).await?;+ let auto_vacuum = sqlx::query_scalar::<_, i64>("PRAGMA auto_vacuum")+ .fetch_one(&pool)+ .await?;+ if auto_vacuum != SqliteAutoVacuum::Incremental as i64 {+ // Existing state DBs need one non-transactional `VACUUM` before+ // SQLite persists `auto_vacuum = INCREMENTAL` in the database header.+ sqlx::query("PRAGMA auto_vacuum = INCREMENTAL")+ .execute(&pool)+ .await?;+ // We do it on best effort. If the lock can't be acquired, it will be done at next run.+ let _ = sqlx::query("VACUUM").execute(&pool).await;+ }+ // We do it on best effort. If the lock can't be acquired, it will be done at next run.+ let _ = sqlx::query("PRAGMA incremental_vacuum")+ .execute(&pool)+ .await;Ok(pool)}