mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
Refine rollout crate extraction
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::error::Result as CodexResult;
|
||||
use crate::session_prefix::format_subagent_context_line;
|
||||
use crate::session_prefix::format_subagent_notification_message;
|
||||
use crate::shell_snapshot::ShellSnapshot;
|
||||
use crate::state_db;
|
||||
use crate::state_runtime;
|
||||
use crate::thread_manager::ThreadManagerState;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::AgentPath;
|
||||
@@ -371,7 +371,7 @@ impl AgentControl {
|
||||
agent_nickname: _,
|
||||
}) => {
|
||||
let (resumed_agent_nickname, resumed_agent_role) =
|
||||
if let Some(state_db_ctx) = state_db::get_state_db(&config).await {
|
||||
if let Some(state_db_ctx) = state_runtime::get_state_db(&config).await {
|
||||
match state_db_ctx.get_thread(thread_id).await {
|
||||
Ok(Some(metadata)) => (metadata.agent_nickname, metadata.agent_role),
|
||||
Ok(None) | Err(_) => (None, None),
|
||||
|
||||
+13
-19
@@ -200,16 +200,6 @@ pub(crate) struct PreviousTurnSettings {
|
||||
pub(crate) realtime_active: Option<bool>,
|
||||
}
|
||||
|
||||
fn rollout_config(config: &Config, cwd: PathBuf) -> RolloutConfig {
|
||||
RolloutConfig::new(
|
||||
config.codex_home.clone(),
|
||||
config.sqlite_home.clone(),
|
||||
cwd,
|
||||
config.model_provider_id.clone(),
|
||||
config.memories.generate_memories,
|
||||
)
|
||||
}
|
||||
|
||||
use crate::exec_policy::ExecPolicyUpdateError;
|
||||
use crate::feedback_tags;
|
||||
use crate::file_watcher::FileWatcher;
|
||||
@@ -279,6 +269,7 @@ use crate::protocol::TokenUsage;
|
||||
use crate::protocol::TokenUsageInfo;
|
||||
use crate::protocol::TurnDiffEvent;
|
||||
use crate::protocol::WarningEvent;
|
||||
use crate::rollout_config_with_cwd;
|
||||
use crate::session_startup_prewarm::SessionStartupPrewarmHandle;
|
||||
use crate::shell;
|
||||
use crate::shell_snapshot::ShellSnapshot;
|
||||
@@ -297,7 +288,7 @@ use crate::skills::resolve_skill_dependencies_for_turn;
|
||||
use crate::state::ActiveTurn;
|
||||
use crate::state::SessionServices;
|
||||
use crate::state::SessionState;
|
||||
use crate::state_db;
|
||||
use crate::state_runtime;
|
||||
use crate::tasks::GhostSnapshotTask;
|
||||
use crate::tasks::ReviewTask;
|
||||
use crate::tasks::SessionTask;
|
||||
@@ -339,7 +330,6 @@ use codex_protocol::protocol::CodexErrorInfo;
|
||||
use codex_protocol::protocol::InitialHistory;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_rollout::EventPersistenceMode;
|
||||
use codex_rollout::RolloutConfig;
|
||||
use codex_rollout::RolloutRecorder;
|
||||
use codex_rollout::RolloutRecorderParams;
|
||||
use codex_rollout::build_thread_metadata_builder;
|
||||
@@ -550,9 +540,13 @@ impl Codex {
|
||||
};
|
||||
match thread_id {
|
||||
Some(thread_id) => {
|
||||
let state_db_ctx = state_db::get_state_db(&config).await;
|
||||
state_db::get_dynamic_tools(state_db_ctx.as_deref(), thread_id, "codex_spawn")
|
||||
.await
|
||||
let state_db_ctx = state_runtime::get_state_db(&config).await;
|
||||
state_runtime::get_dynamic_tools(
|
||||
state_db_ctx.as_deref(),
|
||||
thread_id,
|
||||
"codex_spawn",
|
||||
)
|
||||
.await
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
@@ -738,7 +732,7 @@ impl Codex {
|
||||
state.session_configuration.thread_config_snapshot()
|
||||
}
|
||||
|
||||
pub(crate) fn state_db(&self) -> Option<state_db::StateDbHandle> {
|
||||
pub(crate) fn state_db(&self) -> Option<state_runtime::StateDbHandle> {
|
||||
self.session.state_db()
|
||||
}
|
||||
|
||||
@@ -1473,7 +1467,7 @@ impl Session {
|
||||
),
|
||||
InitialHistory::New | InitialHistory::Forked(_) => None,
|
||||
};
|
||||
let rollout_config = rollout_config(&config, session_configuration.cwd.clone());
|
||||
let rollout_config = rollout_config_with_cwd(&config, session_configuration.cwd.clone());
|
||||
|
||||
// Kick off independent async setup tasks in parallel to reduce startup latency.
|
||||
//
|
||||
@@ -1484,7 +1478,7 @@ impl Session {
|
||||
if config.ephemeral {
|
||||
Ok::<_, anyhow::Error>((None, None))
|
||||
} else {
|
||||
let state_db_ctx = state_db::init(&config).await;
|
||||
let state_db_ctx = state_runtime::init(&config).await;
|
||||
spawn_backfill_if_needed(state_db_ctx.clone(), &rollout_config).await;
|
||||
let rollout_recorder = RolloutRecorder::new(
|
||||
&rollout_config,
|
||||
@@ -2019,7 +2013,7 @@ impl Session {
|
||||
self.tx_event.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn state_db(&self) -> Option<state_db::StateDbHandle> {
|
||||
pub(crate) fn state_db(&self) -> Option<state_runtime::StateDbHandle> {
|
||||
self.services.state_db.clone()
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ use codex_protocol::protocol::RealtimeAudioFrame;
|
||||
use codex_protocol::protocol::Submission;
|
||||
use codex_protocol::protocol::W3cTraceContext;
|
||||
use codex_rollout::EventPersistenceMode;
|
||||
use codex_rollout::RolloutConfig;
|
||||
use codex_rollout::RolloutRecorder;
|
||||
use codex_rollout::RolloutRecorderParams;
|
||||
use core_test_support::tracing::install_test_tracing;
|
||||
@@ -83,17 +82,8 @@ use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||
|
||||
use crate::rollout_config;
|
||||
use codex_protocol::mcp::CallToolResult as McpCallToolResult;
|
||||
|
||||
fn rollout_config(config: &Config) -> RolloutConfig {
|
||||
RolloutConfig::new(
|
||||
config.codex_home.clone(),
|
||||
config.sqlite_home.clone(),
|
||||
config.cwd.clone(),
|
||||
config.model_provider_id.clone(),
|
||||
config.memories.generate_memories,
|
||||
)
|
||||
}
|
||||
use pretty_assertions::assert_eq;
|
||||
use rmcp::model::JsonObject;
|
||||
use rmcp::model::Tool;
|
||||
|
||||
@@ -26,7 +26,7 @@ use std::path::PathBuf;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::sync::watch;
|
||||
|
||||
use crate::state_db::StateDbHandle;
|
||||
use crate::state_runtime::StateDbHandle;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ThreadConfigSnapshot {
|
||||
|
||||
@@ -68,6 +68,7 @@ mod model_provider_info;
|
||||
pub mod path_utils;
|
||||
pub mod personality_migration;
|
||||
pub mod plugins;
|
||||
mod rollout_config_builder;
|
||||
mod sandbox_tags;
|
||||
pub mod sandboxing;
|
||||
mod session_prefix;
|
||||
@@ -128,7 +129,7 @@ pub mod shell_snapshot;
|
||||
pub mod skills;
|
||||
pub mod spawn;
|
||||
mod state;
|
||||
pub mod state_db;
|
||||
pub mod state_runtime;
|
||||
mod tasks;
|
||||
mod tools;
|
||||
pub mod turn_diff_tracker;
|
||||
@@ -157,6 +158,8 @@ pub use exec_policy::check_execpolicy_for_warnings;
|
||||
pub use exec_policy::format_exec_policy_error_with_source;
|
||||
pub use exec_policy::load_exec_policy;
|
||||
pub use file_watcher::FileWatcherEvent;
|
||||
pub use rollout_config_builder::rollout_config;
|
||||
pub use rollout_config_builder::rollout_config_with_cwd;
|
||||
pub use safety::get_platform_sandbox;
|
||||
pub use tools::spec::parse_tool_input_schema;
|
||||
pub use turn_metadata::build_turn_metadata_header;
|
||||
|
||||
@@ -31,7 +31,7 @@ use crate::protocol::EventMsg;
|
||||
use crate::protocol::McpInvocation;
|
||||
use crate::protocol::McpToolCallBeginEvent;
|
||||
use crate::protocol::McpToolCallEndEvent;
|
||||
use crate::state_db;
|
||||
use crate::state_runtime;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::mcp::CallToolResult;
|
||||
use codex_protocol::openai_models::InputModality;
|
||||
@@ -281,7 +281,7 @@ async fn maybe_mark_thread_memory_mode_polluted(sess: &Session, turn_context: &T
|
||||
{
|
||||
return;
|
||||
}
|
||||
state_db::mark_thread_memory_mode_polluted(
|
||||
state_runtime::mark_thread_memory_mode_polluted(
|
||||
sess.services.state_db.as_deref(),
|
||||
sess.conversation_id,
|
||||
"mcp_tool_call",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::config::Config;
|
||||
use codex_rollout::RolloutConfig;
|
||||
|
||||
pub fn rollout_config(config: &Config) -> RolloutConfig {
|
||||
rollout_config_with_cwd(config, config.cwd.clone())
|
||||
}
|
||||
|
||||
pub fn rollout_config_with_cwd(config: &Config, cwd: PathBuf) -> RolloutConfig {
|
||||
RolloutConfig::new(
|
||||
config.codex_home.clone(),
|
||||
config.sqlite_home.clone(),
|
||||
cwd,
|
||||
config.model_provider_id.clone(),
|
||||
config.memories.generate_memories,
|
||||
)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use crate::mcp_connection_manager::McpConnectionManager;
|
||||
use crate::models_manager::manager::ModelsManager;
|
||||
use crate::plugins::PluginsManager;
|
||||
use crate::skills::SkillsManager;
|
||||
use crate::state_db::StateDbHandle;
|
||||
use crate::state_runtime::StateDbHandle;
|
||||
use crate::tools::code_mode::CodeModeService;
|
||||
use crate::tools::network_approval::NetworkApprovalService;
|
||||
use crate::tools::runtimes::ExecveSessionApproval;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
use super::*;
|
||||
use codex_rollout::parse_cursor;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn cursor_to_anchor_normalizes_timestamp_format() {
|
||||
let uuid = Uuid::new_v4();
|
||||
let ts_str = "2026-01-27T12-34-56";
|
||||
let token = format!("{ts_str}|{uuid}");
|
||||
let cursor = parse_cursor(token.as_str()).expect("cursor should parse");
|
||||
let anchor = cursor_to_anchor(Some(&cursor)).expect("anchor should parse");
|
||||
|
||||
let naive =
|
||||
NaiveDateTime::parse_from_str(ts_str, "%Y-%m-%dT%H-%M-%S").expect("ts should parse");
|
||||
let expected_ts = DateTime::<Utc>::from_naive_utc_and_offset(naive, Utc)
|
||||
.with_nanosecond(0)
|
||||
.expect("nanosecond");
|
||||
|
||||
assert_eq!(anchor.id, uuid);
|
||||
assert_eq!(anchor.ts, expected_ts);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ use crate::function_tool::FunctionCallError;
|
||||
use crate::memories::citations::get_thread_id_from_citations;
|
||||
use crate::memories::citations::parse_memory_citation;
|
||||
use crate::parse_turn_item;
|
||||
use crate::state_db;
|
||||
use crate::state_runtime;
|
||||
use crate::tools::parallel::ToolCallRuntime;
|
||||
use crate::tools::router::ToolRouter;
|
||||
use codex_protocol::models::DeveloperInstructions;
|
||||
@@ -146,7 +146,7 @@ async fn maybe_mark_thread_memory_mode_polluted_from_web_search(
|
||||
{
|
||||
return;
|
||||
}
|
||||
state_db::mark_thread_memory_mode_polluted(
|
||||
state_runtime::mark_thread_memory_mode_polluted(
|
||||
sess.services.state_db.as_deref(),
|
||||
sess.conversation_id,
|
||||
"record_completed_response_item",
|
||||
@@ -168,7 +168,7 @@ async fn record_stage1_output_usage_for_completed_item(
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(db) = state_db::get_state_db(turn_context.config.as_ref()).await {
|
||||
if let Some(db) = state_runtime::get_state_db(turn_context.config.as_ref()).await {
|
||||
let _ = db.record_stage1_output_usage(&thread_ids).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ use std::path::PathBuf;
|
||||
|
||||
use chrono::Utc;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_core::rollout_config;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::models::BaseInstructions;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_rollout::EventPersistenceMode;
|
||||
use codex_rollout::RolloutConfig;
|
||||
use codex_rollout::RolloutRecorder;
|
||||
use codex_rollout::RolloutRecorderParams;
|
||||
use codex_rollout::find_archived_thread_path_by_id_str;
|
||||
@@ -51,16 +51,6 @@ fn write_minimal_rollout_with_id_in_subdir(codex_home: &Path, subdir: &str, id:
|
||||
file
|
||||
}
|
||||
|
||||
fn rollout_config(config: &codex_core::config::Config) -> RolloutConfig {
|
||||
RolloutConfig::new(
|
||||
config.codex_home.clone(),
|
||||
config.sqlite_home.clone(),
|
||||
config.cwd.clone(),
|
||||
config.model_provider_id.clone(),
|
||||
config.memories.generate_memories,
|
||||
)
|
||||
}
|
||||
|
||||
/// Create sessions/YYYY/MM/DD and write a minimal rollout file containing the
|
||||
/// provided conversation id in the SessionMeta line. Returns the absolute path.
|
||||
fn write_minimal_rollout_with_id(codex_home: &Path, id: Uuid) -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user