Skip to content

fix(compaction): strip orphaned assistant message IDs after reasoning removal#2728

Merged
seratch merged 1 commit intoopenai:mainfrom
Ratnaditya-J:fix/compaction-orphaned-assistant-ids
Mar 20, 2026
Merged

fix(compaction): strip orphaned assistant message IDs after reasoning removal#2728
seratch merged 1 commit intoopenai:mainfrom
Ratnaditya-J:fix/compaction-orphaned-assistant-ids

Conversation

@Ratnaditya-J
Copy link
Contributor

gpt-5.4's responses.compact strips reasoning items from output but keeps assistant messages with their original IDs. When those get sent back to responses.create, the API 400s because it expects the paired reasoning items that were removed.

This adds a post-compaction pass in run_compaction() that strips id from 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)
  • unit tests for _strip_orphaned_assistant_ids (empty, strips when no reasoning, preserves when reasoning present, preserves msgs without id, handles multiple)
  • integration-level tests through run_compaction() for both the orphaned-id and reasoning-present cases

Fixes #2727

… 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
@github-actions github-actions bot added bug Something isn't working feature:sessions labels Mar 20, 2026
@seratch seratch added this to the 0.12.x milestone Mar 20, 2026
@seratch seratch merged commit c964926 into openai:main Mar 20, 2026
9 checks passed
@seratch seratch modified the milestones: 0.12.x, 0.13.x Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:sessions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIResponsesCompactionSession + reasoning breaks with gpt-5.4 (compact output retains orphaned assistant message IDs)

2 participants