Limit archive rollout reads to requested threads (#43494)

## Why

Archiving threads reads metadata from every active rollout, including unrelated compressed files.

## What changed

Add `RolloutReferenceIndex::scan_unarchived_threads` and use it when archiving. Filter canonical filenames by the requested thread IDs before reading contents, while retaining metadata-based ownership checks.

## Testing

Add tests covering reverted rollouts, requested descendants, compressed rollouts, exclusion of archived and unrelated files, and candidate ownership checks.

GitOrigin-RevId: a64f7fa25e5493ed20312f1d8216422752272bae
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-07 15:19:21 +00:00
1 parent d665e3bbc8
commit d0a8dcd157
3 files changed
+141 -13

No files matched your search

@@ -39,12 +39,15 @@ pub(super) async fn archive_threads(
}
}
let _writer_guards = store.acquire_writer_locks(&lock_thread_ids).await?;
// Already-archived rollouts need no move. Avoid reading the entire archive on every request.
let reference_index = RolloutReferenceIndex::scan_unarchived(store.config.codex_home.as_path())
.await
.map_err(|err| ThreadStoreError::Internal {
message: format!("failed to scan thread rollout files: {err}"),
})?;
// Only inspect active files whose names belong to the threads being archived.
let reference_index = RolloutReferenceIndex::scan_unarchived_threads(
store.config.codex_home.as_path(),
&thread_ids,
)
.await
.map_err(|err| ThreadStoreError::Internal {
message: format!("failed to scan thread rollout files: {err}"),
})?;
let parent_thread_id = thread_ids[0];
let mut archived_thread_ids = Vec::new();