mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Separate thread startup metadata from replay history (#46294)
## Why `CodexThread` retained the full `SessionConfiguredEvent`, including initial replay messages, and cloned it even for callers that only needed thread or session IDs. ## What changed Store `ThreadStartupMetadata` without replay history and expose it by reference through `startup_metadata()`. Update callers to read IDs from this metadata. When rejoining a running thread, rebuild the startup response using the supplied resume history for `initial_messages`. ## Testing Extend the resume test to verify that rejoining reuses the loaded thread, preserves startup metadata, and still returns the original replay messages as a prefix. GitOrigin-RevId: 9d656063088c28f091d29e5862e4b9d894b7642c
This commit is contained in:
1 parent
47fc8d661e
commit
17baabd01b
11 files changed
+171
-25
No files matched your search
@@ -44,7 +44,7 @@ async fn saved_history(test: &TestCodex, thread: &CodexThread) -> Result<Vec<Rol
|
||||
Ok(test
|
||||
.thread_store
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id: thread.session_configured().thread_id,
|
||||
thread_id: thread.startup_metadata().thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?
|
||||
@@ -56,7 +56,7 @@ pub(super) async fn resume(
|
||||
thread: &CodexThread,
|
||||
history: Vec<RolloutItem>,
|
||||
) -> Result<Arc<CodexThread>> {
|
||||
let thread_id = thread.session_configured().thread_id;
|
||||
let thread_id = thread.startup_metadata().thread_id;
|
||||
let environments = thread.environment_selections().await;
|
||||
let model = thread.config_snapshot().await.model;
|
||||
thread.shutdown_and_wait().await?;
|
||||
|
||||
@@ -185,7 +185,7 @@ async fn load_context(test: &TestCodex, thread: &CodexThread) -> Result<Vec<Roll
|
||||
Ok(test
|
||||
.thread_store
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id: thread.session_configured().thread_id,
|
||||
thread_id: thread.startup_metadata().thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?
|
||||
@@ -193,7 +193,7 @@ async fn load_context(test: &TestCodex, thread: &CodexThread) -> Result<Vec<Roll
|
||||
}
|
||||
|
||||
async fn resume(test: &TestCodex, thread: &CodexThread) -> Result<Arc<CodexThread>> {
|
||||
let thread_id = thread.session_configured().thread_id;
|
||||
let thread_id = thread.startup_metadata().thread_id;
|
||||
thread.shutdown_and_wait().await?;
|
||||
test.thread_manager.remove_thread(&thread_id).await;
|
||||
let saved = load_context(test, thread).await?;
|
||||
@@ -729,7 +729,7 @@ async fn disabled_capture_stays_incomplete_after_compaction_and_enabled_resume()
|
||||
assert!(!checkpoint.user_messages_complete());
|
||||
assert_eq!(checkpoint.ordered_entries().count(), 0);
|
||||
|
||||
let thread_id = test.codex.session_configured().thread_id;
|
||||
let thread_id = test.codex.startup_metadata().thread_id;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
test.thread_manager.remove_thread(&thread_id).await;
|
||||
let items: Vec<RolloutItem> = serde_json::from_value(serde_json::to_value(
|
||||
@@ -1057,7 +1057,7 @@ async fn standalone_fork_retains_inherited_user_instructions(
|
||||
let prepared = test
|
||||
.thread_store
|
||||
.prepare_fork(PrepareForkParams {
|
||||
thread_id: worker.session_configured().thread_id,
|
||||
thread_id: worker.startup_metadata().thread_id,
|
||||
boundary: ForkBoundary::Latest,
|
||||
})
|
||||
.await?;
|
||||
@@ -1073,7 +1073,7 @@ async fn standalone_fork_retains_inherited_user_instructions(
|
||||
ForkSnapshot::Interrupted,
|
||||
codex_core::StartThreadOptions::new(test.config.clone()),
|
||||
InitialHistory::Resumed(ResumedHistory {
|
||||
conversation_id: worker.session_configured().thread_id,
|
||||
conversation_id: worker.startup_metadata().thread_id,
|
||||
history: Arc::new(load_context(&test, &worker).await?),
|
||||
rollout_path: None,
|
||||
}),
|
||||
@@ -1260,7 +1260,7 @@ async fn forked_parent_instructions_do_not_become_local_authorization(
|
||||
tokio::time::timeout(Duration::from_secs(30), child_gate.entered.notified())
|
||||
.await
|
||||
.context("child did not reach the paused tool call")?;
|
||||
let child_id = child.session_configured().thread_id.to_string();
|
||||
let child_id = child.startup_metadata().thread_id.to_string();
|
||||
let requests = child_requests.requests();
|
||||
let child_request = requests
|
||||
.iter()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::ThreadSettingsOverrides;
|
||||
use codex_protocol::user_input::ByteRange;
|
||||
@@ -81,10 +82,11 @@ async fn resume_includes_initial_messages_from_rollout_events() -> Result<()> {
|
||||
.await?;
|
||||
|
||||
wait_for_event(&codex, |event| matches!(event, EventMsg::TurnComplete(_))).await;
|
||||
let resumed = builder.restart(&server, &initial).await?;
|
||||
let mut resumed = builder.restart(&server, &initial).await?;
|
||||
let initial_messages = resumed
|
||||
.session_configured
|
||||
.initial_messages
|
||||
.take()
|
||||
.expect("expected initial messages to be present for resumed session");
|
||||
match initial_messages.as_slice() {
|
||||
[
|
||||
@@ -106,6 +108,32 @@ async fn resume_includes_initial_messages_from_rollout_events() -> Result<()> {
|
||||
other => panic!("unexpected initial messages after resume: {other:#?}"),
|
||||
}
|
||||
|
||||
resumed.codex.flush_rollout().await?;
|
||||
let mut rejoined = resumed
|
||||
.thread_manager
|
||||
.resume_thread_from_rollout(
|
||||
resumed.config.clone(),
|
||||
resumed.codex.rollout_path().expect("resumed rollout path"),
|
||||
resumed.thread_manager.auth_manager(),
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
.await?;
|
||||
assert!(Arc::ptr_eq(&rejoined.thread, &resumed.codex));
|
||||
let rejoined_messages = rejoined
|
||||
.session_configured
|
||||
.initial_messages
|
||||
.take()
|
||||
.expect("rejoining a loaded thread must still provide replay messages");
|
||||
assert_eq!(
|
||||
serde_json::to_value(&rejoined.session_configured)?,
|
||||
serde_json::to_value(&resumed.session_configured)?,
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(&rejoined_messages[..initial_messages.len()])?,
|
||||
serde_json::to_value(&initial_messages)?,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user