mirror of
https://github.com/openai/codex.git
synced 2026-12-01 15:42:13 +00:00
Support paginated thread forks (#35220)
## Why `thread/fork` rejected threads using paginated history, so they could not use the same fork workflow as legacy threads. ## What changed - Create paginated forks by referencing a frozen source-history prefix while persisting only child-owned records in the new rollout. - Support latest, `lastTurnId`, and `beforeTurnId` boundaries, including inherited lineage, model-context reconstruction, interruption markers, and approval-reviewer inheritance. - Make paginated reads and occurrence search traverse referenced history while excluding source records added after the fork. - Coordinate fork preparation with archive and delete operations, and materialize compressed rollouts before they become fork references. ## Testing Added app-server and thread-store coverage for boundary selection, active turns, inherited reads and search, compressed lineage, and concurrent source lifecycle operations. GitOrigin-RevId: 66052d69517d7fb97a3b7817ab77a39c5ad995fd
This commit is contained in:
1 parent
58b4277228
commit
05f000263b
44 files changed
+2810
-295
No files matched your search
@@ -58,6 +58,7 @@ use crate::state_db::StateDbHandle;
|
||||
use codex_git_utils::collect_git_info;
|
||||
use codex_git_utils::get_git_repo_root;
|
||||
use codex_protocol::protocol::GitInfo as ProtocolGitInfo;
|
||||
use codex_protocol::protocol::HistoryPosition;
|
||||
use codex_protocol::protocol::InitialHistory;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::ResumedHistory;
|
||||
@@ -103,6 +104,7 @@ pub enum RolloutRecorderParams {
|
||||
selected_capability_roots: Vec<SelectedCapabilityRoot>,
|
||||
multi_agent_version: Option<MultiAgentVersion>,
|
||||
history_mode: ThreadHistoryMode,
|
||||
history_base: Option<HistoryPosition>,
|
||||
subagent_history_start_ordinal: Option<u64>,
|
||||
initial_window_id: Option<String>,
|
||||
},
|
||||
@@ -197,6 +199,7 @@ impl RolloutRecorderParams {
|
||||
selected_capability_roots: Vec::new(),
|
||||
multi_agent_version: None,
|
||||
history_mode: Default::default(),
|
||||
history_base: None,
|
||||
subagent_history_start_ordinal: None,
|
||||
initial_window_id: None,
|
||||
}
|
||||
@@ -247,6 +250,16 @@ impl RolloutRecorderParams {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_history_base(mut self, history_base: Option<HistoryPosition>) -> Self {
|
||||
if let Self::Create {
|
||||
history_base: base, ..
|
||||
} = &mut self
|
||||
{
|
||||
*base = history_base;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_subagent_history_start_ordinal(
|
||||
mut self,
|
||||
subagent_history_start_ordinal: Option<u64>,
|
||||
@@ -797,10 +810,12 @@ impl RolloutRecorder {
|
||||
selected_capability_roots,
|
||||
multi_agent_version,
|
||||
history_mode,
|
||||
history_base,
|
||||
subagent_history_start_ordinal,
|
||||
initial_window_id,
|
||||
} => {
|
||||
let ordinal_state = RolloutOrdinalState::for_new_rollout(history_mode);
|
||||
let ordinal_state =
|
||||
RolloutOrdinalState::for_new_rollout(history_mode, history_base);
|
||||
let log_file_info = precompute_log_file_info(config, conversation_id)?;
|
||||
let path = log_file_info.path.clone();
|
||||
let thread_id = log_file_info.conversation_id;
|
||||
@@ -838,7 +853,7 @@ impl RolloutRecorder {
|
||||
selected_capability_roots,
|
||||
memory_mode: (!config.generate_memories()).then_some("disabled".to_string()),
|
||||
history_mode,
|
||||
history_base: None,
|
||||
history_base,
|
||||
subagent_history_start_ordinal,
|
||||
multi_agent_version,
|
||||
context_window: initial_window_id.map(SessionContextWindow::new),
|
||||
@@ -1564,6 +1579,7 @@ fn precompute_log_file_info(
|
||||
}
|
||||
|
||||
fn open_log_file(path: &Path) -> std::io::Result<File> {
|
||||
let refresh_modified_time = !compression::plain_rollout_path(path).try_exists()?;
|
||||
let path = compression::materialize_rollout_for_append_blocking(path)?;
|
||||
let Some(parent) = path.parent() else {
|
||||
return Err(IoError::other(format!(
|
||||
@@ -1577,6 +1593,9 @@ fn open_log_file(path: &Path) -> std::io::Result<File> {
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(path)?;
|
||||
if refresh_modified_time {
|
||||
file.set_times(std::fs::FileTimes::new().set_modified(std::time::SystemTime::now()))?;
|
||||
}
|
||||
ensure_rollout_is_newline_terminated(&mut file)?;
|
||||
Ok(file)
|
||||
}
|
||||
@@ -1831,6 +1850,8 @@ pub async fn append_rollout_item_to_path(
|
||||
async fn open_rollout_for_append(
|
||||
path: &Path,
|
||||
) -> std::io::Result<(PathBuf, tokio::fs::File, RolloutOrdinalState)> {
|
||||
let refresh_modified_time =
|
||||
!tokio::fs::try_exists(compression::plain_rollout_path(path)).await?;
|
||||
let path = compression::materialize_rollout_for_append(path).await?;
|
||||
let path_for_open = path.clone();
|
||||
let (file, ordinal_state) = tokio::task::spawn_blocking(move || {
|
||||
@@ -1838,6 +1859,9 @@ async fn open_rollout_for_append(
|
||||
.read(true)
|
||||
.append(true)
|
||||
.open(path_for_open.as_path())?;
|
||||
if refresh_modified_time {
|
||||
file.set_times(std::fs::FileTimes::new().set_modified(std::time::SystemTime::now()))?;
|
||||
}
|
||||
ensure_rollout_is_newline_terminated(&mut file)?;
|
||||
let ordinal_state = ordinal_state_for_rollout(&mut file, path_for_open.as_path())?;
|
||||
Ok::<_, std::io::Error>((file, ordinal_state))
|
||||
|
||||
Reference in new issue
Block a user