Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Reserve a sibling rollout candidate slot for the first ancestor (#55627)

ben zhang48b6a9d8e0b5
diff --git a/codex-rs/rollout/src/list.rs b/codex-rs/rollout/src/list.rs
index d66ceb8039..10734a92b9 100644
--- a/codex-rs/rollout/src/list.rs
+++ b/codex-rs/rollout/src/list.rs
@@ -1583,6 +1583,7 @@ pub async fn prefetch_sibling_rollout_paths(
directory,
child_name.thread_id(),
child_name.rollout_id(),
+ first_ancestor_id,
)
.await?;
if ids.len() < 2 || !ids.contains(&first_ancestor_id) {
diff --git a/codex-rs/rollout/src/list_files.rs b/codex-rs/rollout/src/list_files.rs
index 2d6b96ca65..4552592ed3 100644
--- a/codex-rs/rollout/src/list_files.rs
+++ b/codex-rs/rollout/src/list_files.rs
@@ -82,6 +82,7 @@ pub(super) async fn collect_sibling_rollout_ids(
directory: &Path,
thread_id: ThreadId,
child_rollout_id: RolloutId,
+ first_ancestor_id: RolloutId,
) -> io::Result<HashSet<RolloutId>> {
let directory = directory.to_path_buf();
run_scan(move |scan| {
@@ -94,6 +95,13 @@ pub(super) async fn collect_sibling_rollout_ids(
&& file_name.thread_id() == thread_id
&& file_name.rollout_id() != child_rollout_id
{
+ // Reserve the last slot for the first ancestor until it is found.
+ if ids.len() == MAX_SIBLING_ROLLOUT_IDS - 1
+ && file_name.rollout_id() != first_ancestor_id
+ && !ids.contains(&first_ancestor_id)
+ {
+ continue;
+ }
ids.insert(file_name.rollout_id());
if ids.len() >= MAX_SIBLING_ROLLOUT_IDS {
break;
diff --git a/codex-rs/rollout/src/list_files_tests.rs b/codex-rs/rollout/src/list_files_tests.rs
index 25f6033f2e..2606124790 100644
--- a/codex-rs/rollout/src/list_files_tests.rs
+++ b/codex-rs/rollout/src/list_files_tests.rs
@@ -11,6 +11,33 @@ use std::time::Duration;
use std::time::UNIX_EPOCH;
use tempfile::TempDir;
+#[tokio::test]
+async fn sibling_rollout_candidates_prioritize_first_ancestor_at_capacity() -> anyhow::Result<()> {
+ let directory = TempDir::new()?;
+ let thread_id = ThreadId::new();
+ let child_id = RolloutId::new();
+ let sibling_ids: Vec<_> = (0..=MAX_SIBLING_ROLLOUT_IDS)
+ .map(|_| RolloutId::new())
+ .collect();
+ for rollout_id in sibling_ids.iter().copied().chain([child_id]) {
+ let file_name = RolloutFileName::new(OffsetDateTime::UNIX_EPOCH, thread_id, rollout_id);
+ File::create(directory.path().join(file_name.render()?))?;
+ }
+
+ let initial =
+ collect_sibling_rollout_ids(directory.path(), thread_id, child_id, sibling_ids[0]).await?;
+ let omitted = sibling_ids
+ .into_iter()
+ .find(|id| !initial.contains(id))
+ .expect("one sibling must exceed the candidate limit");
+ let prioritized =
+ collect_sibling_rollout_ids(directory.path(), thread_id, child_id, omitted).await?;
+
+ assert_eq!(prioritized.len(), MAX_SIBLING_ROLLOUT_IDS);
+ assert!(prioritized.contains(&omitted));
+ Ok(())
+}
+
#[tokio::test]
async fn dropping_scan_stops_directory_enumeration() -> anyhow::Result<()> {
let root = TempDir::new()?;