Skip to content

fix(sessions): preserve concurrent writes during compaction - #4736

Open
seratch wants to merge 1 commit into
mainfrom
fix/preserve-concurrent-compaction-writes
Open

fix(sessions): preserve concurrent writes during compaction#4736
seratch wants to merge 1 commit into
mainfrom
fix/preserve-concurrent-compaction-writes

Conversation

@seratch

@seratch seratch commented Aug 28, 2026

Copy link
Copy Markdown
Member

This pull request fixes #4679 by serializing OpenAIResponsesCompactionSession mutations across the full responses.compact request and replacement window.

Before this change, run_compaction released its mutation lock while awaiting responses.compact, so a same-wrapper add_items could be overwritten by the later clear-and-replace, and a concurrent clear_session could 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 Session protocol does not expose a shared revision or compare-and-swap boundary.

This pull request resolves #4679.

@seratch seratch added this to the 0.22.x milestone Aug 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-28T11:56:13.116717Z 06a290b New commits
🔒 Security Review Completed 2026-08-28T11:57:23.442481Z 06a290b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/memory/openai_responses_compaction_session.py Outdated
@seratch
seratch force-pushed the fix/preserve-concurrent-compaction-writes branch from a02203e to 22a822d Compare August 28, 2026 08:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/memory/openai_responses_compaction_session.py Outdated
@seratch
seratch force-pushed the fix/preserve-concurrent-compaction-writes branch from 22a822d to 84f047a Compare August 28, 2026 09:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/memory/openai_responses_compaction_session.py Outdated
@seratch
seratch force-pushed the fix/preserve-concurrent-compaction-writes branch from 84f047a to 03583c3 Compare August 28, 2026 09:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/memory/openai_responses_compaction_session.py
@seratch
seratch force-pushed the fix/preserve-concurrent-compaction-writes branch from 03583c3 to c6bd7fa Compare August 28, 2026 11:31
Co-authored-by: Om Singhal <wengsinghal@gmail.com>
@seratch
seratch force-pushed the fix/preserve-concurrent-compaction-writes branch from c6bd7fa to 06a290b Compare August 28, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIResponsesCompactionSession drops session items written while responses.compact is in flight

1 participant