fix(sessions): drop empty reasoning items from OpenAIConversationsSession persistence#3300
Draft
xodn348 wants to merge 1 commit intoopenai:mainfrom
Draft
Conversation
…sion persistence
The Conversations API rejects reasoning items with an empty summary list
({"type":"reasoning","summary":[]}) with "Invalid item". The persistence
path in save_result_to_session still counted these items toward the
persisted-item counter so that the retry/streaming logic advances past
them correctly, but now filters them out of the add_items payload so they
are never sent to the API.
Adds _is_unpersistable_for_openai_conversation() helper and two regression
tests covering the drop-but-count behaviour and the non-empty pass-through.
Fixes openai#3268
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.
Summary
When using
OpenAIConversationsSessionwith a reasoning-enabled model (e.g.gpt-5.4-miniwithreasoning: low), the SDK can produce reasoning run items whosesummarylist is empty. The session persistence path converted these to{"type":"reasoning","summary":[]}and attempted to save them viaconversations.items.create(...), which the Conversations API rejects withInvalid item.This PR fixes that by:
_is_unpersistable_for_openai_conversation()— a targeted predicate that returnsTruefor{"type":"reasoning","summary":[]}items.save_result_to_session, filtering such items from theadd_itemspayload after the persisted-item counter is updated. The counter still advances past empty reasoning items so the retry/streaming deduplication logic works correctly; we just stop sending them to the API.Non-empty reasoning items (with at least one summary entry) are unaffected and continue to be persisted normally.
Test plan
Two new
pytesttests added totests/test_agent_runner.py:test_save_result_to_session_drops_empty_reasoning_from_openai_conversations— verifies that an empty reasoning item is not sent toadd_itemsbut is counted insaved_run_items_countand_current_turn_persisted_item_count.test_save_result_to_session_keeps_nonempty_reasoning_in_openai_conversations— regression guard confirming that reasoning items with a non-empty summary still reachadd_items.All 45 session tests and 119 memory tests pass.
Issue number
Closes #3268
Checks
make lintandmake format