mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Honor the configured SQLite home across state consumers (#34994)
## Why Codex and SQLite data can use separate home directories, but state consumers could reconstruct database paths from the Codex home instead of consistently using the resolved SQLite configuration. ## What changed - Pass `SqliteConfig` through the core, rollout, state runtime, and thread store instead of passing a directory and rebuilding the configuration downstream. - Use that shared configuration for state, logs, memories, goals, and paginated thread-history database access, including integrity checks and cleanup. - Reject state database handles whose SQLite configuration does not match the requesting store. ## Testing Add coverage with separate Codex and SQLite homes that verifies startup backfill, thread listing, and paginated history all use the configured SQLite directory. GitOrigin-RevId: 1de1cdd1d6ff1d70bbb6c360c8352e6543fb8ebf
This commit is contained in:
1 parent
74e9d7efc4
commit
c769a05340
76 files changed
+1383
-702
No files matched your search
@@ -1,12 +1,11 @@
|
||||
use chrono::Utc;
|
||||
use codex_rollout::find_thread_path_by_id_str;
|
||||
|
||||
use super::LocalThreadStore;
|
||||
use super::helpers::matching_rollout_file_name;
|
||||
use super::helpers::scoped_rollout_path;
|
||||
use crate::ArchiveThreadParams;
|
||||
use crate::ThreadStoreError;
|
||||
use crate::ThreadStoreResult;
|
||||
use chrono::Utc;
|
||||
use codex_rollout::find_thread_path_by_id_str;
|
||||
|
||||
pub(super) async fn archive_thread(
|
||||
store: &LocalThreadStore,
|
||||
@@ -66,6 +65,7 @@ mod tests {
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_rollout::ARCHIVED_SESSIONS_SUBDIR;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
@@ -134,7 +134,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(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -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().to_path_buf(),
|
||||
sqlite: store.config.sqlite.clone(),
|
||||
cwd,
|
||||
model_provider_id: params.metadata.model_provider.clone(),
|
||||
generate_memories: matches!(params.metadata.memory_mode, ThreadMemoryMode::Enabled),
|
||||
|
||||
@@ -223,6 +223,7 @@ mod tests {
|
||||
use codex_protocol::protocol::HistoryPosition;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadMemoryMode;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
@@ -420,9 +421,11 @@ mod tests {
|
||||
ThreadHistoryMode::Paginated,
|
||||
)
|
||||
.expect("session file");
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(
|
||||
&codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
)
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let thread_id_string = thread_id.to_string();
|
||||
sqlx::query(
|
||||
"INSERT INTO thread_turns (thread_id, turn_id, rollout_ordinal, status) VALUES (?, 'turn-1', 1, 'completed')",
|
||||
|
||||
@@ -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().to_path_buf(),
|
||||
sqlite: store.config.sqlite.clone(),
|
||||
cwd: store.config.codex_home.clone(),
|
||||
model_provider_id: store.config.default_model_provider_id.clone(),
|
||||
generate_memories: false,
|
||||
@@ -110,7 +110,7 @@ pub(super) async fn list_rollout_threads(
|
||||
});
|
||||
let page = codex_rollout::state_db::list_threads_db(
|
||||
state_db.as_deref(),
|
||||
config.codex_home.as_path(),
|
||||
&config.sqlite,
|
||||
params.page_size,
|
||||
cursor,
|
||||
sort_key,
|
||||
@@ -202,6 +202,7 @@ mod tests {
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::fs;
|
||||
use tempfile::TempDir;
|
||||
@@ -262,7 +263,7 @@ mod tests {
|
||||
fs::write(&rollout_path, "").expect("placeholder rollout file");
|
||||
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -331,7 +332,7 @@ mod tests {
|
||||
fs::write(&rollout_path, "").expect("placeholder rollout file");
|
||||
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -98,7 +98,7 @@ pub(super) async fn resume_thread(
|
||||
})?;
|
||||
let config = RolloutConfig {
|
||||
codex_home: store.config.codex_home.clone(),
|
||||
sqlite_home: store.config.sqlite.home().to_path_buf(),
|
||||
sqlite: store.config.sqlite.clone(),
|
||||
cwd,
|
||||
model_provider_id: params.metadata.model_provider.clone(),
|
||||
generate_memories: matches!(params.metadata.memory_mode, ThreadMemoryMode::Enabled),
|
||||
|
||||
@@ -24,7 +24,6 @@ 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;
|
||||
@@ -128,17 +127,10 @@ pub struct LocalThreadStoreConfig {
|
||||
}
|
||||
|
||||
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: SqliteConfig::from_sqlite_home(
|
||||
AbsolutePathBuf::from_absolute_path_checked(config.sqlite_home())
|
||||
.expect("sqlite home from resolved config should be absolute"),
|
||||
),
|
||||
sqlite: config.sqlite_config().clone(),
|
||||
default_model_provider_id: config.model_provider_id().to_string(),
|
||||
}
|
||||
}
|
||||
@@ -174,7 +166,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()).await
|
||||
codex_state::open_thread_history_db(&self.config.sqlite).await
|
||||
})
|
||||
.await
|
||||
.map_err(|err| ThreadStoreError::Internal {
|
||||
@@ -517,7 +509,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -552,7 +544,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -587,7 +579,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -655,7 +647,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -744,7 +736,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -780,7 +772,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -820,7 +812,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -864,7 +856,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -919,7 +911,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -612,7 +612,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -771,7 +771,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -816,7 +816,7 @@ mod tests {
|
||||
)
|
||||
.expect("session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
config.sqlite.home().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -859,7 +859,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -900,7 +900,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -934,7 +934,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1070,7 +1070,7 @@ mod tests {
|
||||
writeln!(file, "{meta}").expect("write session meta");
|
||||
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
config.sqlite.home().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1124,7 +1124,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1175,7 +1175,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1274,7 +1274,7 @@ mod tests {
|
||||
.path()
|
||||
.join(format!("rollout-2025-01-03T12-00-00-{uuid}.jsonl"));
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
config.sqlite.home().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1336,7 +1336,7 @@ mod tests {
|
||||
.path()
|
||||
.join(format!("rollout-2025-01-03T12-00-00-{uuid}.jsonl"));
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
config.sqlite.home().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1391,7 +1391,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
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().to_path_buf(),
|
||||
sqlite: store.config.sqlite.clone(),
|
||||
cwd: store.config.codex_home.clone(),
|
||||
model_provider_id: store.config.default_model_provider_id.clone(),
|
||||
generate_memories: false,
|
||||
|
||||
@@ -507,7 +507,7 @@ async fn store_with_mode(history_mode: ThreadHistoryMode) -> (TempDir, LocalThre
|
||||
);
|
||||
}
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
config.sqlite.home().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -20,22 +20,218 @@ use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadMemoryMode;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
use codex_rollout::RolloutConfig;
|
||||
use codex_rollout::RolloutRecorder;
|
||||
use codex_rollout::RolloutRecorderParams;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use super::super::LocalThreadStore;
|
||||
use super::super::LocalThreadStoreConfig;
|
||||
use super::super::test_support::test_config;
|
||||
use crate::AppendThreadItemsParams;
|
||||
use crate::CreateThreadParams;
|
||||
use crate::DeleteThreadParams;
|
||||
use crate::ListThreadsParams;
|
||||
use crate::ListTurnsParams;
|
||||
use crate::ResumeThreadParams;
|
||||
use crate::SortDirection;
|
||||
use crate::StoredTurnItemsView;
|
||||
use crate::StoredTurnStatus;
|
||||
use crate::ThreadPersistenceMetadata;
|
||||
use crate::ThreadSortKey;
|
||||
use crate::ThreadStore;
|
||||
|
||||
/// Separate Codex and SQLite homes must work together across startup backfill,
|
||||
/// thread listing, and projection-backed paginated history reads.
|
||||
#[tokio::test]
|
||||
async fn split_homes_support_backfill_listing_and_paginated_history() {
|
||||
let root = TempDir::new().expect("temp dir");
|
||||
let codex_home = root.path().join("codex");
|
||||
let sqlite_home = root.path().join("sqlite");
|
||||
let thread_id = ThreadId::new();
|
||||
let sqlite = codex_state::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
|
||||
let rollout_config = RolloutConfig {
|
||||
codex_home: codex_home.clone(),
|
||||
sqlite: sqlite.clone(),
|
||||
cwd: codex_home.clone(),
|
||||
model_provider_id: "test-provider".to_string(),
|
||||
generate_memories: false,
|
||||
};
|
||||
let recorder = RolloutRecorder::new(
|
||||
&rollout_config,
|
||||
RolloutRecorderParams::new(
|
||||
thread_id,
|
||||
/*forked_from_id*/ None,
|
||||
/*parent_thread_id*/ None,
|
||||
SessionSource::Exec,
|
||||
/*thread_source*/ None,
|
||||
"test-originator".to_string(),
|
||||
BaseInstructions::default(),
|
||||
Vec::new(),
|
||||
)
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_initial_window_id("window-1".to_string()),
|
||||
)
|
||||
.await
|
||||
.expect("create paginated rollout");
|
||||
recorder
|
||||
.record_canonical_items(&[RolloutItem::EventMsg(EventMsg::UserMessage(
|
||||
UserMessageEvent {
|
||||
message: "existing thread".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
))])
|
||||
.await
|
||||
.expect("record existing user message");
|
||||
recorder.persist().await.expect("persist paginated rollout");
|
||||
let rollout_path = recorder.rollout_path().to_path_buf();
|
||||
recorder.shutdown().await.expect("close paginated rollout");
|
||||
|
||||
let runtime = codex_rollout::state_db::try_init(&rollout_config)
|
||||
.await
|
||||
.expect("backfill state from Codex home");
|
||||
assert!(
|
||||
runtime
|
||||
.get_thread(thread_id)
|
||||
.await
|
||||
.expect("read backfilled thread")
|
||||
.is_some(),
|
||||
"startup backfill should index the rollout"
|
||||
);
|
||||
let store = LocalThreadStore::new(
|
||||
LocalThreadStoreConfig::from_config(&rollout_config),
|
||||
Some(runtime),
|
||||
);
|
||||
|
||||
let threads = store
|
||||
.list_threads(ListThreadsParams {
|
||||
page_size: 10,
|
||||
cursor: None,
|
||||
sort_key: ThreadSortKey::CreatedAt,
|
||||
sort_direction: SortDirection::Desc,
|
||||
allowed_sources: Vec::new(),
|
||||
model_providers: None,
|
||||
cwd_filters: None,
|
||||
archived: false,
|
||||
search_term: None,
|
||||
relation_filter: None,
|
||||
is_pinned: None,
|
||||
use_state_db_only: true,
|
||||
})
|
||||
.await
|
||||
.expect("list backfilled threads");
|
||||
assert_eq!(threads.items.len(), 1);
|
||||
assert_eq!(
|
||||
(
|
||||
threads.items[0].thread_id,
|
||||
threads.items[0].rollout_path.as_deref(),
|
||||
threads.items[0].history_mode,
|
||||
),
|
||||
(
|
||||
thread_id,
|
||||
Some(rollout_path.as_path()),
|
||||
ThreadHistoryMode::Paginated,
|
||||
)
|
||||
);
|
||||
|
||||
store
|
||||
.resume_thread(ResumeThreadParams {
|
||||
thread_id,
|
||||
rollout_path: Some(rollout_path),
|
||||
history: None,
|
||||
include_archived: false,
|
||||
metadata: ThreadPersistenceMetadata {
|
||||
cwd: Some(codex_home.clone()),
|
||||
model_provider: "test-provider".to_string(),
|
||||
memory_mode: ThreadMemoryMode::Enabled,
|
||||
},
|
||||
})
|
||||
.await
|
||||
.expect("resume backfilled thread");
|
||||
store
|
||||
.append_items(AppendThreadItemsParams {
|
||||
thread_id,
|
||||
items: vec![
|
||||
turn_started("turn-1"),
|
||||
completed_item(
|
||||
thread_id,
|
||||
"turn-1",
|
||||
TurnItem::UserMessage(UserMessageItem {
|
||||
id: "user-1".to_string(),
|
||||
client_id: None,
|
||||
content: Vec::new(),
|
||||
}),
|
||||
),
|
||||
completed_item(
|
||||
thread_id,
|
||||
"turn-1",
|
||||
TurnItem::AgentMessage(AgentMessageItem {
|
||||
id: "agent-1".to_string(),
|
||||
content: vec![AgentMessageContent::Text {
|
||||
text: "done".to_string(),
|
||||
}],
|
||||
phase: None,
|
||||
memory_citation: None,
|
||||
}),
|
||||
),
|
||||
turn_completed("turn-1"),
|
||||
],
|
||||
})
|
||||
.await
|
||||
.expect("append paginated history");
|
||||
|
||||
let turns = store
|
||||
.list_turns(ListTurnsParams {
|
||||
thread_id,
|
||||
include_archived: false,
|
||||
cursor: None,
|
||||
page_size: 10,
|
||||
sort_direction: SortDirection::Asc,
|
||||
items_view: StoredTurnItemsView::Summary,
|
||||
})
|
||||
.await
|
||||
.expect("list paginated history");
|
||||
assert_eq!(
|
||||
turns
|
||||
.turns
|
||||
.iter()
|
||||
.map(|turn| {
|
||||
(
|
||||
turn.turn_id.as_str(),
|
||||
turn.status,
|
||||
turn.items
|
||||
.iter()
|
||||
.map(|item| item.item_id.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
vec![(
|
||||
"turn-1",
|
||||
StoredTurnStatus::Completed,
|
||||
vec!["user-1", "agent-1"],
|
||||
)]
|
||||
);
|
||||
|
||||
let state_db_path = sqlite.state_db_path();
|
||||
let thread_history_db_path = sqlite.thread_history_db_path();
|
||||
for sqlite_path in [&state_db_path, &thread_history_db_path] {
|
||||
assert!(
|
||||
sqlite_path.exists(),
|
||||
"expected SQLite database at {}",
|
||||
sqlite_path.display()
|
||||
);
|
||||
let filename = sqlite_path.file_name().expect("SQLite database filename");
|
||||
assert!(
|
||||
!codex_home.join(filename).exists(),
|
||||
"SQLite database should not be created under Codex home"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn paginated_live_append_materializes_turn_items_and_state() {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
@@ -87,9 +283,11 @@ async fn paginated_live_append_materializes_turn_items_and_state() {
|
||||
rollout_line_byte_offsets(rollout_path.as_path(), /*ordinal*/ 1);
|
||||
let (_, turn_end_byte_offset) =
|
||||
rollout_line_byte_offsets(rollout_path.as_path(), /*ordinal*/ 4);
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let turn = sqlx::query_as::<
|
||||
_,
|
||||
(
|
||||
@@ -196,9 +394,11 @@ async fn active_turn_stores_only_its_start_position() {
|
||||
.expect("rollout path");
|
||||
let (turn_start_byte_offset, _) =
|
||||
rollout_line_byte_offsets(rollout_path.as_path(), /*ordinal*/ 1);
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let turn_position = sqlx::query_as::<_, (Option<i64>, Option<i64>, Option<i64>)>(
|
||||
"SELECT rollout_byte_offset, rollout_end_ordinal, rollout_end_byte_offset FROM thread_turns WHERE thread_id = ? AND turn_id = ?",
|
||||
)
|
||||
@@ -263,9 +463,11 @@ async fn subagent_prefix_advances_projection_without_materializing_history() {
|
||||
.expect("rollout path");
|
||||
let (child_start_byte_offset, _) =
|
||||
rollout_line_byte_offsets(rollout_path.as_path(), /*ordinal*/ 4);
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let turns = sqlx::query_as::<_, (String, i64, Option<i64>)>(
|
||||
"SELECT turn_id, rollout_ordinal, rollout_byte_offset FROM thread_turns WHERE thread_id = ?",
|
||||
)
|
||||
@@ -313,9 +515,11 @@ async fn replayed_item_snapshot_updates_content_without_reordering() {
|
||||
})
|
||||
.await
|
||||
.expect("append first item snapshot");
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let first_created_at_ms = sqlx::query_scalar::<_, i64>(
|
||||
"SELECT created_at_ms FROM thread_items WHERE thread_id = ? AND turn_id = ? AND item_id = ?",
|
||||
)
|
||||
@@ -399,9 +603,11 @@ async fn terminal_turn_does_not_change_after_later_records() {
|
||||
.await
|
||||
.expect("append later records");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let rollout_path = store
|
||||
.live_rollout_path(thread_id)
|
||||
.await
|
||||
@@ -457,7 +663,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -582,9 +788,11 @@ async fn next_write_catches_up_unprojected_durable_suffix() {
|
||||
.await
|
||||
.expect("persist session metadata");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let checkpoint = projection_state(&pool, thread_id).await;
|
||||
store
|
||||
.append_items(AppendThreadItemsParams {
|
||||
@@ -667,9 +875,11 @@ async fn synchronized_catch_up_does_not_replay_old_rows() {
|
||||
.await
|
||||
.expect("append turn start");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let before = projection_state(&pool, thread_id).await;
|
||||
sqlx::query("UPDATE thread_turns SET status = 'sentinel' WHERE thread_id = ?")
|
||||
.bind(thread_id.to_string())
|
||||
@@ -705,9 +915,11 @@ async fn catch_up_preserves_trailing_partial_line_boundaries() {
|
||||
.await
|
||||
.expect("persist session metadata");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let before = projection_state(&pool, thread_id).await;
|
||||
let complete_line = rollout_line(Some(1), turn_started("turn-1"));
|
||||
let partial_line = rollout_line(Some(2), turn_completed("turn-1"));
|
||||
@@ -782,9 +994,11 @@ async fn catch_up_rejects_invalid_complete_suffixes_without_advancing_state() {
|
||||
.await
|
||||
.expect("persist session metadata");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(
|
||||
&codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
)
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let before = projection_state(&pool, thread_id).await;
|
||||
let rollout_path = store
|
||||
.live_rollout_path(thread_id)
|
||||
@@ -940,9 +1154,11 @@ async fn blank_and_rejected_rollout_lines_do_not_poison_projection() {
|
||||
.await
|
||||
.expect("project valid retry after rejected line");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let (expected_start_byte_offset, _) =
|
||||
rollout_line_byte_offsets(rollout_path.as_path(), /*ordinal*/ 1);
|
||||
let start_byte_offset = sqlx::query_scalar::<_, Option<i64>>(
|
||||
@@ -980,9 +1196,11 @@ async fn shutdown_materializes_items_queued_without_a_flush() {
|
||||
.await
|
||||
.expect("shutdown live thread");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let projected_turns = sqlx::query_scalar::<_, i64>(
|
||||
"SELECT COUNT(*) FROM thread_turns WHERE thread_id = ? AND turn_id = ?",
|
||||
)
|
||||
@@ -1032,9 +1250,11 @@ async fn delete_waits_for_in_flight_projection_before_removing_rows() {
|
||||
.expect("finish in-flight append");
|
||||
delete.await.expect("join delete").expect("delete thread");
|
||||
|
||||
let pool = codex_state::open_thread_history_db(home.path())
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let pool = codex_state::open_thread_history_db(&codex_state::SqliteConfig::new_for_testing(
|
||||
home.path().abs(),
|
||||
))
|
||||
.await
|
||||
.expect("open thread history db");
|
||||
let counts = sqlx::query_as::<_, (i64, i64, i64)>(
|
||||
r#"
|
||||
SELECT
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use codex_rollout::find_archived_thread_path_by_id_str;
|
||||
use codex_rollout::rollout_date_parts;
|
||||
|
||||
use super::LocalThreadStore;
|
||||
use super::helpers::matching_rollout_file_name;
|
||||
use super::helpers::scoped_rollout_path;
|
||||
@@ -10,6 +7,8 @@ use crate::ReadThreadParams;
|
||||
use crate::StoredThread;
|
||||
use crate::ThreadStoreError;
|
||||
use crate::ThreadStoreResult;
|
||||
use codex_rollout::find_archived_thread_path_by_id_str;
|
||||
use codex_rollout::rollout_date_parts;
|
||||
|
||||
pub(super) async fn unarchive_thread(
|
||||
store: &LocalThreadStore,
|
||||
@@ -94,6 +93,7 @@ mod tests {
|
||||
use chrono::Utc;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
@@ -143,7 +143,7 @@ mod tests {
|
||||
let archived_path = write_archived_session_file(home.path(), "2025-01-03T13-00-00", uuid)
|
||||
.expect("archived session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -842,6 +842,7 @@ mod tests {
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
@@ -900,7 +901,7 @@ mod tests {
|
||||
write_session_file(home.path(), "2025-01-03T14-20-00", uuid).expect("session file");
|
||||
let original_rollout = std::fs::read_to_string(&rollout_path).expect("read rollout");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1009,7 +1010,7 @@ mod tests {
|
||||
.expect("session file");
|
||||
let original_rollout = std::fs::read_to_string(&path).expect("read rollout");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1101,7 +1102,7 @@ mod tests {
|
||||
let path =
|
||||
write_session_file(home.path(), "2025-01-03T14-30-00", uuid).expect("session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1147,7 +1148,7 @@ mod tests {
|
||||
.expect("session file");
|
||||
let original_rollout = std::fs::read_to_string(&path).expect("read rollout");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1244,7 +1245,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1349,7 +1350,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1392,7 +1393,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1447,7 +1448,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1505,7 +1506,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().to_path_buf(),
|
||||
config.sqlite.clone(),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1708,7 +1709,7 @@ mod tests {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1809,7 +1810,7 @@ mod tests {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1852,7 +1853,7 @@ mod tests {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1910,7 +1911,7 @@ mod tests {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1957,7 +1958,7 @@ mod tests {
|
||||
)
|
||||
.expect("session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1997,7 +1998,7 @@ mod tests {
|
||||
write_archived_session_file(home.path(), "2025-01-03T19-30-00", uuid)
|
||||
.expect("archived session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -2033,7 +2034,7 @@ mod tests {
|
||||
let home = TempDir::new().expect("temp dir");
|
||||
let config = test_config(home.path());
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -2103,7 +2104,7 @@ mod tests {
|
||||
let archived_path = write_archived_session_file(home.path(), "2025-01-03T16-00-00", uuid)
|
||||
.expect("archived session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -2166,7 +2167,7 @@ mod tests {
|
||||
let archived_path = write_archived_session_file(home.path(), "2025-01-03T16-30-00", uuid)
|
||||
.expect("archived session file");
|
||||
let runtime = codex_state::StateRuntime::init(
|
||||
home.path().to_path_buf(),
|
||||
codex_state::SqliteConfig::new_for_testing(home.path().abs()),
|
||||
config.default_model_provider_id.clone(),
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in new issue
Block a user