fix(compaction): strip orphaned assistant message IDs after reasoning removal#2728
Merged
seratch merged 1 commit intoopenai:mainfrom Mar 20, 2026
Merged
Conversation
… removal gpt-5.4's responses.compact retains assistant message IDs in its output even after stripping the paired reasoning items. When those orphaned IDs are sent back to responses.create, the API rejects them with a 400 because it expects the paired reasoning items to still be present. Strip id from assistant messages in compacted output when no reasoning items are present, matching the behavior that gpt-5.2's compact endpoint already produces natively. Fixes openai#2727
seratch
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gpt-5.4's
responses.compactstrips reasoning items from output but keeps assistant messages with their original IDs. When those get sent back toresponses.create, the API 400s because it expects the paired reasoning items that were removed.This adds a post-compaction pass in
run_compaction()that stripsidfrom assistant messages when no reasoning items are present in the compacted output — matching what gpt-5.2's compact already does natively.Testing
pytest tests/memory/test_openai_responses_compaction_session.py— 36 tests pass (7 new covering the fix + helper)_strip_orphaned_assistant_ids(empty, strips when no reasoning, preserves when reasoning present, preserves msgs without id, handles multiple)run_compaction()for both the orphaned-id and reasoning-present casesFixes #2727