Repository navigation
core: preserve ghost snapshot tails and guard stalled compaction - #14563
charley-oai wants to merge 13 commits into
Conversation
|
@codex review this |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks for the quick turnaround on this, @charley-oai! Glad the root cause analysis in #13946 was useful. The PR description matches the two edge cases exactly — the tail-write race and the retry cap. Looking forward to seeing this merged. 🙌 |
|
Read through the diff carefully — a few things I appreciate about this implementation:
LGTM from a correctness standpoint. The regression test covering the concurrent tail merge is a nice addition too. |
|
Thanks @charley-oai for picking this up so quickly — great to see both findings translated into a fix. On Finding 1 (race condition): The On Finding 2 (infinite loop): One open question on Finding 3 (atomic persistence): Thanks again for the fast turnaround! |
8d13d68 to
ce52fd9
Compare
|
@codex review this |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce52fd94f6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Those entries are stripped from `for_prompt()`, so re-snapshot here to | ||
| // preserve an append-only ghost-snapshot tail without reintroducing | ||
| // model-visible items that were never compacted. | ||
| let latest_history_snapshot = sess.clone_history().await; |
There was a problem hiding this comment.
Merge tail and replace history under one critical section
latest_history_snapshot is taken before replace_compacted_history, but replacement happens in a separate lock acquisition. If a ghost snapshot is appended in that gap, it is still lost, so concurrent tail writes are not actually preserved. The same TOCTOU pattern appears in both local and remote compaction paths (compact.rs and compact_remote.rs).
Useful? React with 👍 / 👎.
|
Re: the P1 bot comment on TOCTOU The finding is correct — there's still a narrow window between the re-snapshot ( The fix is to collapse those two steps into a single critical section. Instead of separate // proposed addition to Session
pub(crate) async fn snapshot_and_replace_compacted_history(
&self,
mut new_history: Vec<ResponseItem>,
base_history: &[ResponseItem],
) -> bool {
let mut live = self.history.lock().await;
let merged = append_concurrent_ghost_snapshot_tail_if_append_only(
&mut new_history,
base_history,
live.raw_items(),
);
*live = HistoryLog::from(new_history);
merged
}Both One note on practical severity: the window is now much smaller (snapshot-to-replace, not snapshot-to-model-call-to-replace), so the P1 label feels slightly elevated for what's left. But making it atomic is clearly the right shape — it removes the race entirely rather than just shrinking it. |
Move ghost snapshot tail preservation into replace_compacted_history so the merge happens under the same session lock as history replacement and the persisted replacement history matches the live history. Tests: just fmt Tests: cargo test -p codex-core Co-authored-by: Codex <[email protected]>
Move ghost snapshot tail preservation into replace_compacted_history so the merge happens under the same session lock as history replacement and the persisted replacement history matches the live history. Tests: just fmt Tests: cargo test -p codex-core Co-authored-by: Codex <[email protected]>
Handle interrupted multi-agent status in tui_app_server so the SDK build stays exhaustive after rebasing onto main. Tests: just fmt Tests: cargo test -p codex-tui-app-server collab_resume_interrupted_snapshot Tests: cargo build --bin codex Co-authored-by: Codex <[email protected]>
d2e333f to
97c69de
Compare
Co-authored-by: Codex <[email protected]>
Move ghost snapshot tail preservation into replace_compacted_history so the merge happens under the same session lock as history replacement and the persisted replacement history matches the live history. Tests: just fmt Tests: cargo test -p codex-core Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
486a4cd to
3b9dd27
Compare
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
|
@codex review this |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Preserve append-only session history items that arrive during local or remote compaction before replacing compacted history, and stop mid-turn auto compaction after three attempts with a user-visible error. Co-authored-by: Codex <[email protected]>
Rename the append-only compaction merge helper, switch it to a boolean success signal, and document the exact concurrency assumption. Co-authored-by: Codex <[email protected]>
Explain the snapshot-to-replace race at both compaction call sites so the extra re-snapshot and append-only tail preservation logic is easier to review. Co-authored-by: Codex <[email protected]>
Narrow the compaction race fix to preserve only appended ghost snapshots, which are non-model-visible and can realistically arrive from detached background tasks while compaction is waiting. Co-authored-by: Codex <[email protected]>
Make the mid-turn compaction cap explicit as a stalled auto-compaction safeguard with dedicated error text, telemetry, and regression coverage. Co-authored-by: Codex <[email protected]>
Move ghost snapshot tail preservation into replace_compacted_history so the merge happens under the same session lock as history replacement and the persisted replacement history matches the live history. Tests: just fmt Tests: cargo test -p codex-core Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: Codex <[email protected]>
Narrow the compaction race fix to the concrete ghost-snapshot case. Remove the conflict classification and warning path, and make replace_compacted_history opportunistically preserve only an append-only GhostSnapshot tail under the state lock. Co-authored-by: Codex <[email protected]>
Add an inline comment explaining why replacement_history is refreshed from the final in-memory items after the ghost snapshot tail merge. Co-authored-by: Codex <[email protected]>
f335c95 to
232ffcf
Compare
Add the required argument-name comment to the stalled auto-compaction telemetry counter increment. Co-authored-by: Codex <[email protected]>
|
Discussed with @aibrahim-oai, we actually think these edge cases should be rare enough that it's not worth adding code complexity for. However if you notice
|
Summary
GhostSnapshottail items that land during local or remote compaction, merging them insidereplace_compacted_historyso the live history and persistedreplacement_historystay alignedNotes
GhostSnapshottail, and only when the live history still extends the compacted prefix.GhostSnapshotitems are detached/undometadata and are stripped fromfor_prompt(), so this preserves checkpoint state without reintroducing model-visible items that the compaction request never saw.replace_history, which closes the final snapshot-to-replace gap called out in review.CompactedItem.replacement_historyis refreshed from the final installed history so rollout reconstruction stays consistent with the live session.codex.auto_compaction.stalled) and fail the turn instead of looping indefinitely.Testing
just fmtcargo test -p codex-core(one unrelated local failure:tools::js_repl::tests::js_repl_imported_local_files_can_access_repl_globalsdue sandbox tempdir permissions while bootstrapping dotslash in this sandbox)