mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Pass the last inherited turn ID when creating a fork (#65111)
## Why A thread store that resolves the last inherited turn during fork preparation can reuse that ID when creating the child instead of resolving it again. ## What changed Forward the optional `last_inherited_turn_id` from `PreparedFork` to `CreateThreadParams` alongside the inherited history position. Omit the field from serialized creation parameters when no ID is available. ## Testing Add a regression test that checks the in-memory thread store receives the turn ID supplied by the prepared fork when it creates the child. GitOrigin-RevId: 709c8cc4a744b2f893af6233e825026a27732873
This commit is contained in:
@@ -500,6 +500,7 @@ impl ExternalAgentSessionImporter {
|
||||
multi_agent_version: Some(MultiAgentVersion::V1),
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -139,6 +139,7 @@ async fn get_conversation_summary_by_thread_id_reads_pathless_store_thread() ->
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -302,6 +302,7 @@ async fn thread_list_repeated_cursor_returns_internal_error() -> Result<()> {
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
@@ -555,6 +556,7 @@ async fn thread_delete_with_non_local_thread_store_does_not_create_local_persist
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -660,6 +660,7 @@ async fn thread_search_occurrences_reads_paginated_projection() -> Result<()> {
|
||||
multi_agent_version: None,
|
||||
history_mode: codex_protocol::protocol::ThreadHistoryMode::Paginated,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
@@ -3156,6 +3157,7 @@ async fn create_paginated_thread(
|
||||
multi_agent_version: None,
|
||||
history_mode: codex_protocol::protocol::ThreadHistoryMode::Paginated,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
@@ -3275,6 +3277,7 @@ async fn seed_pathless_store_thread(
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -76,6 +76,7 @@ fn create_params(codex_home: &Path, thread_id: ThreadId) -> CreateThreadParams {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Paginated,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -264,6 +264,7 @@ async fn thread_unarchive_preserves_pathless_store_metadata() -> Result<()> {
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -502,6 +502,7 @@ pub(crate) enum ForkPersistence {
|
||||
CopiedDeferred,
|
||||
Referenced {
|
||||
history_base: Option<HistoryPosition>,
|
||||
last_inherited_turn_id: Option<String>,
|
||||
inherited_item_count: usize,
|
||||
inherited_history_visibility: InheritedHistoryVisibility,
|
||||
},
|
||||
|
||||
@@ -1143,6 +1143,22 @@ impl Session {
|
||||
anyhow::anyhow!("new thread missing its initial window")
|
||||
})?;
|
||||
let auth = persistence_auth.await;
|
||||
let (history_base, last_inherited_turn_id, inherited_history_visibility) =
|
||||
match &fork_persistence {
|
||||
ForkPersistence::Copied | ForkPersistence::CopiedDeferred => {
|
||||
(None, None, InheritedHistoryVisibility::Full)
|
||||
}
|
||||
ForkPersistence::Referenced {
|
||||
history_base,
|
||||
last_inherited_turn_id,
|
||||
inherited_history_visibility,
|
||||
..
|
||||
} => (
|
||||
*history_base,
|
||||
last_inherited_turn_id.clone(),
|
||||
*inherited_history_visibility,
|
||||
),
|
||||
};
|
||||
let params = CreateThreadParams {
|
||||
attached_thread,
|
||||
creator_user_id: auth.as_ref().and_then(CodexAuth::get_chatgpt_user_id),
|
||||
@@ -1163,19 +1179,9 @@ impl Session {
|
||||
selected_capability_roots: selected_capability_roots.clone(),
|
||||
multi_agent_version: initial_multi_agent_version,
|
||||
history_mode: session_configuration.history_mode,
|
||||
history_base: match &fork_persistence {
|
||||
ForkPersistence::Copied | ForkPersistence::CopiedDeferred => None,
|
||||
ForkPersistence::Referenced { history_base, .. } => *history_base,
|
||||
},
|
||||
inherited_history_visibility: match &fork_persistence {
|
||||
ForkPersistence::Copied | ForkPersistence::CopiedDeferred => {
|
||||
InheritedHistoryVisibility::Full
|
||||
}
|
||||
ForkPersistence::Referenced {
|
||||
inherited_history_visibility,
|
||||
..
|
||||
} => *inherited_history_visibility,
|
||||
},
|
||||
history_base,
|
||||
last_inherited_turn_id,
|
||||
inherited_history_visibility,
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ids.initial_window_id.clone(),
|
||||
runtime_workspace_roots: Some(config.workspace_roots.clone()),
|
||||
|
||||
@@ -4810,6 +4810,7 @@ async fn open_thread_persistence(session: &mut Session) -> PathBuf {
|
||||
history_mode: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
runtime_workspace_roots: None,
|
||||
@@ -8636,6 +8637,7 @@ async fn shutdown_complete_does_not_append_to_thread_store_after_shutdown() {
|
||||
history_mode: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
runtime_workspace_roots: None,
|
||||
@@ -8776,6 +8778,7 @@ async fn submission_loop_channel_close_runs_full_thread_teardown() -> anyhow::Re
|
||||
history_mode: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
runtime_workspace_roots: None,
|
||||
@@ -11754,6 +11757,7 @@ async fn attach_in_memory_thread_store(
|
||||
history_mode: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
runtime_workspace_roots: None,
|
||||
|
||||
@@ -1950,6 +1950,7 @@ impl ThreadManager {
|
||||
});
|
||||
let fork_persistence = ForkPersistence::Referenced {
|
||||
history_base: prepared.history_base,
|
||||
last_inherited_turn_id: prepared.last_inherited_turn_id.clone(),
|
||||
inherited_item_count: prepared.model_context.len(),
|
||||
inherited_history_visibility,
|
||||
};
|
||||
|
||||
@@ -101,6 +101,43 @@ async fn prepared_fork_uses_prepared_store_creation() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A prepared fork must pass its resolved boundary turn to the thread-store backend creating the
|
||||
/// child, so remote stores do not have to rediscover it.
|
||||
#[tokio::test]
|
||||
async fn prepared_fork_passes_boundary_turn_to_store() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = MockServer::start().await;
|
||||
let store = Arc::new(InMemoryThreadStore::default());
|
||||
let test = test_codex()
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
let expected_turn_id = "turn-at-fork-boundary".to_string();
|
||||
let mut prepared = PreparedFork::with_source_revalidation(
|
||||
test.session_configured.thread_id,
|
||||
/*history_base*/ None,
|
||||
Arc::new(Vec::new()),
|
||||
);
|
||||
prepared.last_inherited_turn_id = Some(expected_turn_id.clone());
|
||||
|
||||
let child = test
|
||||
.thread_manager
|
||||
.fork_prepared_thread(
|
||||
test.start_thread_options().await,
|
||||
prepared,
|
||||
InheritedHistoryVisibility::Full,
|
||||
)
|
||||
.await?;
|
||||
let create_params = store
|
||||
.created_thread_params(child.thread_id)
|
||||
.await
|
||||
.expect("child creation parameters");
|
||||
|
||||
assert_eq!(create_params.last_inherited_turn_id, Some(expected_turn_id));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn ephemeral_fork_skips_stored_title_lookup() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
@@ -64,6 +64,7 @@ async fn create_store(path: &Path, owner: ThreadId) -> anyhow::Result<LocalThrea
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Paginated,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -185,6 +185,7 @@ mod tests {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
@@ -479,6 +480,7 @@ mod tests {
|
||||
multi_agent_version: None,
|
||||
history_mode,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: ContextWindowId::new_uuid_v7(),
|
||||
@@ -592,6 +594,16 @@ impl InMemoryThreadStore {
|
||||
self.state.lock().await.calls.clone()
|
||||
}
|
||||
|
||||
/// Returns the parameters used to create `thread_id`.
|
||||
pub async fn created_thread_params(&self, thread_id: ThreadId) -> Option<CreateThreadParams> {
|
||||
self.state
|
||||
.lock()
|
||||
.await
|
||||
.created_threads
|
||||
.get(&thread_id)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
/// Makes every thread-list page return the same cursor for public API error-path tests.
|
||||
pub async fn repeat_list_threads_cursor_for_testing(&self, cursor: impl Into<String>) {
|
||||
self.state.lock().await.repeated_list_threads_cursor = Some(cursor.into());
|
||||
|
||||
@@ -2628,6 +2628,7 @@ mod tests {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -702,6 +702,7 @@ fn create_thread_params(thread_id: ThreadId) -> CreateThreadParams {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -367,6 +367,7 @@ async fn create_paginated_thread(store: &LocalThreadStore, thread_id: ThreadId)
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Paginated,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -815,6 +815,7 @@ async fn paginated_realtime_items_materialize_separately_in_rollout_order() {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
@@ -3170,6 +3171,7 @@ async fn create_paginated_subagent_thread(
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Paginated,
|
||||
history_base,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -528,6 +528,7 @@ mod tests {
|
||||
multi_agent_version: None,
|
||||
history_mode: ThreadHistoryMode::Legacy,
|
||||
history_base: None,
|
||||
last_inherited_turn_id: None,
|
||||
inherited_history_visibility: Default::default(),
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
|
||||
|
||||
@@ -122,6 +122,9 @@ pub struct CreateThreadParams {
|
||||
pub history_mode: ThreadHistoryMode,
|
||||
/// Exclusive prefix of another paginated rollout inherited by this thread.
|
||||
pub history_base: Option<HistoryPosition>,
|
||||
/// Last turn included in `history_base`, when the backend resolved a turn boundary.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub last_inherited_turn_id: Option<String>,
|
||||
/// Visibility of the history inherited through `history_base`.
|
||||
#[serde(default)]
|
||||
pub inherited_history_visibility: InheritedHistoryVisibility,
|
||||
@@ -257,6 +260,8 @@ pub struct PreparedFork {
|
||||
pub source_thread_id: ThreadId,
|
||||
/// Frozen physical rollout prefix inherited by the child.
|
||||
pub history_base: Option<HistoryPosition>,
|
||||
/// Last turn included in `history_base`, when the backend resolved a turn boundary.
|
||||
pub last_inherited_turn_id: Option<String>,
|
||||
/// Bounded model context selected by the requested fork boundary.
|
||||
pub model_context: Arc<Vec<RolloutItem>>,
|
||||
/// Opening preview from the frozen transcript when compaction omitted it from model context.
|
||||
@@ -280,6 +285,7 @@ impl PreparedFork {
|
||||
Self {
|
||||
source_thread_id,
|
||||
history_base,
|
||||
last_inherited_turn_id: None,
|
||||
model_context,
|
||||
preview_before_compaction: None,
|
||||
_source_reservation: Some(Box::new(source_reservation)),
|
||||
@@ -296,6 +302,7 @@ impl PreparedFork {
|
||||
Self {
|
||||
source_thread_id,
|
||||
history_base,
|
||||
last_inherited_turn_id: None,
|
||||
model_context,
|
||||
preview_before_compaction: None,
|
||||
_source_reservation: None,
|
||||
|
||||
Reference in New Issue
Block a user