Skip to content

fix(sessions): drop empty reasoning items from OpenAIConversationsSession persistence#3300

Draft
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/drop-empty-reasoning-from-oai-conversations-session
Draft

fix(sessions): drop empty reasoning items from OpenAIConversationsSession persistence#3300
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/drop-empty-reasoning-from-oai-conversations-session

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented May 9, 2026

Summary

When using OpenAIConversationsSession with a reasoning-enabled model (e.g. gpt-5.4-mini with reasoning: low), the SDK can produce reasoning run items whose summary list is empty. The session persistence path converted these to {"type":"reasoning","summary":[]} and attempted to save them via conversations.items.create(...), which the Conversations API rejects with Invalid item.

This PR fixes that by:

  • Adding _is_unpersistable_for_openai_conversation() — a targeted predicate that returns True for {"type":"reasoning","summary":[]} items.
  • In save_result_to_session, filtering such items from the add_items payload 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.

=== LOCAL_TEST_PASSED ===

Test plan

Two new pytest tests added to tests/test_agent_runner.py:

  • test_save_result_to_session_drops_empty_reasoning_from_openai_conversations — verifies that an empty reasoning item is not sent to add_items but is counted in saved_run_items_count and _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 reach add_items.
uv run ruff check src/agents/run_internal/session_persistence.py tests/test_agent_runner.py
uv run pytest tests/test_agent_runner.py -k "session" -v
uv run pytest tests/memory/ -v

All 45 session tests and 119 memory tests pass.

Issue number

Closes #3268

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

…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
@github-actions github-actions Bot added bug Something isn't working feature:core labels May 9, 2026
@seratch seratch marked this pull request as draft May 9, 2026 10:38
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:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIConversationsSession persists empty reasoning item {"type":"reasoning","summary":[]} and Conversations API rejects it as invalid

1 participant