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

+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