Fix: Remove ID from reasoning items when store is set to False #2068
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
Fixes session management for OpenAI Responses API when using Zero Data Retention (
store=False) with load-balanced instances. Previously, reasoning item IDs were saved to sessions, causing "reasoning item not found" errors when subsequent requests were routed to different OpenAI instances.Problem:
When using the OpenAI Responses API with
store=False(ZDR mode) and reasoning enabled (response_include=["reasoning.encrypted_content"]), the API returns reasoning items with instance-specific IDs (e.g.,rs_07162bf5faaac0660...). These IDs are temporary references to reasoning content stored in the memory of the specific OpenAI instance that generated them. When the SDK's session management saves these items to persistent storage and replays them in a subsequent request, if that request is load-balanced to a different OpenAI instance, the new instance cannot resolve the ID, resulting in an error.Root Cause:
Even with
store=False, OpenAI assigns instance-specific IDs to reasoning items. These IDs act as cryptographic references to encrypted reasoning content temporarily held in the memory of the specific instance. Theencrypted_contentfield, however, is universally decryptable by any OpenAI instance using shared internal keys.Solution:
Modified
_save_result_to_session()insrc/agents/run.pyto conditionally strip theidfield from reasoning items whenstore=Falsebefore persisting them to session storage. This ensures that only portable information (theencrypted_content) is saved.The fix:
store=Falseset in the agent's model settingsidfield before saving to sessionencrypted_contentfield, which is universally decryptablestore=TrueorNone(default), as those reference valid server-side conversation stateIssue number
Closes #2063
User Scenario
Before Fix:
After Fix:
The chosen approach balances correctness, backward compatibility, and minimal API surface changes.