fix(sessions): preserve concurrent writes during compaction - #4736
fix(sessions): preserve concurrent writes during compaction#4736seratch wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a02203e033
ℹ️ 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".
a02203e to
22a822d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22a822dc98
ℹ️ 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".
22a822d to
84f047a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84f047a28d
ℹ️ 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".
Co-authored-by: Om Singhal <wengsinghal@gmail.com>
84f047a to
03583c3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03583c342e
ℹ️ 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".
| async with self._mutation_lock: | ||
| await self._run_compaction_locked(args, wrapper=wrapper) |
There was a problem hiding this comment.
Revalidate history after acquiring the compaction lock
When run A releases this lock after add_items(), an already-waiting run B can acquire it and append its batch before A reacquires it here. In the default previous_response_id path, A then compacts only resp_A while the local history already includes B and replaces that history with A's compacted output, silently deleting B's committed items; the new tests only cover the opposite ordering where compaction acquires the lock first. Preserve ownership across the append-to-compaction boundary or reject replacement when the generation changed.
AGENTS.md reference: AGENTS.md:L149-L149
Useful? React with 👍 / 👎.
This pull request fixes #4679 by serializing
OpenAIResponsesCompactionSessionmutations across the fullresponses.compactrequest and replacement window.Before this change,
run_compactionreleased its mutation lock while awaitingresponses.compact, so a same-wrapperadd_itemscould be overwritten by the later clear-and-replace, and a concurrentclear_sessioncould be undone. The compaction lock now remains held from the history snapshot through replacement, so queued mutations run afterward and determine the final Session state.The regression tests use deterministic event ordering to verify that a queued append survives after compacted output and that a queued clear leaves the Session empty. This change intentionally does not add backend-wide coordination for separate compaction wrapper instances because the released
Sessionprotocol does not expose a shared revision or compare-and-swap boundary.This pull request resolves #4679.