diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs index 52ad78d137..ad434e7254 100644 --- a/codex-rs/core/src/compact.rs +++ b/codex-rs/core/src/compact.rs @@ -211,6 +211,9 @@ async fn run_compact_task_inner( .cloned() .collect(); new_history.extend(ghost_snapshots); + // Compaction snapshots history, waits on a model call, then replaces + // session history wholesale. Background writers can append during that + // window, so re-snapshot here and preserve any append-only tail items. let latest_history_snapshot = sess.clone_history().await; if !append_concurrent_history_tail_if_append_only( &mut new_history, diff --git a/codex-rs/core/src/compact_remote.rs b/codex-rs/core/src/compact_remote.rs index 838a12d98f..7bf7161fb8 100644 --- a/codex-rs/core/src/compact_remote.rs +++ b/codex-rs/core/src/compact_remote.rs @@ -151,6 +151,9 @@ async fn run_remote_compact_task_inner_impl( if !ghost_snapshots.is_empty() { new_history.extend(ghost_snapshots); } + // Remote compaction snapshots history, waits on an API call, then replaces + // session history wholesale. Background writers can append during that + // window, so re-snapshot here and preserve any append-only tail items. let latest_history_snapshot = sess.clone_history().await; if !append_concurrent_history_tail_if_append_only( &mut new_history,