Centralize SQLite connection configuration (#34808)

## What changed

- Add `SqliteConfig` to own the resolved SQLite home, runtime database paths,
  and shared read/write and read-only pool settings.
- Pass the configuration through state and local thread-store consumers,
  replacing standalone path helpers and duplicated connection setup.

GitOrigin-RevId: 7351b08da94b5c8b6c0bbe492f86aeeca0699d3c
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-07-22 18:45:47 +00:00
1 parent a59a419afa
commit 946ed315a4
35 files changed
+445 -397

No files matched your search

@@ -20,7 +20,7 @@ pub(super) async fn create_thread(
})?;
let config = RolloutConfig {
codex_home: store.config.codex_home.clone(),
sqlite_home: store.config.sqlite_home.clone(),
sqlite_home: store.config.sqlite.home().to_path_buf(),
cwd,
model_provider_id: params.metadata.model_provider.clone(),
generate_memories: matches!(params.metadata.memory_mode, ThreadMemoryMode::Enabled),
@@ -41,7 +41,7 @@ pub(super) async fn list_threads(
let state_db = store.state_db().await;
let rollout_config = RolloutConfig {
codex_home: store.config.codex_home.clone(),
sqlite_home: store.config.sqlite_home.clone(),
sqlite_home: store.config.sqlite.home().to_path_buf(),
cwd: store.config.codex_home.clone(),
model_provider_id: store.config.default_model_provider_id.clone(),
generate_memories: false,
@@ -93,7 +93,7 @@ pub(super) async fn resume_thread(
})?;
let config = RolloutConfig {
codex_home: store.config.codex_home.clone(),
sqlite_home: store.config.sqlite_home.clone(),
sqlite_home: store.config.sqlite.home().to_path_buf(),
cwd,
model_provider_id: params.metadata.model_provider.clone(),
generate_memories: matches!(params.metadata.memory_mode, ThreadMemoryMode::Enabled),
+21 -12
View File
@@ -22,6 +22,8 @@ use codex_protocol::ThreadId;
use codex_protocol::protocol::ThreadHistoryMode;
use codex_rollout::RolloutRecorder;
use codex_rollout::StateDbHandle;
use codex_state::SqliteConfig;
use codex_utils_absolute_path::AbsolutePathBuf;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::path::PathBuf;
@@ -115,16 +117,23 @@ impl LiveWriterLocks {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LocalThreadStoreConfig {
pub codex_home: PathBuf,
pub sqlite_home: PathBuf,
pub sqlite: SqliteConfig,
/// Provider used only when older local metadata does not contain one.
pub default_model_provider_id: String,
}
impl LocalThreadStoreConfig {
#[expect(
clippy::expect_used,
reason = "resolved Codex configuration paths must be absolute"
)]
pub fn from_config(config: &impl codex_rollout::RolloutConfigView) -> Self {
Self {
codex_home: config.codex_home().to_path_buf(),
sqlite_home: config.sqlite_home().to_path_buf(),
sqlite: SqliteConfig::from_sqlite_home(
AbsolutePathBuf::from_absolute_path_checked(config.sqlite_home())
.expect("sqlite home from resolved config should be absolute"),
),
default_model_provider_id: config.model_provider_id().to_string(),
}
}
@@ -158,7 +167,7 @@ impl LocalThreadStore {
async fn thread_history_db(&self) -> ThreadStoreResult<&sqlx::SqlitePool> {
self.thread_history_db
.get_or_try_init(|| async {
codex_state::open_thread_history_db(self.config.sqlite_home.as_path()).await
codex_state::open_thread_history_db(self.config.sqlite.home()).await
})
.await
.map_err(|err| ThreadStoreError::Internal {
@@ -499,7 +508,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -534,7 +543,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -569,7 +578,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -637,7 +646,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -726,7 +735,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -762,7 +771,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -802,7 +811,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -846,7 +855,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -901,7 +910,7 @@ mod tests {
let external_home = TempDir::new().expect("external temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
+12 -12
View File
@@ -608,7 +608,7 @@ mod tests {
let active_path =
write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -767,7 +767,7 @@ mod tests {
let rollout_path =
write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -812,7 +812,7 @@ mod tests {
)
.expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -855,7 +855,7 @@ mod tests {
let rollout_path =
write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -896,7 +896,7 @@ mod tests {
let rollout_path =
write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -930,7 +930,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1066,7 +1066,7 @@ mod tests {
writeln!(file, "{meta}").expect("write session meta");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1120,7 +1120,7 @@ mod tests {
write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file");
let stale_path = external.path().join("missing-rollout.jsonl");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1171,7 +1171,7 @@ mod tests {
let stale_path = write_session_file(external.path(), "2025-01-04T12-00-00", other_uuid)
.expect("other session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1270,7 +1270,7 @@ mod tests {
.path()
.join(format!("rollout-2025-01-03T12-00-00-{uuid}.jsonl"));
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1332,7 +1332,7 @@ mod tests {
.path()
.join(format!("rollout-2025-01-03T12-00-00-{uuid}.jsonl"));
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1387,7 +1387,7 @@ mod tests {
let archived_path = write_archived_session_file(home.path(), "2025-01-03T12-00-00", uuid)
.expect("archived session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -60,7 +60,7 @@ pub(super) async fn search_threads(
let state_db = store.state_db().await;
let rollout_config = RolloutConfig {
codex_home: store.config.codex_home.clone(),
sqlite_home: store.config.sqlite_home.clone(),
sqlite_home: store.config.sqlite.home().to_path_buf(),
cwd: store.config.codex_home.clone(),
model_provider_id: store.config.default_model_provider_id.clone(),
generate_memories: false,
@@ -5,6 +5,7 @@ use std::path::PathBuf;
use codex_protocol::protocol::ThreadHistoryMode;
use codex_rollout::ARCHIVED_SESSIONS_SUBDIR;
use codex_utils_absolute_path::test_support::PathExt;
use uuid::Uuid;
use super::LocalThreadStoreConfig;
@@ -12,7 +13,7 @@ use super::LocalThreadStoreConfig;
pub(super) fn test_config(codex_home: &Path) -> LocalThreadStoreConfig {
LocalThreadStoreConfig {
codex_home: codex_home.to_path_buf(),
sqlite_home: codex_home.to_path_buf(),
sqlite: codex_state::SqliteConfig::new_for_testing(codex_home.abs()),
default_model_provider_id: "test-provider".to_string(),
}
}
@@ -32,7 +32,7 @@ pub(super) async fn next_rollout_byte_offset(
store: &LocalThreadStore,
thread_id: ThreadId,
) -> ThreadStoreResult<u64> {
let db_path = codex_state::thread_history_db_path(store.config.sqlite_home.as_path());
let db_path = store.config.sqlite.thread_history_db_path();
if !tokio::fs::try_exists(db_path.as_path())
.await
.map_err(thread_history_error)?
@@ -140,7 +140,7 @@ pub(super) async fn delete_thread(
store: &LocalThreadStore,
thread_id: ThreadId,
) -> ThreadStoreResult<()> {
let db_path = codex_state::thread_history_db_path(store.config.sqlite_home.as_path());
let db_path = store.config.sqlite.thread_history_db_path();
if !tokio::fs::try_exists(db_path.as_path())
.await
.map_err(thread_history_delete_error)?
@@ -507,7 +507,7 @@ async fn store_with_mode(history_mode: ThreadHistoryMode) -> (TempDir, LocalThre
);
}
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -21,6 +21,7 @@ use codex_protocol::protocol::ThreadMemoryMode;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::protocol::TurnStartedEvent;
use codex_rollout::RolloutRecorder;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
@@ -456,7 +457,7 @@ async fn summary_items_use_final_answers_and_ignore_commentary() {
let config = test_config(home.path());
let thread_id = ThreadId::default();
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -832,7 +833,11 @@ async fn jsonl_failure_does_not_create_projection_database() {
.await
.expect_err("JSONL append should fail");
assert!(!codex_state::thread_history_db_path(home.path()).exists());
assert!(
!codex_state::SqliteConfig::new_for_testing(home.path().abs())
.thread_history_db_path()
.exists()
);
}
#[tokio::test]
@@ -866,7 +871,7 @@ async fn sqlite_failure_does_not_fail_durable_jsonl_write() {
let sqlite_home = home.path().join("not-a-directory");
fs::write(sqlite_home.as_path(), "not a directory").expect("block sqlite home");
let mut config = test_config(home.path());
config.sqlite_home = sqlite_home;
config.sqlite = codex_state::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
let store = LocalThreadStore::new(config, /*state_db*/ None);
let thread_id = ThreadId::default();
create_paginated_thread(&store, thread_id).await;
@@ -1095,7 +1095,7 @@ mod tests {
let path =
write_session_file(home.path(), "2025-01-03T18-30-00", uuid).expect("session file");
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1200,7 +1200,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1243,7 +1243,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1298,7 +1298,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await
@@ -1356,7 +1356,7 @@ mod tests {
let home = TempDir::new().expect("temp dir");
let config = test_config(home.path());
let runtime = codex_state::StateRuntime::init(
config.sqlite_home.clone(),
config.sqlite.home().to_path_buf(),
config.default_model_provider_id.clone(),
)
.await