mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
Default local threads to paginated history (#47900)
## What changed - Make `LocalThreadStore` default to paginated history while retaining explicit legacy mode. - Explicitly use paginated history for Guardian review sessions and allow in-memory stores to create paginated threads. - Rename full-history resume, fork, and subagent helpers to identify them as legacy APIs, and document the paginated alternatives. - Reject `thread/revert` for ephemeral threads and prevent the TUI from replaying or attaching to ephemeral agent threads. ## Testing Add coverage for preserving the default and explicitly selected history modes and conversation context across restart, and for retaining context after rejected ephemeral reverts. Extend Guardian checkpoint coverage across both history modes and verify that saved reviews use paginated history. GitOrigin-RevId: 870239eb3757018159ee4f230a009c97d38ac5b7
This commit is contained in:
@@ -2123,6 +2123,11 @@ impl ThreadRequestProcessor {
|
||||
let (thread_id, thread) = self.load_thread(&thread_id).await?;
|
||||
ensure_direct_input_allowed(thread.as_ref()).await?;
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
if config_snapshot.ephemeral {
|
||||
return Err(invalid_request(
|
||||
"ephemeral threads do not support thread/revert",
|
||||
));
|
||||
}
|
||||
if !matches!(config_snapshot.history_mode, ThreadHistoryMode::Paginated) {
|
||||
return Err(invalid_request(
|
||||
"thread/revert only supports paginated threads",
|
||||
|
||||
@@ -1452,7 +1452,7 @@ impl TurnRequestProcessor {
|
||||
parent_thread: Arc<CodexThread>,
|
||||
prompt: &str,
|
||||
) -> std::result::Result<(), JSONRPCErrorError> {
|
||||
// AgentRunner::start still delegates to spawn_subagent, which forks from the parent's
|
||||
// AgentRunner::start still delegates to spawn_legacy_subagent, which forks from the parent's
|
||||
// full history. Paginated threads only allow bounded model-context reads, so keep this
|
||||
// closed until detached review has a bounded fork path.
|
||||
if matches!(
|
||||
|
||||
@@ -348,7 +348,12 @@ async fn managed_reviewers_reuse_fork_and_resume_after_parent_shutdown(
|
||||
metadata.preview.as_deref(),
|
||||
metadata.first_user_message.as_deref(),
|
||||
),
|
||||
("Guardian review", None, Some("Approval review"), None),
|
||||
(
|
||||
"Guardian review",
|
||||
Some("Guardian review"),
|
||||
Some("Approval review"),
|
||||
None
|
||||
),
|
||||
);
|
||||
// Saved reviewers remain discoverable through the existing subagent filters.
|
||||
for kind in [ThreadSourceKind::SubAgent, ThreadSourceKind::SubAgentOther] {
|
||||
|
||||
@@ -1810,7 +1810,7 @@ async fn guardian_v2_routes_scoped_tool_approvals(
|
||||
(
|
||||
r#"{"subagent":{"other":"guardian"}}"#,
|
||||
"Guardian review",
|
||||
None,
|
||||
Some("Guardian review"),
|
||||
Some("Approval review"),
|
||||
None
|
||||
),
|
||||
|
||||
@@ -51,6 +51,91 @@ use tokio::time::timeout;
|
||||
|
||||
const DEFAULT_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
||||
|
||||
#[test_case::test_case(None; "default_paginated")]
|
||||
#[test_case::test_case(Some(ThreadHistoryMode::Legacy); "explicit_legacy")]
|
||||
#[tokio::test]
|
||||
async fn thread_revert_rejects_ephemeral_without_losing_context(
|
||||
history_mode: Option<ThreadHistoryMode>,
|
||||
) -> Result<()> {
|
||||
let server = create_mock_responses_server_repeating_assistant("Remembered answer").await;
|
||||
let codex_home = TempDir::new()?;
|
||||
MockResponsesConfig::new(&server.uri()).write(codex_home.path())?;
|
||||
let mut mcp = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.build()
|
||||
.await?;
|
||||
initialize_experimental(&mut mcp).await?;
|
||||
let ThreadStartResponse { thread, .. } = mcp
|
||||
.start_thread(ThreadStartParams {
|
||||
ephemeral: Some(true),
|
||||
history_mode,
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
let completed = mcp
|
||||
.start_turn_and_wait_for_completion(TurnStartParams {
|
||||
thread_id: thread.id.clone(),
|
||||
input: vec![UserInput::Text {
|
||||
text: "Remember this task".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
let request_id = mcp
|
||||
.send_request(
|
||||
"thread/revert",
|
||||
Some(serde_json::to_value(ThreadRevertParams {
|
||||
thread_id: thread.id.clone(),
|
||||
before_turn_id: completed.turn.id,
|
||||
})?),
|
||||
)
|
||||
.await?;
|
||||
let error = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_error_message(RequestId::Integer(request_id)),
|
||||
)
|
||||
.await??;
|
||||
assert_eq!(
|
||||
error.error,
|
||||
codex_app_server_protocol::JSONRPCErrorError {
|
||||
code: -32600,
|
||||
message: "ephemeral threads do not support thread/revert".to_string(),
|
||||
data: None,
|
||||
}
|
||||
);
|
||||
mcp.start_turn_and_wait_for_completion(TurnStartParams {
|
||||
thread_id: thread.id,
|
||||
input: vec![UserInput::Text {
|
||||
text: "Continue".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
let requests = server.received_requests().await.expect("response requests");
|
||||
let followup = requests
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|request| request.url.path().ends_with("/responses"))
|
||||
.expect("followup request")
|
||||
.body_json::<Value>()?;
|
||||
let input = followup["input"].as_array().expect("model input");
|
||||
for (role, text) in [
|
||||
("user", "Remember this task"),
|
||||
("assistant", "Remembered answer"),
|
||||
] {
|
||||
assert!(
|
||||
input.iter().any(|item| item["role"] == role
|
||||
&& item["content"]
|
||||
.as_array()
|
||||
.is_some_and(|content| content.iter().any(|part| part["text"] == text))),
|
||||
"missing prior {role} message from followup: {followup}"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(false; "live_reload")]
|
||||
#[test_case::test_case(true; "cold_resume")]
|
||||
#[tokio::test]
|
||||
|
||||
@@ -1126,7 +1126,7 @@ async fn thread_start_ephemeral_remains_pathless() -> Result<()> {
|
||||
thread.ephemeral,
|
||||
"ephemeral threads should be marked explicitly"
|
||||
);
|
||||
assert_eq!(thread.history_mode, ThreadHistoryMode::Legacy);
|
||||
assert_eq!(thread.history_mode, ThreadHistoryMode::Paginated);
|
||||
assert_eq!(
|
||||
thread.path, None,
|
||||
"ephemeral threads should not expose a path"
|
||||
|
||||
@@ -319,29 +319,13 @@ async fn persisted_originator(thread: &CodexThread) -> String {
|
||||
.expect("thread rollout should flush");
|
||||
let stored_thread = thread
|
||||
.read_thread(
|
||||
/*include_archived*/ true, /*include_history*/ true,
|
||||
/*include_archived*/ true, /*include_history*/ false,
|
||||
)
|
||||
.await
|
||||
.expect("thread should be readable");
|
||||
let history = stored_thread.history.expect("history should be loaded");
|
||||
history
|
||||
.items
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::SessionMeta(meta_line) => Some(meta_line.meta.originator.clone()),
|
||||
RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. }
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::WorldState(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::TurnContext(_) => None,
|
||||
})
|
||||
.expect("session metadata should be persisted")
|
||||
stored_thread
|
||||
.originator
|
||||
.expect("originator should be persisted")
|
||||
}
|
||||
|
||||
fn has_subagent_notification<'a>(
|
||||
@@ -1307,6 +1291,7 @@ async fn cold_resume_with_thread_instructions_preserves_lazy_v2_child_inheritanc
|
||||
let parent = harness
|
||||
.manager
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
thread_instructions_provider: Some(Arc::new(TestThreadInstructionsProvider {
|
||||
text: "initial thread instructions".into(),
|
||||
shared,
|
||||
@@ -2189,7 +2174,10 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
Some("Child subagent guidance.".to_string());
|
||||
let new_thread = harness
|
||||
.manager
|
||||
.start_thread(StartThreadOptions::new(parent_config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(parent_config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start parent thread");
|
||||
let parent_thread_id = new_thread.thread_id;
|
||||
@@ -3167,7 +3155,16 @@ async fn resume_and_cold_fork_restore_mcp_attribution_in_constructed_requests(
|
||||
record_invalid_source: bool,
|
||||
) {
|
||||
let harness = AgentControlHarness::new().await;
|
||||
let (source_thread_id, source_thread) = harness.start_thread().await;
|
||||
let source = harness
|
||||
.manager
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(harness.config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start legacy source");
|
||||
let source_thread_id = source.thread_id;
|
||||
let source_thread = source.thread;
|
||||
let turn_context = source_thread.session.new_default_turn().await;
|
||||
source_thread
|
||||
.session
|
||||
@@ -3228,7 +3225,7 @@ async fn resume_and_cold_fork_restore_mcp_attribution_in_constructed_requests(
|
||||
|
||||
let forked = harness
|
||||
.manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
StartThreadOptions::new(harness.config.clone()),
|
||||
rollout_path.clone(),
|
||||
@@ -3237,7 +3234,7 @@ async fn resume_and_cold_fork_restore_mcp_attribution_in_constructed_requests(
|
||||
.expect("fork unloaded source thread");
|
||||
let resumed = harness
|
||||
.manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
harness.config.clone(),
|
||||
rollout_path,
|
||||
AuthManager::from_auth_for_testing(CodexAuth::from_api_key("dummy")),
|
||||
|
||||
@@ -99,6 +99,7 @@ impl PreparedGuardianContext {
|
||||
.model_client
|
||||
.responses_websocket_enabled();
|
||||
let options = crate::StartThreadOptions {
|
||||
history_mode: Some(codex_protocol::protocol::ThreadHistoryMode::Paginated),
|
||||
internal_parent: Some(crate::thread_manager::InternalSessionParent {
|
||||
thread_id: self.parent.thread_id(),
|
||||
auth_manager: Arc::clone(&self.parent.services.auth_manager),
|
||||
|
||||
@@ -5,15 +5,21 @@ use crate::session::tests::make_session_and_context;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::TokenUsage;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use test_case::test_case;
|
||||
|
||||
#[test_case(GuardianContextMode::Legacy; "legacy")]
|
||||
#[test_case(GuardianContextMode::ThreadOwned; "thread_owned")]
|
||||
#[test_case(GuardianContextMode::Legacy, ThreadHistoryMode::Legacy; "legacy_context_legacy_storage")]
|
||||
#[test_case(GuardianContextMode::ThreadOwned, ThreadHistoryMode::Legacy; "thread_owned_context_legacy_storage")]
|
||||
#[test_case(GuardianContextMode::Legacy, ThreadHistoryMode::Paginated; "legacy_context_paginated_storage")]
|
||||
#[test_case(GuardianContextMode::ThreadOwned, ThreadHistoryMode::Paginated; "thread_owned_context_paginated_storage")]
|
||||
#[tokio::test]
|
||||
async fn guardian_checkpoint_preserves_live_context_without_storage(mode: GuardianContextMode) {
|
||||
async fn guardian_checkpoint_preserves_live_context_without_storage(
|
||||
mode: GuardianContextMode,
|
||||
history_mode: ThreadHistoryMode,
|
||||
) {
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
// This session has no live store. A checkpoint must still capture the complete context.
|
||||
assert!(session.live_thread().is_none());
|
||||
@@ -93,6 +99,7 @@ async fn guardian_checkpoint_preserves_live_context_without_storage(mode: Guardi
|
||||
.await;
|
||||
// Replay into a fresh session so preserved live state cannot mask missing checkpoint data.
|
||||
let (fork, _) = make_session_and_context().await;
|
||||
fork.state.lock().await.session_configuration.history_mode = history_mode;
|
||||
fork.state.lock().await.history = ContextManager::for_session(&SessionSource::default());
|
||||
fork.record_initial_history(InitialHistory::Forked(items))
|
||||
.await;
|
||||
|
||||
@@ -3908,7 +3908,7 @@ async fn fork_startup_context_then_first_turn_diff_snapshot() -> anyhow::Result<
|
||||
codex_config::Constrained::allow_any(AskForApproval::UnlessTrusted);
|
||||
let forked = initial
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
usize::MAX,
|
||||
core_test_support::test_codex::StartThreadOptions::new(fork_config.clone()),
|
||||
rollout_path,
|
||||
|
||||
@@ -169,7 +169,7 @@ pub async fn start_thread_with_user_shell_override(
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn resume_thread_from_rollout_with_user_shell_override(
|
||||
pub async fn resume_legacy_thread_from_rollout_with_user_shell_override(
|
||||
thread_manager: &ThreadManager,
|
||||
config: Config,
|
||||
rollout_path: PathBuf,
|
||||
@@ -178,7 +178,7 @@ pub async fn resume_thread_from_rollout_with_user_shell_override(
|
||||
supports_openai_form_elicitation: bool,
|
||||
) -> codex_protocol::error::Result<crate::NewThread> {
|
||||
thread_manager
|
||||
.resume_thread_from_rollout_with_user_shell_override_for_tests(
|
||||
.resume_legacy_thread_from_rollout_with_user_shell_override_for_tests(
|
||||
config,
|
||||
rollout_path,
|
||||
auth_manager,
|
||||
|
||||
@@ -212,7 +212,7 @@ struct ForkHistory {
|
||||
persistence: ForkPersistence,
|
||||
}
|
||||
|
||||
/// Preserve legacy `fork_thread(usize, ...)` callsites by mapping them to the
|
||||
/// Preserve legacy `fork_legacy_thread(usize, ...)` callsites by mapping them to the
|
||||
/// existing truncate-before-nth-user-message snapshot mode.
|
||||
impl From<usize> for ForkSnapshot {
|
||||
fn from(value: usize) -> Self {
|
||||
@@ -1155,8 +1155,11 @@ impl ThreadManager {
|
||||
}
|
||||
|
||||
// TODO(jif) merge with fork_agent
|
||||
/// Spawn a subagent by forking persisted history from `forked_from_thread_id`.
|
||||
pub async fn spawn_subagent(
|
||||
/// Spawn a subagent from a legacy thread's full persisted history.
|
||||
///
|
||||
/// Paginated sources are rejected. For paginated thread forks, use
|
||||
/// [`ThreadStore::prepare_fork`] and [`Self::fork_prepared_thread`].
|
||||
pub async fn spawn_legacy_subagent(
|
||||
&self,
|
||||
forked_from_thread_id: ThreadId,
|
||||
mut options: StartThreadOptions,
|
||||
@@ -1191,7 +1194,12 @@ impl ThreadManager {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn resume_thread_from_rollout(
|
||||
/// Resume a legacy thread by reading its full rollout history.
|
||||
///
|
||||
/// Paginated sources are rejected. Load their context with
|
||||
/// [`ThreadStore::load_latest_model_context`] and pass it to
|
||||
/// [`Self::resume_thread_with_history`] instead.
|
||||
pub async fn resume_legacy_thread_from_rollout(
|
||||
&self,
|
||||
config: Config,
|
||||
rollout_path: PathBuf,
|
||||
@@ -1199,7 +1207,9 @@ impl ThreadManager {
|
||||
parent_trace: Option<W3cTraceContext>,
|
||||
client_mcp_extensions: ClientMcpExtensions,
|
||||
) -> CodexResult<NewThread> {
|
||||
let initial_history = self.initial_history_from_rollout_path(rollout_path).await?;
|
||||
let initial_history = self
|
||||
.legacy_initial_history_from_rollout_path(rollout_path)
|
||||
.await?;
|
||||
Box::pin(self.resume_thread_with_history(
|
||||
config,
|
||||
initial_history,
|
||||
@@ -1290,7 +1300,7 @@ impl ThreadManager {
|
||||
Box::pin(self.state.spawn_thread(request)).await
|
||||
}
|
||||
|
||||
pub(crate) async fn resume_thread_from_rollout_with_user_shell_override_for_tests(
|
||||
pub(crate) async fn resume_legacy_thread_from_rollout_with_user_shell_override_for_tests(
|
||||
&self,
|
||||
config: Config,
|
||||
rollout_path: PathBuf,
|
||||
@@ -1299,7 +1309,9 @@ impl ThreadManager {
|
||||
client_mcp_extensions: ClientMcpExtensions,
|
||||
) -> CodexResult<NewThread> {
|
||||
let agent_control = self.agent_control_for_config(&config);
|
||||
let initial_history = self.initial_history_from_rollout_path(rollout_path).await?;
|
||||
let initial_history = self
|
||||
.legacy_initial_history_from_rollout_path(rollout_path)
|
||||
.await?;
|
||||
let (session_source, thread_source) = initial_history
|
||||
.get_resumed_session_sources()
|
||||
.unwrap_or_else(|| (self.state.session_source.clone(), None));
|
||||
@@ -1411,12 +1423,15 @@ impl ThreadManager {
|
||||
report
|
||||
}
|
||||
|
||||
/// Fork an existing thread by snapshotting rollout history according to
|
||||
/// Fork a legacy thread by snapshotting its full rollout history according to
|
||||
/// `snapshot` and starting a new thread with identical configuration
|
||||
/// (unless overridden by the caller's options). The new thread has a fresh id.
|
||||
/// Fork history replaces `options.initial_history`; hosts can supply the new
|
||||
/// task's instruction provider through the same options as thread creation.
|
||||
pub async fn fork_thread<S>(
|
||||
///
|
||||
/// Paginated sources are rejected. Use [`ThreadStore::prepare_fork`] and
|
||||
/// [`Self::fork_prepared_thread`] for paginated thread forks.
|
||||
pub async fn fork_legacy_thread<S>(
|
||||
&self,
|
||||
snapshot: S,
|
||||
options: StartThreadOptions,
|
||||
@@ -1426,12 +1441,12 @@ impl ThreadManager {
|
||||
S: Into<ForkSnapshot>,
|
||||
{
|
||||
let snapshot = snapshot.into();
|
||||
let history = self.initial_history_from_rollout_path(path).await?;
|
||||
let history = self.legacy_initial_history_from_rollout_path(path).await?;
|
||||
self.fork_thread_from_history(snapshot, options, history)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn initial_history_from_rollout_path(
|
||||
async fn legacy_initial_history_from_rollout_path(
|
||||
&self,
|
||||
rollout_path: PathBuf,
|
||||
) -> CodexResult<InitialHistory> {
|
||||
|
||||
@@ -371,7 +371,10 @@ async fn thread_id_generator_applies_to_roots_children_and_forks() {
|
||||
)
|
||||
.with_thread_id_generator(move || generated_ids[next_id.fetch_add(1, Ordering::Relaxed)]);
|
||||
let root = manager
|
||||
.start_thread(StartThreadOptions::new(config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start root thread");
|
||||
let child = root
|
||||
@@ -401,7 +404,7 @@ async fn thread_id_generator_applies_to_roots_children_and_forks() {
|
||||
.await
|
||||
.expect("spawn actual child agent");
|
||||
let fork = manager
|
||||
.spawn_subagent(root.thread_id, StartThreadOptions::new(config))
|
||||
.spawn_legacy_subagent(root.thread_id, StartThreadOptions::new(config))
|
||||
.await
|
||||
.expect("fork root thread");
|
||||
|
||||
@@ -435,7 +438,10 @@ async fn thread_id_generator_does_not_replace_resumed_thread_id() {
|
||||
)
|
||||
.with_thread_id_generator(move || original_thread_id);
|
||||
let original = original_manager
|
||||
.start_thread(StartThreadOptions::new(config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start source thread");
|
||||
original.thread.ensure_rollout_materialized().await;
|
||||
@@ -464,7 +470,7 @@ async fn thread_id_generator_does_not_replace_resumed_thread_id() {
|
||||
)
|
||||
.with_thread_id_generator(|| panic!("resuming must not allocate a new thread ID"));
|
||||
let resumed = resumed_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config,
|
||||
rollout_path,
|
||||
Arc::clone(&resumed_manager.state.auth_manager),
|
||||
@@ -778,7 +784,8 @@ fn fork_thread_accepts_legacy_usize_snapshot_argument() {
|
||||
config: Config,
|
||||
path: std::path::PathBuf,
|
||||
) {
|
||||
let _future = manager.fork_thread(usize::MAX, crate::StartThreadOptions::new(config), path);
|
||||
let _future =
|
||||
manager.fork_legacy_thread(usize::MAX, crate::StartThreadOptions::new(config), path);
|
||||
}
|
||||
|
||||
let _: fn(&ThreadManager, Config, std::path::PathBuf) = assert_legacy_snapshot_callsite;
|
||||
@@ -1938,6 +1945,7 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
|
||||
source_config.cwd = selected_cwd.clone();
|
||||
let source = manager
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
environments: Some(environments.clone()),
|
||||
..StartThreadOptions::new(source_config)
|
||||
})
|
||||
@@ -1961,7 +1969,7 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
|
||||
let _ = manager.remove_thread(&source.thread_id).await;
|
||||
|
||||
let resumed = manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config.clone(),
|
||||
rollout_path.clone(),
|
||||
auth_manager,
|
||||
@@ -2006,7 +2014,7 @@ async fn resume_and_fork_do_not_restore_thread_environments_from_rollout() {
|
||||
);
|
||||
|
||||
let forked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config),
|
||||
rollout_path,
|
||||
@@ -2122,7 +2130,10 @@ async fn resume_active_thread_from_rollout_returns_running_thread() {
|
||||
);
|
||||
|
||||
let source = manager
|
||||
.start_thread(StartThreadOptions::new(config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start source thread");
|
||||
source.thread.ensure_rollout_materialized().await;
|
||||
@@ -2137,7 +2148,7 @@ async fn resume_active_thread_from_rollout_returns_running_thread() {
|
||||
.expect("source rollout path should exist");
|
||||
|
||||
let resumed = manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config,
|
||||
rollout_path,
|
||||
auth_manager,
|
||||
@@ -2185,7 +2196,10 @@ async fn resume_stopped_thread_from_rollout_spawns_new_thread() {
|
||||
);
|
||||
|
||||
let source = manager
|
||||
.start_thread(StartThreadOptions::new(config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("start source thread");
|
||||
source.thread.ensure_rollout_materialized().await;
|
||||
@@ -2205,7 +2219,7 @@ async fn resume_stopped_thread_from_rollout_spawns_new_thread() {
|
||||
.expect("shutdown source thread");
|
||||
|
||||
let resumed = manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config,
|
||||
rollout_path,
|
||||
auth_manager,
|
||||
@@ -2256,6 +2270,7 @@ async fn resume_stopped_thread_from_rollout_preserves_thread_source() {
|
||||
|
||||
let source = manager
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
thread_source: Some(ThreadSource::User),
|
||||
environments: Some(Vec::new()),
|
||||
..StartThreadOptions::new(config.clone())
|
||||
@@ -2280,7 +2295,7 @@ async fn resume_stopped_thread_from_rollout_preserves_thread_source() {
|
||||
let _ = manager.remove_thread(&source.thread_id).await;
|
||||
|
||||
let resumed = manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config,
|
||||
rollout_path,
|
||||
auth_manager,
|
||||
@@ -2425,7 +2440,7 @@ async fn rollout_path_resume_and_fork_read_history_through_thread_store() {
|
||||
let _ = manager.remove_thread(&resumed.thread_id).await;
|
||||
|
||||
let resumed_from_path = manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
config.clone(),
|
||||
rollout_path.clone(),
|
||||
auth_manager,
|
||||
@@ -2437,7 +2452,7 @@ async fn rollout_path_resume_and_fork_read_history_through_thread_store() {
|
||||
assert_eq!(resumed_from_path.thread_id, resumed.thread_id);
|
||||
|
||||
let forked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config),
|
||||
rollout_path,
|
||||
@@ -2934,16 +2949,14 @@ async fn interrupted_fork_snapshot_does_not_synthesize_turn_id_for_legacy_histor
|
||||
);
|
||||
|
||||
let source = manager
|
||||
.resume_thread_with_history(
|
||||
config.clone(),
|
||||
InitialHistory::Forked(vec![
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
initial_history: InitialHistory::Forked(vec![
|
||||
RolloutItem::ResponseItem(user_msg("hello").into()),
|
||||
RolloutItem::ResponseItem(assistant_msg("partial").into()),
|
||||
]),
|
||||
auth_manager,
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("create source thread from completed history");
|
||||
let source_path = source
|
||||
@@ -2959,7 +2972,7 @@ async fn interrupted_fork_snapshot_does_not_synthesize_turn_id_for_legacy_histor
|
||||
assert_eq!(expected_turn_id, None);
|
||||
|
||||
let forked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config.clone()),
|
||||
source_path,
|
||||
@@ -3046,9 +3059,9 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
|
||||
);
|
||||
|
||||
let source = manager
|
||||
.resume_thread_with_history(
|
||||
config.clone(),
|
||||
InitialHistory::Forked(vec![
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
initial_history: InitialHistory::Forked(vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-explicit".to_string(),
|
||||
root_turn_id: None,
|
||||
@@ -3060,10 +3073,8 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
|
||||
RolloutItem::ResponseItem(user_msg("hello").into()),
|
||||
RolloutItem::ResponseItem(assistant_msg("partial").into()),
|
||||
]),
|
||||
auth_manager,
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("create source thread from explicit partial history");
|
||||
let source_path = source
|
||||
@@ -3085,7 +3096,7 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
|
||||
);
|
||||
|
||||
let forked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config.clone()),
|
||||
source_path,
|
||||
@@ -3149,16 +3160,14 @@ async fn interrupted_fork_snapshot_uses_persisted_mid_turn_history_without_live_
|
||||
);
|
||||
|
||||
let source = manager
|
||||
.resume_thread_with_history(
|
||||
config.clone(),
|
||||
InitialHistory::Forked(vec![
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
initial_history: InitialHistory::Forked(vec![
|
||||
RolloutItem::ResponseItem(user_msg("hello").into()),
|
||||
RolloutItem::ResponseItem(assistant_msg("partial").into()),
|
||||
]),
|
||||
auth_manager,
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
..StartThreadOptions::new(config.clone())
|
||||
})
|
||||
.await
|
||||
.expect("create source thread from partial history");
|
||||
let source_path = source
|
||||
@@ -3172,7 +3181,7 @@ async fn interrupted_fork_snapshot_uses_persisted_mid_turn_history_without_live_
|
||||
manager.remove_thread(&source.thread_id).await;
|
||||
|
||||
let forked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config.clone()),
|
||||
source_path,
|
||||
@@ -3211,7 +3220,7 @@ async fn interrupted_fork_snapshot_uses_persisted_mid_turn_history_without_live_
|
||||
|
||||
manager.remove_thread(&forked.thread_id).await;
|
||||
let reforked = manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
crate::StartThreadOptions::new(config.clone()),
|
||||
forked_path,
|
||||
|
||||
@@ -458,8 +458,8 @@ impl TestCodexBuilder {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_history_mode(mut self, history_mode: ThreadHistoryMode) -> Self {
|
||||
self.history_mode = Some(history_mode);
|
||||
pub fn with_history_mode(mut self, history_mode: impl Into<Option<ThreadHistoryMode>>) -> Self {
|
||||
self.history_mode = history_mode.into();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -855,7 +855,7 @@ impl TestCodexBuilder {
|
||||
(Some(path), Some(user_shell_override)) => {
|
||||
let auth_manager = self.auth.manager_for_home(config.codex_home.as_path());
|
||||
Box::pin(
|
||||
codex_core::test_support::resume_thread_from_rollout_with_user_shell_override(
|
||||
codex_core::test_support::resume_legacy_thread_from_rollout_with_user_shell_override(
|
||||
thread_manager.as_ref(),
|
||||
config.clone(),
|
||||
path,
|
||||
@@ -868,7 +868,7 @@ impl TestCodexBuilder {
|
||||
}
|
||||
(Some(path), None) => {
|
||||
let auth_manager = self.auth.manager_for_home(config.codex_home.as_path());
|
||||
Box::pin(thread_manager.resume_thread_from_rollout(
|
||||
Box::pin(thread_manager.resume_legacy_thread_from_rollout(
|
||||
config.clone(),
|
||||
path,
|
||||
auth_manager,
|
||||
@@ -1481,7 +1481,8 @@ pub fn test_codex() -> TestCodexBuilder {
|
||||
supports_openai_form_elicitation: false,
|
||||
external_time_provider: None,
|
||||
code_mode_host_program: None,
|
||||
history_mode: None,
|
||||
// These fixtures exercise legacy-only resume/fork helpers; store-default tests opt out.
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
models_manager: None,
|
||||
thread_store: None,
|
||||
image_store: codex_core::passthrough_image_store(),
|
||||
|
||||
@@ -263,9 +263,12 @@ async fn host_threads_preserve_lineage_settings_and_resume_routing() -> anyhow::
|
||||
assert_eq!(controller.service_tier(), Some("priority".to_string()));
|
||||
child.thread.ensure_rollout_materialized().await;
|
||||
child.thread.flush_rollout().await?;
|
||||
let saved = child
|
||||
.thread
|
||||
.load_history(/*include_archived*/ false)
|
||||
let saved = test
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id: child.thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
assert!(saved.items.iter().any(|item| matches!(item,
|
||||
RolloutItem::SessionMeta(meta) if meta.meta.parent_thread_id == Some(root_id)
|
||||
|
||||
@@ -249,7 +249,13 @@ async fn child_turn_start_preserves_root_attribution() -> Result<()> {
|
||||
wait_for_event(&thread, |event| matches!(event, EventMsg::TurnComplete(_))).await;
|
||||
}
|
||||
thread.flush_rollout().await?;
|
||||
let history = thread.load_history(/*include_archived*/ false).await?;
|
||||
let history = test
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
for item in history.items {
|
||||
if let codex_history::RolloutItem::EventMsg(EventMsg::TurnStarted(event)) = item {
|
||||
starts.push((thread_id, event));
|
||||
|
||||
@@ -266,12 +266,13 @@ pub(super) async fn submit_thread_turn(
|
||||
|
||||
pub(super) async fn persisted_resume_history(
|
||||
thread: &Arc<codex_core::CodexThread>,
|
||||
store: &dyn codex_thread_store::ThreadStore,
|
||||
) -> Result<(ThreadId, InitialHistory)> {
|
||||
thread.ensure_rollout_materialized().await;
|
||||
thread.flush_rollout().await?;
|
||||
let stored = thread
|
||||
.read_thread(
|
||||
/*include_archived*/ true, /*include_history*/ true,
|
||||
/*include_archived*/ true, /*include_history*/ false,
|
||||
)
|
||||
.await?;
|
||||
let thread_id = stored.thread_id;
|
||||
@@ -280,9 +281,12 @@ pub(super) async fn persisted_resume_history(
|
||||
InitialHistory::Resumed(ResumedHistory {
|
||||
conversation_id: thread_id,
|
||||
history: Arc::new(
|
||||
stored
|
||||
.history
|
||||
.ok_or_else(|| anyhow!("thread history should be loaded"))?
|
||||
store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: true,
|
||||
})
|
||||
.await?
|
||||
.items,
|
||||
),
|
||||
rollout_path: stored.rollout_path,
|
||||
@@ -1564,7 +1568,7 @@ async fn fork_preserves_thread_instructions(
|
||||
let fork = match source {
|
||||
InstructionForkSource::LiveRollout => {
|
||||
test.thread_manager
|
||||
.fork_thread(ForkSnapshot::Interrupted, options, rollout_path)
|
||||
.fork_legacy_thread(ForkSnapshot::Interrupted, options, rollout_path)
|
||||
.await?
|
||||
}
|
||||
InstructionForkSource::OfflineHistory => {
|
||||
@@ -1654,7 +1658,8 @@ async fn thread_provider_lives_with_its_session_across_resume() -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(provider.load_count(), 1);
|
||||
let (_, history) = persisted_resume_history(&started.thread).await?;
|
||||
let (_, history) =
|
||||
persisted_resume_history(&started.thread, test.thread_store.as_ref()).await?;
|
||||
let cold_provider = Arc::new(RecordingThreadInstructionsProvider::with_text(
|
||||
"cold session instructions",
|
||||
));
|
||||
@@ -1688,7 +1693,8 @@ async fn thread_provider_lives_with_its_session_across_resume() -> Result<()> {
|
||||
submit_thread_turn(&started.thread, "load instructions added after creation").await?;
|
||||
assert_eq!(provider.load_count(), 2);
|
||||
assert_eq!(same_provider.load_count(), 0);
|
||||
let (_, history) = persisted_resume_history(&started.thread).await?;
|
||||
let (_, history) =
|
||||
persisted_resume_history(&started.thread, test.thread_store.as_ref()).await?;
|
||||
started.thread.shutdown_and_wait().await?;
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
@@ -2324,7 +2330,7 @@ async fn fork_injects_changed_agents_md_once() -> Result<()> {
|
||||
.expect("test config should allow ContentItemKinds override");
|
||||
let forked = parent
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
codex_core::StartThreadOptions::new(fork_config),
|
||||
rollout_path,
|
||||
|
||||
@@ -2830,7 +2830,7 @@ async fn responses_websocket_restored_history_metric(fork: bool) -> anyhow::Resu
|
||||
options.thread_extension_init.insert(metrics);
|
||||
let restored = if fork {
|
||||
manager
|
||||
.fork_thread(codex_core::ForkSnapshot::Interrupted, options, rollout_path)
|
||||
.fork_legacy_thread(codex_core::ForkSnapshot::Interrupted, options, rollout_path)
|
||||
.await?
|
||||
} else {
|
||||
options.initial_history =
|
||||
|
||||
@@ -687,7 +687,7 @@ async fn resume_conversation(
|
||||
let auth_manager = codex_core::test_support::auth_manager_from_auth(
|
||||
codex_login::CodexAuth::from_api_key("dummy"),
|
||||
);
|
||||
Box::pin(manager.resume_thread_from_rollout(
|
||||
Box::pin(manager.resume_legacy_thread_from_rollout(
|
||||
config.clone(),
|
||||
path,
|
||||
auth_manager,
|
||||
@@ -706,7 +706,7 @@ async fn fork_thread(
|
||||
path: std::path::PathBuf,
|
||||
nth_user_message: usize,
|
||||
) -> Arc<CodexThread> {
|
||||
Box::pin(manager.fork_thread(
|
||||
Box::pin(manager.fork_legacy_thread(
|
||||
nth_user_message,
|
||||
codex_core::StartThreadOptions::new(config.clone()),
|
||||
path,
|
||||
|
||||
@@ -133,7 +133,7 @@ async fn fork_thread_twice_drops_to_first_message() {
|
||||
thread: codex_fork1,
|
||||
..
|
||||
} = thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::TruncateBeforeNthUserMessage(1),
|
||||
codex_core::StartThreadOptions::new(config_for_fork.clone()),
|
||||
base_path.clone(),
|
||||
@@ -160,7 +160,7 @@ async fn fork_thread_twice_drops_to_first_message() {
|
||||
thread: codex_fork2,
|
||||
..
|
||||
} = thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::TruncateBeforeNthUserMessage(0),
|
||||
codex_core::StartThreadOptions::new(config_for_fork.clone()),
|
||||
fork1_path.clone(),
|
||||
|
||||
@@ -22,6 +22,7 @@ use codex_thread_store::PersistContext;
|
||||
use codex_thread_store::ReadThreadByRolloutPathParams;
|
||||
use codex_thread_store::ReadThreadParams;
|
||||
use codex_thread_store::ResumeThreadParams;
|
||||
use codex_thread_store::StoredModelContext;
|
||||
use codex_thread_store::StoredThread;
|
||||
use codex_thread_store::StoredThreadHistory;
|
||||
use codex_thread_store::ThreadPage;
|
||||
@@ -42,7 +43,7 @@ use tokio::sync::oneshot;
|
||||
use tokio::time::timeout;
|
||||
|
||||
struct PendingSave {
|
||||
history: StoredThreadHistory,
|
||||
history: StoredModelContext,
|
||||
complete: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ impl ThreadStore for GatedReviewerStore {
|
||||
Box::pin(async move {
|
||||
let is_reviewer = self.reviewer.lock().await.thread_id == Some(thread_id);
|
||||
let pending = if is_reviewer {
|
||||
let history = ThreadStore::load_history(
|
||||
let history = ThreadStore::load_latest_model_context(
|
||||
&self.inner,
|
||||
LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
@@ -192,6 +193,13 @@ async fn guardian_saves_each_completed_review_before_releasing_its_action() -> a
|
||||
let pending = timeout(Duration::from_secs(10), pending_saves.recv())
|
||||
.await?
|
||||
.expect("review save");
|
||||
assert_eq!(
|
||||
pending.history.items.iter().find_map(|item| match item {
|
||||
RolloutItem::SessionMeta(meta) => Some(meta.meta.history_mode),
|
||||
_ => None,
|
||||
}),
|
||||
Some(ThreadHistoryMode::Paginated)
|
||||
);
|
||||
assert_eq!(
|
||||
*reviewer_id.get_or_insert(pending.history.thread_id),
|
||||
pending.history.thread_id
|
||||
|
||||
@@ -1678,7 +1678,7 @@ print(json.dumps({"hookSpecificOutput": {
|
||||
|
||||
let forked = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::TruncateBeforeNthUserMessage(1),
|
||||
StartThreadOptions::new(test.config.clone()),
|
||||
test.codex.rollout_path().expect("parent rollout path"),
|
||||
|
||||
@@ -219,9 +219,12 @@ async fn owner_cancellation_closes_agent_and_preserves_history_and_parent() -> a
|
||||
fixture.thread_store.flush_thread(agent.thread_id).await,
|
||||
Err(ThreadStoreError::ThreadNotFound { .. })
|
||||
));
|
||||
let history = agent
|
||||
.thread
|
||||
.load_history(/*include_archived*/ false)
|
||||
let history = fixture
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id: agent.thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
assert!(history.items.iter().any(|item| matches!(
|
||||
item,
|
||||
|
||||
@@ -266,7 +266,7 @@ async fn first_turn_after_empty_prefix_fork_preserves_inherited_base_instruction
|
||||
fork_config.base_instructions = None;
|
||||
let fork = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::TruncateBeforeNthUserMessage(0),
|
||||
codex_core::StartThreadOptions::new(fork_config),
|
||||
source_rollout_path,
|
||||
@@ -987,7 +987,7 @@ async fn model_change_projects_media_without_changing_live_or_replayed_history(
|
||||
MediaHistorySource::Live => Arc::clone(&test.codex),
|
||||
MediaHistorySource::Resume => {
|
||||
test.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
test.config.clone(),
|
||||
rollout_path,
|
||||
test.thread_manager.auth_manager(),
|
||||
@@ -999,7 +999,7 @@ async fn model_change_projects_media_without_changing_live_or_replayed_history(
|
||||
}
|
||||
MediaHistorySource::Fork => {
|
||||
test.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
codex_core::StartThreadOptions::new(test.config.clone()),
|
||||
rollout_path,
|
||||
|
||||
@@ -706,7 +706,7 @@ async fn resume_and_fork_append_permissions_messages() -> Result<()> {
|
||||
fork_config.permissions.approval_policy = Constrained::allow_any(AskForApproval::UnlessTrusted);
|
||||
let forked = initial
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
codex_core::StartThreadOptions::new(fork_config.clone()),
|
||||
rollout_path,
|
||||
|
||||
@@ -182,7 +182,7 @@ async fn ephemeral_fork_shares_cache_routing_but_keeps_session_identity() -> Res
|
||||
config.ephemeral = true;
|
||||
let fork = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::TruncateBeforeNthUserMessage(usize::MAX),
|
||||
StartThreadOptions {
|
||||
environments: Some(test.codex.environment_selections().await),
|
||||
|
||||
@@ -143,7 +143,7 @@ async fn worker_reasoning_overrides_follow_effective_client_policy(
|
||||
options.thread_source = Some(thread_source);
|
||||
let forked = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
options,
|
||||
parent.rollout_path().expect("parent rollout path"),
|
||||
@@ -619,7 +619,7 @@ async fn reasoning_effort_override_websocket_prewarm_preserves_baseline(
|
||||
configure_prewarm(&mut config);
|
||||
let forked = previous
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
codex_core::StartThreadOptions::new(config.clone()),
|
||||
previous.codex.rollout_path().expect("rollout path"),
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use anyhow::Result;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_history::ResumedHistory;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::user_input::ByteRange;
|
||||
use codex_protocol::user_input::TextElement;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_thread_store::LoadThreadHistoryParams;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::ev_reasoning_item;
|
||||
@@ -21,6 +25,74 @@ use core_test_support::wait_for_event;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test_case::test_case(None, ThreadHistoryMode::Paginated; "store default")]
|
||||
#[test_case::test_case(Some(ThreadHistoryMode::Legacy), ThreadHistoryMode::Legacy; "explicit legacy")]
|
||||
#[test_case::test_case(Some(ThreadHistoryMode::Paginated), ThreadHistoryMode::Paginated; "explicit paginated")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn local_thread_history_mode_survives_restart(
|
||||
requested: Option<ThreadHistoryMode>,
|
||||
expected: ThreadHistoryMode,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = start_mock_server().await;
|
||||
let mut builder = test_codex().with_history_mode(requested);
|
||||
let initial = builder.build_with_auto_env(&server).await?;
|
||||
assert_eq!(initial.codex.config_snapshot().await.history_mode, expected);
|
||||
mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_assistant_message("seed", "Remembered answer"),
|
||||
ev_completed("seed"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
initial.submit_text_turn("Remember this task").await?;
|
||||
|
||||
initial.codex.shutdown_and_wait().await?;
|
||||
let history = initial
|
||||
.thread_store
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id: initial.session_configured.thread_id,
|
||||
include_archived: true,
|
||||
})
|
||||
.await?;
|
||||
let resumed = initial
|
||||
.thread_manager
|
||||
.resume_thread_with_history(
|
||||
initial.config.clone(),
|
||||
InitialHistory::Resumed(ResumedHistory {
|
||||
conversation_id: history.thread_id,
|
||||
history: Arc::new(history.items),
|
||||
rollout_path: initial.session_configured.rollout_path.clone(),
|
||||
}),
|
||||
initial.thread_manager.auth_manager(),
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
resumed.thread.config_snapshot().await.history_mode,
|
||||
expected
|
||||
);
|
||||
let response = mount_sse_once(&server, sse(vec![ev_completed("followup")])).await;
|
||||
resumed
|
||||
.thread
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "Continue".into(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
wait_for_event(&resumed.thread, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
let request = response.single_request();
|
||||
assert!(request.body_contains_text("Remember this task"));
|
||||
assert!(request.body_contains_text("Remembered answer"));
|
||||
resumed.thread.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn resume_restores_windows_sandbox_override() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -111,7 +183,7 @@ async fn resume_includes_initial_messages_from_rollout_events() -> Result<()> {
|
||||
resumed.codex.flush_rollout().await?;
|
||||
let mut rejoined = resumed
|
||||
.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
resumed.config.clone(),
|
||||
resumed.codex.rollout_path().expect("resumed rollout path"),
|
||||
resumed.thread_manager.auth_manager(),
|
||||
|
||||
@@ -72,7 +72,7 @@ async fn running_descendants_refresh_only_shared_thread_instructions(shared: boo
|
||||
let root_response = mount_sse_once(&server, responses::sse_completed("root-step")).await;
|
||||
submit_thread_turn(&root.thread, "persist the root before it unloads").await?;
|
||||
root_response.single_request();
|
||||
let (_, history) = persisted_resume_history(&root.thread).await?;
|
||||
let (_, history) = persisted_resume_history(&root.thread, test.thread_store.as_ref()).await?;
|
||||
root.thread.shutdown_and_wait().await?;
|
||||
assert!(
|
||||
test.thread_manager
|
||||
|
||||
@@ -1099,6 +1099,9 @@ async fn opted_in_executor_provider_skips_host_discovery_but_injects_discovered_
|
||||
let executor_thread = test
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions {
|
||||
// Keep the trace fixture's legacy mode: paginated SQLite workers can close
|
||||
// spans through a different subscriber than this test's scoped collector.
|
||||
history_mode: Some(codex_protocol::protocol::ThreadHistoryMode::Legacy),
|
||||
environments: Some(vec![environment.clone()]),
|
||||
thread_extension_init,
|
||||
..StartThreadOptions::new(executor_config)
|
||||
|
||||
@@ -154,7 +154,7 @@ async fn thread_creator_survives_resume_and_forks_use_current_auth() -> Result<(
|
||||
|
||||
let fork = resumed
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
codex_core::ForkSnapshot::Interrupted,
|
||||
StartThreadOptions::new(resumed.config.clone()),
|
||||
rollout_path,
|
||||
@@ -358,6 +358,7 @@ async fn resume_restores_dynamic_tools_from_rollout_with_sqlite_enabled() -> Res
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions {
|
||||
dynamic_tools: vec![dynamic_tool],
|
||||
history_mode: Some(codex_protocol::protocol::ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(base_test.config.clone())
|
||||
})
|
||||
.await?;
|
||||
@@ -451,7 +452,10 @@ async fn resume_restores_legacy_dynamic_tools_from_rollout_with_sqlite_enabled()
|
||||
let base_test = builder.build(&server).await?;
|
||||
let started = base_test
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions::new(base_test.config.clone()))
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(codex_protocol::protocol::ThreadHistoryMode::Legacy),
|
||||
..StartThreadOptions::new(base_test.config.clone())
|
||||
})
|
||||
.await?;
|
||||
let rollout_path = started
|
||||
.session_configured
|
||||
|
||||
@@ -328,6 +328,7 @@ async fn tool_result_history_keeps_originating_model_across_switch_and_replay()
|
||||
let started = test
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions {
|
||||
history_mode: Some(ThreadHistoryMode::Legacy),
|
||||
dynamic_tools: vec![DynamicToolSpec::Function(DynamicToolFunctionSpec {
|
||||
name: "diagnostics".to_string(),
|
||||
description: "Returns diagnostic text and a screenshot.".to_string(),
|
||||
@@ -574,7 +575,7 @@ async fn tool_result_history_keeps_originating_model_across_switch_and_replay()
|
||||
replay_config.model = Some(model.to_string());
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
replay_config.clone(),
|
||||
rollout_path.clone(),
|
||||
codex_core::test_support::auth_manager_from_auth(CodexAuth::from_api_key("dummy")),
|
||||
@@ -585,7 +586,7 @@ async fn tool_result_history_keeps_originating_model_across_switch_and_replay()
|
||||
.thread;
|
||||
let forked = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
StartThreadOptions::new(replay_config),
|
||||
rollout_path.clone(),
|
||||
@@ -707,7 +708,7 @@ async fn custom_tool_output_replay_preserves_originating_budget() -> Result<()>
|
||||
replay_config.model = Some(MODEL_A.to_string());
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
replay_config.clone(),
|
||||
rollout_path.clone(),
|
||||
codex_core::test_support::auth_manager_from_auth(CodexAuth::from_api_key("dummy")),
|
||||
@@ -718,7 +719,7 @@ async fn custom_tool_output_replay_preserves_originating_budget() -> Result<()>
|
||||
.thread;
|
||||
let forked = test
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
ForkSnapshot::Interrupted,
|
||||
StartThreadOptions::new(replay_config),
|
||||
rollout_path,
|
||||
|
||||
@@ -126,7 +126,9 @@ async fn strict_tool_collisions_fail_the_turn_before_sampling(
|
||||
defer_loading: false,
|
||||
})]
|
||||
};
|
||||
let codex_core::NewThread { thread, .. } = test
|
||||
let codex_core::NewThread {
|
||||
thread_id, thread, ..
|
||||
} = test
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions {
|
||||
dynamic_tools,
|
||||
@@ -166,7 +168,13 @@ async fn strict_tool_collisions_fail_the_turn_before_sampling(
|
||||
};
|
||||
assert_eq!(completed.error, Some(error));
|
||||
thread.flush_rollout().await?;
|
||||
let history = thread.load_history(/*include_archived*/ false).await?;
|
||||
let history = test
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
let attribution = history.items.iter().find_map(|item| match item {
|
||||
codex_history::RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
if event.turn_id == completed.turn_id =>
|
||||
|
||||
@@ -67,7 +67,7 @@ async fn window_id_advances_after_compact_persists_on_resume_and_resets_on_fork(
|
||||
|
||||
let forked = resumed
|
||||
.thread_manager
|
||||
.fork_thread(
|
||||
.fork_legacy_thread(
|
||||
/*snapshot*/ 0usize,
|
||||
codex_core::StartThreadOptions::new(resumed.config.clone()),
|
||||
rollout_path,
|
||||
|
||||
@@ -30,7 +30,7 @@ pub struct AgentRun {
|
||||
pub thread: Arc<CodexThread>,
|
||||
}
|
||||
|
||||
/// Runs resolved agents in threads forked by the owning [`ThreadManager`].
|
||||
/// Runs resolved agents in legacy threads forked by the owning [`ThreadManager`].
|
||||
#[derive(Clone)]
|
||||
pub struct AgentRunner {
|
||||
thread_manager: Weak<ThreadManager>,
|
||||
@@ -41,7 +41,9 @@ impl AgentRunner {
|
||||
Self { thread_manager }
|
||||
}
|
||||
|
||||
/// Starts a resolved agent in a fork of `parent_thread_id`.
|
||||
/// Starts a resolved agent in a fork of a legacy `parent_thread_id`.
|
||||
///
|
||||
/// Paginated parents are rejected by [`ThreadManager::spawn_legacy_subagent`].
|
||||
pub async fn start(
|
||||
&self,
|
||||
parent_thread_id: ThreadId,
|
||||
@@ -65,7 +67,7 @@ impl AgentRunner {
|
||||
let NewThread {
|
||||
thread_id, thread, ..
|
||||
} = thread_manager
|
||||
.spawn_subagent(
|
||||
.spawn_legacy_subagent(
|
||||
parent_thread_id,
|
||||
StartThreadOptions {
|
||||
parent_trace: parent_trace.clone(),
|
||||
|
||||
@@ -690,7 +690,7 @@ async fn externally_changed_queues_dispatch_independently_and_retry_failed_wakes
|
||||
advance_queue_poll().await;
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
.resume_legacy_thread_from_rollout(
|
||||
test.config.clone(),
|
||||
rollout_path,
|
||||
test.thread_manager.auth_manager(),
|
||||
|
||||
@@ -327,9 +327,12 @@ mod tests {
|
||||
let rollout_path = PathBuf::from("/tmp/paginated-thread.jsonl");
|
||||
|
||||
store
|
||||
.create_thread(create_thread_params(thread_id, ThreadHistoryMode::Legacy))
|
||||
.create_thread(create_thread_params(
|
||||
thread_id,
|
||||
ThreadHistoryMode::Paginated,
|
||||
))
|
||||
.await
|
||||
.expect("create legacy thread");
|
||||
.expect("create paginated thread");
|
||||
store
|
||||
.resume_thread(ResumeThreadParams {
|
||||
thread_id,
|
||||
@@ -340,22 +343,6 @@ mod tests {
|
||||
})
|
||||
.await
|
||||
.expect("register rollout path");
|
||||
{
|
||||
let mut state = store.state.lock().await;
|
||||
state
|
||||
.created_threads
|
||||
.get_mut(&thread_id)
|
||||
.expect("created thread")
|
||||
.history_mode = ThreadHistoryMode::Paginated;
|
||||
let Some(RolloutItem::SessionMeta(meta_line)) = state
|
||||
.histories
|
||||
.get_mut(&thread_id)
|
||||
.and_then(|history| history.first_mut())
|
||||
else {
|
||||
panic!("canonical session meta");
|
||||
};
|
||||
meta_line.meta.history_mode = ThreadHistoryMode::Paginated;
|
||||
}
|
||||
|
||||
let thread = store
|
||||
.read_thread(ReadThreadParams {
|
||||
@@ -418,15 +405,6 @@ mod tests {
|
||||
})
|
||||
.await
|
||||
.expect("resume should succeed");
|
||||
assert_paginated_threads_unsupported(
|
||||
store
|
||||
.create_thread(create_thread_params(
|
||||
ThreadId::default(),
|
||||
ThreadHistoryMode::Paginated,
|
||||
))
|
||||
.await
|
||||
.expect_err("paginated create should fail"),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -593,7 +571,6 @@ impl InMemoryThreadStore {
|
||||
}
|
||||
|
||||
async fn create_thread(&self, params: CreateThreadParams) -> ThreadStoreResult<()> {
|
||||
reject_paginated_history_mode(params.history_mode)?;
|
||||
let mut state = self.state.lock().await;
|
||||
state.calls.create_thread += 1;
|
||||
let session_meta = SessionMeta {
|
||||
|
||||
@@ -468,6 +468,10 @@ impl LocalThreadStore {
|
||||
}
|
||||
|
||||
impl ThreadStore for LocalThreadStore {
|
||||
fn default_history_mode(&self) -> ThreadHistoryMode {
|
||||
ThreadHistoryMode::Paginated
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -412,6 +412,11 @@ impl App {
|
||||
let mut thread = app_server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await?;
|
||||
if thread.ephemeral {
|
||||
return Err(color_eyre::eyre::eyre!(
|
||||
"Agent thread {thread_id} is not yet available for replay or live attach."
|
||||
));
|
||||
}
|
||||
match app_server
|
||||
.hydrate_initial_thread_history(
|
||||
&mut thread,
|
||||
|
||||
@@ -577,6 +577,9 @@ async fn command_center_new_preserves_only_selected_server_profiles() -> Result<
|
||||
app.app_server_target = AppServerTarget::Remote {
|
||||
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:8765")?,
|
||||
};
|
||||
let state_db =
|
||||
crate::init_state_db_for_app_server_target(&server_config, &AppServerTarget::Embedded)
|
||||
.await?;
|
||||
let client = crate::start_embedded_app_server(
|
||||
codex_arg0::Arg0DispatchPaths::default(),
|
||||
server_config,
|
||||
@@ -586,7 +589,7 @@ async fn command_center_new_preserves_only_selected_server_profiles() -> Result<
|
||||
CloudConfigBundleLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
/*state_db*/ None,
|
||||
state_db,
|
||||
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
|
||||
Default::default(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user