mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Throttle repeated rollout compression runs (#25659)
## Why [#25089](https://github.com/openai/codex/pull/25089) introduced the background worker that compresses cold archived rollouts, and [#25654](https://github.com/openai/codex/pull/25654) made that pass faster once it starts. But the worker still deleted `rollout-compression.lock` on successful exit, so the existing six-hour staleness window only helped with overlapping or crashed workers. Each new local thread-store initialization could immediately rescan archived rollouts even if a full pass had just finished. This change keeps the existing marker around long enough to throttle redundant reruns. The worker is still best-effort, but it no longer does repeated startup scans when nothing new is eligible for compression. ## What Changed - Replace the drop-scoped `CompressionLock` with a `CompressionRunMarker` that claims the existing `.tmp/rollout-compression.lock` path and leaves it in place after success. - Reuse the existing six-hour staleness window to block both overlapping starts and immediate reruns, while still letting a stale marker be reclaimed. - Update the worker docs and debug logging to describe the new "already running or recently ran" behavior. - Extend the rollout compression tests to assert that a successful run leaves the marker behind and that a fresh marker suppresses a new run. ## Validation - `just test -p codex-rollout`
This commit is contained in:
1 parent
ba2b67f9cd
commit
c3cdf3c007
2 files changed
+68
-26
No files matched your search
@@ -141,6 +141,12 @@ async fn worker_compresses_old_archived_rollouts_only() -> anyhow::Result<()> {
|
||||
assert!(!compressed_rollout_path(&fresh_path).exists());
|
||||
assert!(!stale_temp.exists());
|
||||
assert!(fresh_temp.exists());
|
||||
assert!(
|
||||
home.path()
|
||||
.join(".tmp")
|
||||
.join("rollout-compression.lock")
|
||||
.exists()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -323,16 +329,16 @@ async fn worker_skips_existing_compressed_archived_rollouts() -> anyhow::Result<
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn worker_skips_when_fresh_lock_exists() -> anyhow::Result<()> {
|
||||
async fn worker_skips_when_fresh_run_marker_exists() -> anyhow::Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let uuid = Uuid::from_u128(11);
|
||||
let thread_id = ThreadId::from_string(&uuid.to_string())?;
|
||||
let rollout_path = archived_rollout_path(home.path(), "2025-01-03T12-00-00", uuid);
|
||||
write_rollout(&rollout_path, thread_id, "locked worker")?;
|
||||
write_rollout(&rollout_path, thread_id, "throttled worker")?;
|
||||
set_old_mtime(&rollout_path)?;
|
||||
let lock_dir = home.path().join(".tmp");
|
||||
fs::create_dir_all(lock_dir.as_path())?;
|
||||
fs::write(lock_dir.join("rollout-compression.lock"), "locked")?;
|
||||
let marker_dir = home.path().join(".tmp");
|
||||
fs::create_dir_all(marker_dir.as_path())?;
|
||||
fs::write(marker_dir.join("rollout-compression.lock"), "recent run")?;
|
||||
|
||||
worker::run(home.path().to_path_buf()).await?;
|
||||
|
||||
@@ -341,6 +347,27 @@ async fn worker_skips_when_fresh_lock_exists() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_marker_is_removed_unless_persisted() -> anyhow::Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let marker_path = home.path().join(".tmp").join("rollout-compression.lock");
|
||||
|
||||
{
|
||||
let marker = worker::CompressionRunMarker::try_claim(home.path())?;
|
||||
assert!(marker.is_some());
|
||||
}
|
||||
assert!(!marker_path.exists());
|
||||
|
||||
let marker = worker::CompressionRunMarker::try_claim(home.path())?;
|
||||
let Some(marker) = marker else {
|
||||
panic!("expected run marker claim");
|
||||
};
|
||||
marker.persist();
|
||||
assert!(marker_path.exists());
|
||||
assert!(worker::CompressionRunMarker::try_claim(home.path())?.is_none());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn find_thread_path_by_id_handles_compressed_rollout_filenames() -> anyhow::Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
|
||||
Reference in new issue
Block a user