Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/agent-graph-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }

[dev-dependencies]
codex-utils-absolute-path = { workspace = true }
pretty_assertions = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }
Expand Down
13 changes: 8 additions & 5 deletions codex-rs/agent-graph-store/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct LocalAgentGraphStore {
impl std::fmt::Debug for LocalAgentGraphStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LocalAgentGraphStore")
.field("codex_home", &self.state_db.codex_home())
.field("sqlite", self.state_db.sqlite())
.finish_non_exhaustive()
}
}
Expand Down Expand Up @@ -126,6 +126,7 @@ fn internal_error(err: impl std::fmt::Display) -> AgentGraphStoreError {
mod tests {
use super::*;
use codex_state::DirectionalThreadSpawnEdgeStatus;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use tempfile::TempDir;

Expand All @@ -141,10 +142,12 @@ mod tests {

async fn state_runtime() -> TestRuntime {
let codex_home = TempDir::new().expect("tempdir should be created");
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string())
.await
.expect("state db should initialize");
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await
.expect("state db should initialize");
TestRuntime {
state_db,
_codex_home: codex_home,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ mod tests {
use crate::transport::remote_control::protocol::normalize_remote_control_url;
use crate::transport::remote_control::server_api::enroll_remote_control_server;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::sync::Arc;
Expand All @@ -445,9 +446,12 @@ mod tests {
use tokio::time::timeout;

async fn remote_control_state_runtime(codex_home: &TempDir) -> Arc<StateRuntime> {
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string())
.await
.expect("state runtime should initialize")
StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await
.expect("state runtime should initialize")
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use codex_login::token_data::parse_chatgpt_jwt_claims;
use codex_protocol::auth::AuthMode;
use codex_state::RemoteControlEnrollmentRecord;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use futures::SinkExt;
use futures::StreamExt;
use gethostname::gethostname;
Expand Down Expand Up @@ -126,9 +127,12 @@ fn remote_control_auth_dot_json(account_id: Option<&str>) -> AuthDotJson {
}

async fn remote_control_state_runtime(codex_home: &TempDir) -> Arc<StateRuntime> {
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string())
.await
.expect("state runtime should initialize")
StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await
.expect("state runtime should initialize")
}

#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,7 @@ mod tests {
use codex_login::token_data::parse_chatgpt_jwt_claims;
use codex_protocol::auth::AuthMode;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use futures::StreamExt;
use pretty_assertions::assert_eq;
use std::sync::Arc;
Expand Down Expand Up @@ -1994,9 +1995,12 @@ mod tests {
}

pub(super) async fn remote_control_state_runtime(codex_home: &TempDir) -> Arc<StateRuntime> {
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string())
.await
.expect("state runtime should initialize")
StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await
.expect("state runtime should initialize")
}

pub(super) fn remote_control_auth_manager() -> Arc<AuthManager> {
Expand Down
14 changes: 3 additions & 11 deletions codex-rs/app-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub async fn run_main_with_transport_options(
Err(err) => {
return Err(std::io::Error::other(format!(
"failed to initialize sqlite state runtime under {}: {err}",
config.sqlite_home.display()
config.sqlite_config().home().display()
)));
}
};
Expand Down Expand Up @@ -1196,16 +1196,8 @@ async fn init_sqlite_state_db_with_fresh_start_on_corruption(
}
Err(err) => err,
};
let database_path =
codex_state::runtime_db_path_for_corruption_error(&err).unwrap_or_else(|| {
codex_state::SqliteConfig::from_sqlite_home(
codex_utils_absolute_path::AbsolutePathBuf::resolve_path_against_base(
config.sqlite_home.clone(),
&config.codex_home,
),
)
.state_db_path()
});
let database_path = codex_state::runtime_db_path_for_corruption_error(&err)
.unwrap_or_else(|| config.sqlite_config().state_db_path());
if !codex_state::is_sqlite_corruption_error(&err)
&& !sqlite_home_is_blocking_file(database_path.as_path())
{
Expand Down
9 changes: 6 additions & 3 deletions codex-rs/app-server/tests/suite/v2/external_agent_config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use codex_utils_absolute_path::test_support::PathExt;
use std::time::Duration;

use anyhow::Result;
Expand Down Expand Up @@ -538,9 +539,11 @@ async fn external_agent_config_import_sends_completion_notification_for_sync_onl
)
.await??;
assert_eq!(completed.import_id, import_id);
let state_db =
codex_state::StateRuntime::init(sqlite_home.path().to_path_buf(), "mock_provider".into())
.await?;
let state_db = codex_state::StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(sqlite_home.path().abs()),
"mock_provider".into(),
)
.await?;
let details_record = state_db
.external_agent_config_import_details_record(&import_id)
.await?
Expand Down
7 changes: 6 additions & 1 deletion codex-rs/app-server/tests/suite/v2/memory_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use codex_protocol::protocol::SessionSource;
use codex_state::Stage1JobClaimOutcome;
use codex_state::StateRuntime;
use codex_state::ThreadMetadataBuilder;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -120,7 +121,11 @@ async fn seed_stage1_output(state_db: &Arc<StateRuntime>, codex_home: &Path) ->
}

async fn init_state_db(codex_home: &Path) -> Result<Arc<StateRuntime>> {
let state_db = StateRuntime::init(codex_home.to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.abs()),
"mock_provider".into(),
)
.await?;
state_db
.mark_backfill_complete(/*last_watermark*/ None)
.await?;
Expand Down
37 changes: 26 additions & 11 deletions codex-rs/app-server/tests/suite/v2/remote_control.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use codex_utils_absolute_path::test_support::PathExt;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::io::ErrorKind;
Expand Down Expand Up @@ -254,8 +255,11 @@ async fn listen_off_honors_persisted_remote_control_enable() -> Result<()> {
"ws://{}/backend-api/wham/remote/control/server",
listener.local_addr()?
);
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await?;
state_db
.upsert_remote_control_enrollment(&RemoteControlEnrollmentRecord {
websocket_url,
Expand Down Expand Up @@ -298,8 +302,11 @@ async fn listen_off_ignores_persisted_enable_when_disabled_by_requirements() ->
"ws://{}/backend-api/wham/remote/control/server",
listener.local_addr()?
);
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await?;
state_db
.upsert_remote_control_enrollment(&RemoteControlEnrollmentRecord {
websocket_url: websocket_url.clone(),
Expand Down Expand Up @@ -348,9 +355,11 @@ async fn listen_off_exits_without_persisted_remote_control_enable() -> Result<()
"ws://{}/backend-api/wham/remote/control/server",
listener.local_addr()?
);
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string())
.await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await?;
state_db
.upsert_remote_control_enrollment(&RemoteControlEnrollmentRecord {
websocket_url,
Expand Down Expand Up @@ -460,8 +469,11 @@ async fn disable_waits_for_in_flight_durable_enable() -> Result<()> {
let codex_home = TempDir::new()?;
let mut backend = BlockingRemoteControlBackend::start(codex_home.path()).await?;
let websocket_url = backend.websocket_url().to_string();
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await?;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
.without_auto_env()
Expand Down Expand Up @@ -494,8 +506,11 @@ async fn rpc_updates_durable_preference_but_ephemeral_does_not() -> Result<()> {
let codex_home = TempDir::new()?;
let mut backend = BlockingRemoteControlBackend::start(codex_home.path()).await?;
let websocket_url = backend.websocket_url().to_string();
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "test-provider".to_string()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"test-provider".to_string(),
)
.await?;

let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
Expand Down
22 changes: 16 additions & 6 deletions codex-rs/app-server/tests/suite/v2/thread_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use codex_core::find_thread_path_by_id_str;
use codex_protocol::ThreadId;
use codex_state::DirectionalThreadSpawnEdgeStatus;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use std::path::Path;
use tempfile::TempDir;
Expand Down Expand Up @@ -186,8 +187,11 @@ async fn thread_archive_archives_spawned_descendants() -> Result<()> {
let parent_thread_id = ThreadId::from_string(&parent_id)?;
let child_thread_id = ThreadId::from_string(&child_id)?;
let grandchild_thread_id = ThreadId::from_string(&grandchild_id)?;
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
state_db
.mark_backfill_complete(/*last_watermark*/ None)
.await?;
Expand Down Expand Up @@ -292,8 +296,11 @@ async fn thread_archive_succeeds_when_descendant_archive_fails() -> Result<()> {
let parent_thread_id = ThreadId::from_string(&parent_id)?;
let child_thread_id = ThreadId::from_string(&child_id)?;
let grandchild_thread_id = ThreadId::from_string(&grandchild_id)?;
let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
state_db
.mark_backfill_complete(/*last_watermark*/ None)
.await?;
Expand Down Expand Up @@ -408,8 +415,11 @@ async fn thread_archive_succeeds_when_spawned_descendant_is_missing() -> Result<
let parent_thread_id = ThreadId::from_string(&parent_id)?;
let missing_child_thread_id = ThreadId::from_string("00000000-0000-0000-0000-000000000901")?;

let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
state_db
.mark_backfill_complete(/*last_watermark*/ None)
.await?;
Expand Down
16 changes: 12 additions & 4 deletions codex-rs/app-server/tests/suite/v2/thread_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use codex_core::find_thread_path_by_id_str;
use codex_protocol::ThreadId;
use codex_protocol::protocol::HistoryPosition;
use codex_state::DirectionalThreadSpawnEdgeStatus;
use codex_state::SqliteConfig;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use pretty_assertions::assert_eq;
use std::path::Path;
use tempfile::TempDir;
Expand All @@ -32,8 +34,11 @@ async fn thread_delete_deletes_spawned_descendants() -> Result<()> {
let grandchild_id =
create_delete_test_rollout(codex_home.path(), /*minute*/ 2, "grandchild")?;

let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
let parent_thread_id = ThreadId::from_string(&parent_id)?;
let child_thread_id = ThreadId::from_string(&child_id)?;
let grandchild_thread_id = ThreadId::from_string(&grandchild_id)?;
Expand Down Expand Up @@ -139,8 +144,11 @@ async fn thread_delete_preflights_external_fork_references_for_spawned_subtrees(
})?;
std::fs::write(external_path.as_path(), format!("{external_meta}\n"))?;

let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
state_db
.upsert_thread_spawn_edge(
parent_thread_id,
Expand Down
8 changes: 6 additions & 2 deletions codex-rs/app-server/tests/suite/v2/thread_fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use codex_rollout::append_rollout_item_to_path;
use codex_rollout::append_thread_name;
use codex_rollout::read_session_meta_line;
use codex_state::StateRuntime;
use codex_utils_absolute_path::test_support::PathExt;
use core_test_support::responses;
use pretty_assertions::assert_eq;
use serde_json::Value;
Expand Down Expand Up @@ -522,8 +523,11 @@ async fn thread_fork_defers_inherited_active_goal_until_next_turn() -> Result<()
}
mcp.clear_message_buffer();

let state_db =
StateRuntime::init(codex_home.path().to_path_buf(), "mock_provider".into()).await?;
let state_db = StateRuntime::init(
codex_state::SqliteConfig::new_for_testing(codex_home.path().abs()),
"mock_provider".into(),
)
.await?;
let source_goal = state_db
.thread_goals()
.replace_thread_goal(
Expand Down
Loading
Loading